Supreme Object
Supreme Object is to create Data Object or Data Transfer Objects for you, instead of dealing with arrays or class properties.
From the command line run:
composer require saedyousef/supreme-object
With the package now installed, you can implement the main Interface DataObject
and by using the trait DataObjectTrait
that have all the methods implemented for you.
Here is an example of a class PostDataObject
that implements the DataObject
interface :
use Saedyousef\SupremeObject\Contracts\DataObject;
use Saedyousef\SupremeObject\Support\DataObjectTrait;
/**
* @property int|null id
* @property string title
* @property string body
*/
class PostDataObject implements DataObject
{
use DataObjectTrait;
public function __construct(array $properties = [])
{
$this->_properties = [
'id' => null,
'title' => '',
'body' => ''
];
$this->hydrate($properties);
}
/**
* @return int|null
*/
public function getId()
{
return $this->id;
}
}
And that's it! Now you have your data object set.
A Star on this repo would be appreciated ;)