Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

saedyousef/supreme-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Supreme Object

Total Downloads Latest Stable Version License wakatime


Supreme Object is to create Data Object or Data Transfer Objects for you, instead of dealing with arrays or class properties.

Installation

From the command line run:

composer require saedyousef/supreme-object

Usage

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 ;)