Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kherge-archive/lib-accessor
A PHP library for simplifying the use of accessors.
https://github.com/kherge-archive/lib-accessor
Last synced: 29 days ago
JSON representation
A PHP library for simplifying the use of accessors.
- Host: GitHub
- URL: https://github.com/kherge-archive/lib-accessor
- Owner: kherge-archive
- License: mit
- Archived: true
- Created: 2013-11-07T22:58:16.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-11-16T00:23:51.000Z (about 11 years ago)
- Last Synced: 2024-04-14T17:04:51.482Z (8 months ago)
- Language: PHP
- Size: 133 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-php-cn - Lib Accessor - 一个简化访问的库 (目录 / 数据结构和存储 Data Structure and Storage)
README
Accessor
========[![Build Status][]](https://travis-ci.org/phine/lib-accessor)
[![Coverage Status][]](https://coveralls.io/r/phine/lib-accessor)
[![Latest Stable Version][]](https://packagist.org/packages/phine/accessor)
[![Total Downloads][]](https://packagist.org/packages/phine/accessor)A PHP library for simplifying the use of accessors.
Usage
-----```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'));
}
}
```Now we make use of that example class:
```php
// 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;
```Requirement
------------ PHP >= 5.4
Installation
------------Via [Composer][]:
$ composer require "phine/accessor=~1.0"
Documentation
-------------You can find the documentation in the [`docs/`](docs/) directory.
License
-------This library is available under the [MIT license](LICENSE).
[Build Status]: https://travis-ci.org/phine/lib-accessor.png?branch=master
[Coverage Status]: https://coveralls.io/repos/phine/lib-accessor/badge.png
[Latest Stable Version]: https://poser.pugx.org/phine/accessor/v/stable.png
[Total Downloads]: https://poser.pugx.org/phine/accessor/downloads.png
[Phine Exception]: https://github.com/phine/lib-exception
[Composer]: http://getcomposer.org/