phine/accessor

此包已被废弃,不再维护。没有建议的替代包。

一个用于简化访问器使用的PHP库。

1.0.0 2013-11-07 23:15 UTC

This package is not auto-updated.

Last update: 2021-12-07 01:40:41 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads

一个用于简化访问器使用的PHP库。

使用方法

use Doctrine\ORM\Mapping as ORM;
use Phine\Accessor\AccessorTrait;
use Phine\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.
     */
    public function __construct()
    {
        $this->makePropertyAccessible('country');
        $this->makePropertyAccessible('id');
        $this->makePropertyAccessible('state');

        $this->makePropertyMutable('country', new InstanceType('Country'));
        $this->makePropertyMutable('state', new InstanceType('State'));
    }
}

现在我们使用这个示例类

// this all works just fine
$address = new Address();
$address->country = new Country();
$address->state = new State();

// these throw exceptions
$address->country = new State();
$address->id = 123;
$address->state = null;

要求

  • PHP >= 5.4

安装

通过Composer

$ composer require "phine/accessor=~1.0"

文档

您可以在docs/目录中找到文档。链接

许可

此库可在MIT许可下使用。