作者:bradley-hol
项目:zf
public function testTriggerChangeEventOfBaseCapabilities()
{
$em = $this->_capabilities->getEventManager();
$this->assertInstanceOf('Zend\\EventManager\\EventManager', $em);
$event = null;
$em->attach('change', function ($eventArg) use(&$event) {
$event = $eventArg;
});
$this->_baseCapabilities->setMaxTtl($this->_marker, 100);
$this->assertInstanceOf('Zend\\EventManager\\Event', $event);
$this->assertEquals('change', $event->getName());
$this->assertSame($this->_baseCapabilities, $event->getTarget());
$this->assertEquals(array('maxTtl' => 100), $event->getParams());
}
作者:nevvermin
项目:zf
/**
* Get the event manager
*
* @return EventManager
* @throws Exception\MissingDependencyException
*/
public function getEventManager()
{
if ($this->eventManager instanceof EventManager) {
return $this->eventManager;
}
if (!class_exists('Zend\\EventManager\\EventManager')) {
throw new Exception\MissingDependencyException('Zend\\EventManager\\EventManager not found');
}
// create a new event manager object
$eventManager = new EventManager();
// trigger change event on change of a base capability
if ($this->baseCapabilities && $this->baseCapabilities->hasEventManager()) {
$onChange = function ($event) use($eventManager) {
$eventManager->trigger('change', $event->getTarget(), $event->getParams());
};
$this->baseCapabilities->getEventManager()->attach('change', $onChange);
}
// register event manager
$this->eventManager = $eventManager;
return $this->eventManager;
}
作者:haoyanfe
项目:zf
/**
* Internal method to get capabilities of this adapter
*
* @return Capabilities
*/
protected function internalGetCapabilities()
{
if ($this->capabilities === null) {
$marker = new stdClass();
$capabilities = new Capabilities($this, $marker, array('supportedDatatypes' => array('NULL' => true, 'boolean' => true, 'integer' => true, 'double' => true, 'string' => true, 'array' => true, 'object' => 'object', 'resource' => false), 'supportedMetadata' => array('internal_key', 'atime', 'ctime', 'mtime', 'rtime', 'size', 'hits', 'ttl'), 'minTtl' => 1, 'maxTtl' => 0, 'staticTtl' => true, 'ttlPrecision' => 1, 'useRequestTime' => (bool) ini_get('apc.use_request_time'), 'expiredRead' => false, 'maxKeyLength' => 5182, 'namespaceIsPrefix' => true, 'namespaceSeparator' => $this->getOptions()->getNamespaceSeparator()));
// update namespace separator on change option
$this->getEventManager()->attach('option', function ($event) use($capabilities, $marker) {
$params = $event->getParams();
if (isset($params['namespace_separator'])) {
$capabilities->setNamespaceSeparator($marker, $params['namespace_separator']);
}
});
$this->capabilities = $capabilities;
$this->capabilityMarker = $marker;
}
return $this->capabilities;
}
作者:till
项目:vufin
/**
* Internal method to get capabilities of this adapter
*
* @return Capabilities
*/
protected function internalGetCapabilities()
{
if ($this->capabilities === null) {
$marker = new stdClass();
$options = $this->getOptions();
// detect metadata
$metadata = array('mtime', 'filespec');
if (!$options->getNoAtime()) {
$metadata[] = 'atime';
}
if (!$options->getNoCtime()) {
$metadata[] = 'ctime';
}
$capabilities = new Capabilities($this, $marker, array('supportedDatatypes' => array('NULL' => 'string', 'boolean' => 'string', 'integer' => 'string', 'double' => 'string', 'string' => true, 'array' => false, 'object' => false, 'resource' => false), 'supportedMetadata' => $metadata, 'minTtl' => 1, 'maxTtl' => 0, 'staticTtl' => false, 'ttlPrecision' => 1, 'expiredRead' => true, 'maxKeyLength' => 251, 'namespaceIsPrefix' => true, 'namespaceSeparator' => $options->getNamespaceSeparator()));
// update capabilities on change options
$this->getEventManager()->attach('option', function ($event) use($capabilities, $marker) {
$params = $event->getParams();
if (isset($params['namespace_separator'])) {
$capabilities->setNamespaceSeparator($marker, $params['namespace_separator']);
}
if (isset($params['no_atime']) || isset($params['no_ctime'])) {
$metadata = $capabilities->getSupportedMetadata();
if (isset($params['no_atime']) && !$params['no_atime']) {
$metadata[] = 'atime';
} elseif (isset($params['no_atime']) && ($index = array_search('atime', $metadata)) !== false) {
unset($metadata[$index]);
}
if (isset($params['no_ctime']) && !$params['no_ctime']) {
$metadata[] = 'ctime';
} elseif (isset($params['no_ctime']) && ($index = array_search('ctime', $metadata)) !== false) {
unset($metadata[$index]);
}
$capabilities->setSupportedMetadata($marker, $metadata);
}
});
$this->capabilityMarker = $marker;
$this->capabilities = $capabilities;
}
return $this->capabilities;
}
作者:till
项目:vufin
/**
* Internal method to get capabilities of this adapter
*
* @return Capabilities
*/
protected function internalGetCapabilities()
{
if ($this->capabilities === null) {
$marker = new stdClass();
$capabilities = new Capabilities($this, $marker, array('supportedDatatypes' => array('NULL' => 'string', 'boolean' => 'string', 'integer' => 'string', 'double' => 'string', 'string' => true, 'array' => false, 'object' => false, 'resource' => false), 'minTtl' => 0, 'supportedMetadata' => array(), 'maxKeyLength' => 0, 'namespaceIsPrefix' => true, 'namespaceSeparator' => $this->getOptions()->getNamespaceSeparator()));
// update namespace separator on change option
$this->getEventManager()->attach('option', function ($event) use($capabilities, $marker) {
$params = $event->getParams();
if (isset($params['namespace_separator'])) {
$capabilities->setNamespaceSeparator($marker, $params['namespace_separator']);
}
});
$this->capabilities = $capabilities;
$this->capabilityMarker = $marker;
}
return $this->capabilities;
}
作者:razvansividr
项目:pnlzf2-
public function testTriggerCapabilityEvent()
{
$em = $this->_capabilities->getAdapter()->getEventManager();
$event = null;
$em->attach('capability', function ($eventArg) use(&$event) {
$event = $eventArg;
});
$this->_capabilities->setMaxTtl($this->_marker, 100);
$this->assertInstanceOf('Zend\\EventManager\\Event', $event);
$this->assertEquals('capability', $event->getName());
$this->assertSame($this->_adapter, $event->getTarget());
$params = $event->getParams();
$this->assertInstanceOf('ArrayObject', $params);
$this->assertTrue(isset($params['maxTtl']));
$this->assertEquals(100, $params['maxTtl']);
}