Model behaviors base classes
Requirement
PHP 5.4, (*1)
Installation
Checkout the code to either of your library directories:, (*2)
cd libraries
git clone git@github.com:jails/li3_behaviors.git
Include the library in your /app/config/bootstrap/libraries.php
, (*3)
Libraries::add('li3_behaviors');
Presentation
Model behaviors providing a simple way to extend models. This pattern allow common logic to be encapsulated inside behaviors for keeping models lite and composed only by its own business logic., (*4)
API
Simple model creation attached to a behavior:, (*5)
[
'fields' => ['title' => 'title', 'name' => 'slug']
]];
}
?>
['label' => 'slug']
];
parent::__construct($config + $defaults);
}
protected function _init() {
parent::_init();
if ($model = $this->_model) {
$behavior = $this;
$model::applyFilter('save', function($self, $params, $chain) use ($behavior) {
$params = $behavior->invokeMethod('_slug', array($params));
return $chain->next($self, $params, $chain);
});
}
}
protected function _slug($params) {
extract($this->_config);
foreach ($fields as $from => $to) {
if (isset($params['data'][$from])) {
$params['data'][$to] = Inflector::slug($params['data'][$from]);
}
}
return $params;
}
}
?>
Greetings
The li3 team, Nateabele's filters system and all others which make that possible (including my parents which I love)., (*6)
Build status
, (*7)