A PHP library for simplifying the use of accessors.
useDoctrine\ORM\MappingasORM;
usePhine\Accessor\AccessorTrait;
usePhine\Accessor\Type\InstanceType;
/** * This is an example Doctrine entity class. * * @ORM\Entity() * @ORM\Table() */class Address
{
use AccessorTrait;
/** * The country the address resides in. * * @var Country * * @ORM\JoinColumn(name="country") * @ORM\ManyToOne(targetEntity="Country") */private$country;
/** * The unique identifier for this address. * * @var integer * * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") * @ORM\Id() */private$id;
/** * The state the address resides in. * * @var State * * @ORM\JoinColumn(name="state") * @ORM\ManyToOne(targetEntity="State") */private$state;
/** * Configures the accessors. */publicfunction__construct()
{
$this->makePropertyAccessible('country');
$this->makePropertyAccessible('id');
$this->makePropertyAccessible('state');
$this->makePropertyMutable('country', newInstanceType('Country'));
$this->makePropertyMutable('state', newInstanceType('State'));
}
}Now we make use of that example class:
// this all works just fine$address = newAddress();
$address->country = newCountry();
$address->state = newState();
// these throw exceptions$address->country = newState();
$address->id = 123;
$address->state = null;- PHP >= 5.4
Via Composer:
$ composer require "phine/accessor=~1.0"
You can find the documentation in the docs/ directory.
This library is available under the MIT license.



