library abstractmodel
A library for creating simple data models.
dsmithhayes/abstractmodel
A library for creating simple data models.
- Tuesday, March 14, 2017
- by dsmithhayes
- Repository
- 1 Watchers
- 0 Stars
- 7 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 2 Versions
- 0 % Grown
AbstractModel
The problem: writing get and set methods for specific
properties can get tiresome, especially when there is no extra
logic other than getting, and setting. AbstractModel solves
this problem by letting you build a data model and
automatically generating the mutators., (*1)
The AbstractModel class implements the PSR-11 Container
interface., (*2)
Installation
$ composer require dsmithhayes/abstractmodel
Usage
<?php
use Dsh\AbstractModel;
/**
* By default all public values are treated as such.
*/
class User extends AbstractModel
{
/**
* Protected properties get mutators by default
*/
protected $username;
/**
* Private properties do not.
*/
private $password;
public function __construct($username, $password)
{
$this->username = $username;
$this->password = $password;
}
}
// `init()` actually reads the properties and builds a store
// for the values
$user = (new User('dave', 'password'))->init();
echo $user->getUsername(); // yields 'dave'
echo $user->getPassword(); // throws an Exception
$user->init(User::USE_ALL);
echo $user->getPassword(); // yields 'password'
dev-master
9999999-dev
A library for creating simple data models.
Sources
Download
BSD 3.0
The Requires
by
Dave Smith-Hayes
v0.0.1
0.0.1.0
A library for creating simple data models.
Sources
Download
BSD 3.0
The Requires
by
Dave Smith-Hayes