1. Go to this page and download the library: Download zfstarter/zfs-domain-model library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
'service_manager' => array(
'aliases' => array(
// допустим, у нас есть подключение к БД как 'Db\Adapter'
// чтоб ZFS\DomainModel могла его использовать по-умолчанию, делаем алиас:
'ZFS\DomainModel\Adapter' => 'Db\Adapter'
)
)
namespace Application\Model\Gateway;
use ZFS\DomainModel\Gateway\AbstractFactory as BaseAbstractFactory;
class AbstractFactory extends BaseAbstractFactory
{
protected $provides = array(
'UsersGateway' => array(
'tableName' => 'users'
)
);
}
const OPTION_TABLE_GATEWAY = 'tableGateway'; // имя класса, создается через new
const OPTION_TABLE_NAME = 'tableName'; // имя таблицы, единственное обязательное поле
const OPTION_ADAPTER = 'adapter'; // имя, доступное через ServiceLocator
const OPTION_TABLE_FEATURES = 'tableFeatures'; // массив из обьектов ***Feature
const OPTION_RESULT_SET_PROTOTYPE = 'resultSetPrototype'; // имя класса, создается через new
const OPTION_OBJECT_PROTOTYPE = 'objectPrototype'; // имя класса, создается через new
const OPTION_SQL = 'sql'; // имя класса, создается через new
namespace Application\Model\Object;
use ZFS\DomainModel\Object\Object;
class User extends Object
{
protected $primaryColumns = array(
'id'
);
public function getId()
{
return $this->data['id']; // напрямую из массива данных
}
public function getName()
{
return $this->get('name'); // использует настройку $fieldToColumnMap, а так же возвращает null если isset($this->data[$name]) == false
}
}
namespace Application\Model\Object;
use ZFS\DomainModel\Object\ObjectMagic;
/**
* @property int id
* @property string name
*/
class User extends ObjectMagic
{
protected $primaryColumns = array(
'id'
);
}
namespace Application\Model\Object;
use ZFS\DomainModel\Object\ObjectMagic;
/**
* @property int id
* @property string name
* @property string dateOfBirth
*/
class User extends ObjectMagic
{
protected $primaryColumns = array(
'id'
);
protected $fieldToColumnMap = array(
'dateOfBirth' => 'date_of_birth'
);
}
namespace Application\Model\Gateway;
use ZFS\DomainModel\Feature\FilterColumnsFeature;
use ZFS\DomainModel\Gateway\AbstractFactory as BaseAbstractFactory;
use ZFS\DomainModel\Service\Options;
class AbstractFactory extends BaseAbstractFactory
{
public function __construct()
{
$this->provides['UsersGateway'] = array(
Options::OPTION_TABLE_NAME => 'users',
Options::OPTION_TABLE_FEATURES => array(new FilterColumnsFeature()),
Options::OPTION_OBJECT_PROTOTYPE => 'Application\Model\Object\User'
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.