Permalink
Browse files

Added ability to retrieve back metadata attributes from models using …

…older array syntax
  • Loading branch information...
troydavisson committed Jul 3, 2015
1 parent fa1408a commit 8b38b41b48faee508d24563d5d365e48d0e8120f
Showing with 131 additions and 2 deletions.
  1. +1 −0 README.md
  2. +30 −0 docs/changelog.md
  3. +1 −1 docs/contribute.md
  4. +1 −0 mkdocs.yml
  5. +75 −1 src/Models/Metadata/Base.php
  6. +23 −0 tests/Models/Metadata/ResourceTest.php
@@ -3,6 +3,7 @@ Note: If you're looking for version 1, please see the "1.x" branch. Otherwise,
[![Latest Stable Version](https://poser.pugx.org/troydavisson/PHRETS/v/stable.png)](https://packagist.org/packages/troydavisson/PHRETS)
[![Total Downloads](https://poser.pugx.org/troydavisson/PHRETS/downloads.png)](https://packagist.org/packages/troydavisson/PHRETS)
[![Build Status](https://travis-ci.org/troydavisson/PHRETS.svg?branch=2)](https://travis-ci.org/troydavisson/PHRETS)
[![Documentation Status](https://readthedocs.org/projects/phrets/badge/?version=latest)](https://readthedocs.org/projects/phrets/?badge=latest)
[![ScreenShot](http://troda.com/newfeatures.png)](http://youtu.be/115mx-9jYVM)
@@ -0,0 +1,30 @@
## master
_Release TBD_
- Access metadata attributes using array syntax
## 2.1
_Released May 4, 2015_
- New Configuration method to force HTTP Basic authentication
- Added methods for easily generating CSV, array and JSON structures directly from results
- Modifications to support both Guzzle 4.x and 5.x
- Loosened version requirements on some Composer dependencies
## 2.0
_Released April 5, 2015_
- Major rewrite
- Added support for RETS 1.8
> **Note**: PHRETS moved to GitHub in 2011 so the commit history since can be [viewed there](https://github.com/troydavisson/PHRETS/commits/master).
## Original
_Released 2006_
@@ -1,4 +1,4 @@
Outside contributions to this library as welcome.
Outside contributions to this library are welcome.
# Contributing directly to the code
@@ -6,5 +6,6 @@ pages:
- [functions.md, Function Reference]
- [examples.md, Examples and Common Use Cases]
- [tutorials.md, Tutorials and Guides]
- [changelog.md, Changelog]
- [contribute.md, Contributing]
theme: readthedocs
@@ -1,6 +1,6 @@
<?php namespace PHRETS\Models\Metadata;
abstract class Base
abstract class Base implements \ArrayAccess
{
/** @var \PHRETS\Session */
protected $session;
@@ -68,4 +68,78 @@ public function getXmlAttributes()
{
return $this->attributes;
}
/**
* (PHP 5 &gt;= 5.0.0)<br/>
* Whether a offset exists
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
* @param mixed $offset <p>
* An offset to check for.
* </p>
* @return boolean true on success or false on failure.
* </p>
* <p>
* The return value will be casted to boolean if non-boolean was returned.
*/
public function offsetExists($offset)
{
foreach (array_merge($this->getXmlElements(), $this->getXmlAttributes()) as $attr) {
if (strtolower($attr) == strtolower($offset)) {
return true;
}
}
return false;
}
/**
* (PHP 5 &gt;= 5.0.0)<br/>
* Offset to retrieve
* @link http://php.net/manual/en/arrayaccess.offsetget.php
* @param mixed $offset <p>
* The offset to retrieve.
* </p>
* @return mixed Can return all value types.
*/
public function offsetGet($offset)
{
foreach (array_merge($this->getXmlElements(), $this->getXmlAttributes()) as $attr) {
if (strtolower($attr) == strtolower($offset)) {
return \array_get($this->values, $attr);
}
}
return null;
}
/**
* (PHP 5 &gt;= 5.0.0)<br/>
* Offset to set
* @link http://php.net/manual/en/arrayaccess.offsetset.php
* @param mixed $offset <p>
* The offset to assign the value to.
* </p>
* @param mixed $value <p>
* The value to set.
* </p>
* @return void
*/
public function offsetSet($offset, $value)
{
$this->values[$offset] = $value;
}
/**
* (PHP 5 &gt;= 5.0.0)<br/>
* Offset to unset
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
* @param mixed $offset <p>
* The offset to unset.
* </p>
* @return void
*/
public function offsetUnset($offset)
{
if ($this->offsetExists($offset)) {
unset($this->values[$offset]);
}
}
}
@@ -27,4 +27,27 @@ public function it_returns_null_for_unrecognized_attributes()
$metadata = new Resource;
$this->assertNull($metadata->getSomethingFake());
}
/** @test **/
public function it_works_like_an_array()
{
$metadata = new Resource;
$metadata->setDescription('Test Description');
$this->assertTrue(array_key_exists('Description', $metadata));
$this->assertSame('Test Description', $metadata['Description']);
}
/** @test **/
public function it_sets_like_an_array()
{
$metadata = new Resource;
$metadata['Description'] = "Array setter";
$this->assertSame("Array setter", $metadata->getDescription());
unset($metadata['Description']);
$this->assertNull($metadata->getDescription());
}
}

0 comments on commit 8b38b41

Please sign in to comment.