piano / accessor
There is no license information available for the latest version (0.2) of this package.
A creator of getter and setter method by using annotations!
0.2
2016-05-30 16:16 UTC
Requires (Dev)
This package is auto-updated.
Last update: 2024-12-28 11:38:35 UTC
README
Piano Accessor
This package allows us to create getters and setters just by using a few annotations.
Installing
composer require piano/accessor
Usage example
See the example:
This User
class:
<?php namespace App; class User { private $name; private $age; private $createdAt; public function setName($name) { $this->name = $name; } public function setAge($age) { $this->age = (int) $age; } public function setCreatedAt(\DateTime $createdAt) { $this->createdAt = $createdAt; } public function getName() { return $this->name; } public function getAge() { return (int) $this->age; } public function getCreatedAt() { return $this->createdAt; } }
Is the same as this User
class:
<?php namespace App; class User { use \Piano\AccessorTrait; /** * @set * @get */ private $name; /** * @set int * @get int */ private $age; /** * @set \DateTime * @get */ private $createdAt; }
As you can see it's possible to specify the type hint or type cast when defining the @set
and it's also possible to specify the type cast when defining the @get
.
That's optional though.
As below:
For @set
any other value will be treated as type hint.