Skip to content

Readers

Rafael Santos edited this page Jun 27, 2016 · 1 revision

Readers are similars to writers but are used to create the array from object.

By default the library use Rafrsr\LibArray2Object\Reader\AccessorReader this reader require the getter method of each property to get the value, otherwise the value is not getted.

Can use one of the following readers:

Rafrsr\LibArray2Object\Reader\AccessorReader:

Require the getter in the object to work.

Rafrsr\LibArray2Object\Writer\ReflectionReader:

Read values directly on propertiers, optionally can read only public properties.

How use one of this readers

$object2Array = Object2Array::create()->setReader(new ReflectionReader())->build();

Standalone reader class

Can implements your own reader class implementing Rafrsr\LibArray2Object\Reader\PropertyReaderInterface

class CustomReader implements PropertyReaderInterface
{
    /**
     * @inheritDoc
     */
    public function isReadable($object, $propertyPath)
    {
        // TODO: Implement isReadable() method.
    }

    /**
     * @inheritDoc
     */
    public function getValue(&$object, $propertyPath)
    {
        // TODO: Implement getValue() method.
    }
}