polidog / object-access
0.0.1
2018-09-18 11:56 UTC
Requires
- php: ^7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
- phpunit/phpunit: ^7.3
This package is auto-updated.
Last update: 2024-11-21 21:10:24 UTC
README
This library provides object property accessor. It is very simple.
It support only object. Array is No support.
Installation
$ composer req polidog/object-access
Usage
class User {
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $name;
/**
* Sample constructor.
* @param int $id
* @param string $name
*/
public function __construct(int $id, string $name)
{
$this->id = $id;
$this->name = $name;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
}
$user = new User(120,'test-user');
$accessor = \Polidog\ObjectAccess\ObjectAccess::createAccessor();
$accessor->setter($user, 'name', 'change-name-user');
var_dump($user->getName()); // change-name-user