/**
* Sets up the adapter with the configuration assigned by the `Session` class.
*
* @param array $config Available configuration options for this adapter:
* - `'config'` _string_: The name of the model that this adapter should use.
*/
public function __construct(array $config = array())
{
$this->config = Set::merge($this->config, $config);
if (empty($this->config['model']) || !class_exists($this->config['model'])) {
throw new ConfigException("No valid model \"{$this->config['model']}\" available to use for Session interaction");
} elseif (empty($this->config['entityManager']) && (!method_exists($this->config['model'], 'getEntityManager') || !is_callable($this->config['model'] . '::getEntityManager'))) {
throw new ConfigException("The session model {$this->config['model']} must define a getEntityManager() static method, or you must set the entityManager session config variable");
}
$reflection = new \ReflectionClass($this->config['model']);
if (!$reflection->implementsInterface('li3_doctrine2\\models\\ISession')) {
throw new ConfigException("The model {$this->config['model']} must implement ISession");
}
$this->entityManager = $this->config['entityManager'] ?: call_user_func($this->config['model'] . '::getEntityManager');
if (!isset($this->entityManager) || !$this->entityManager instanceof EntityManager) {
throw new ConfigException('Not a valid entity manager');
}
$this->repository = $this->entityManager->getRepository($this->config['model']);
foreach ($this->config['ini'] as $key => $config) {
if (isset($this->config['ini'][$key]) && ini_set("session.{$key}", $this->config['ini'][$key]) === false) {
throw new ConfigException("Could not initialize the session variable {$key}");
}
}
session_set_save_handler(array(&$this, '_open'), array(&$this, '_close'), array(&$this, '_read'), array(&$this, '_write'), array(&$this, '_destroy'), array(&$this, '_gc'));
register_shutdown_function('session_write_close');
if ($this->config['start']) {
$this->_startup();
}
}