public __construct ( |
||
$container | The configuration variables to this model | |
$config | array | Configuration values for this model |
public function __construct(Container $container, array $config = array())
{
$this->container = $container;
// Set the model's name from $config
if (isset($config['name'])) {
$this->name = $config['name'];
}
// If $config['name'] is not set, auto-detect the model's name
$this->name = $this->getName();
// Set the model state
if (array_key_exists('state', $config)) {
if (is_object($config['state'])) {
$this->state = $config['state'];
} elseif (is_array($config['state'])) {
$this->state = (object) $config['state'];
} else {
$this->state = new \stdClass();
}
} else {
$this->state = new \stdClass();
}
// Set the internal state marker
if (!empty($config['use_populate'])) {
$this->_state_set = true;
}
// Set the internal state marker
if (!empty($config['ignore_request'])) {
$this->_ignoreRequest = true;
}
}
/** * Assigns callback functions to the class, the $methods array should be an associative one, where * the keys are the method names, while the values are the closure functions, e.g. * * array( * 'foobar' => function(){ return 'Foobar'; } * ) * * @param $container * @param array $config * @param array $methods */ public function __construct(Container $container, array $config = array(), array $methods = array()) { foreach ($methods as $method => $function) { $this->methods[$method] = $function; } parent::__construct($container, $config); }