Skip to content

Writers

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

Writers are used to set the array parsed value in the matched object property.

By default the library use Rafrsr\LibArray2Object\Writer\AccessorWriter this writer require the setter method of each property to set the value, otherwise the value is not settled.

Can use one of the following writers:

Rafrsr\LibArray2Object\Writer\AccessorWriter:

Require the setter in the object to work.

Rafrsr\LibArray2Object\Writer\ReflectionWriter:

Write values directly on propeties, optionally can write only public properties.

How use one of this writers

$array2Object = Array2ObjectBuilder::create()->setWriter(new ReflectionWriter())->build();

Standalone writer class

Can implements your own writer class implementing Rafrsr\LibArray2Object\Writer\PropertyWriterInterface

class CustomWriter implements PropertyWriterInterface
{
    /**
     * @inheritDoc
     */
    public function isWritable($object, $propertyPath)
    {
        // TODO: Implement isWritable() method.
    }

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