本文整理汇总了PHP中Zend\Cache\Storage\Adapter\AbstractAdapter类的典型用法代码示例。如果您正苦于以下问题:PHP AbstractAdapter类的具体用法?PHP AbstractAdapter怎么用?PHP AbstractAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkPreEventCanChangeArguments
protected function checkPreEventCanChangeArguments($method, array $args, array $expectedArgs)
{
$internalMethod = 'internal' . ucfirst($method);
$eventName = $method . '.pre';
// init mock
$this->_storage = $this->getMockForAbstractAdapter(array($internalMethod));
$this->_storage->getEventManager()->attach($eventName, function ($event) use($expectedArgs) {
$params = $event->getParams();
foreach ($expectedArgs as $k => $v) {
$params[$k] = $v;
}
});
// set expected arguments of internal method call
$tmp = $this->_storage->expects($this->once())->method($internalMethod);
$equals = array();
foreach ($expectedArgs as $v) {
$equals[] = $this->equalTo($v);
}
call_user_func_array(array($tmp, 'with'), $equals);
// run
call_user_func_array(array($this->_storage, $method), $args);
}
示例2: getSizes
/**
* Returns sizes array for photo identified by Flickr photo id
*
* @param int $photoId
* @return array Array of photo size information
*/
public function getSizes($photoId)
{
$sizes = $this->adapter->getItem($photoId);
if (is_null($sizes)) {
$sizes = $this->flickr->getSizes($photoId);
$this->adapter->addItem($photoId, $sizes);
}
return $sizes;
}
示例3: setOptions
/**
* Set options.
*
* @param array|\Traversable|SessionOptions $options
* @return Memory
* @see getOptions()
*/
public function setOptions($options)
{
if (!$options instanceof SessionOptions) {
$options = new SessionOptions($options);
}
return parent::setOptions($options);
}
示例4: manageAction
/**
* All a user to add and update a feed in the application
*
* @return ViewModel
*/
public function manageAction()
{
$formManager = $this->serviceLocator->get('FormElementManager');
$form = $formManager->get('BabyMonitor\\Forms\\ManageRecordForm');
$feedId = (int) $this->params()->fromRoute('id');
if ($this->getRequest()->isGet()) {
if (!empty($feedId)) {
if ($feed = $this->_feedTable->fetchById($feedId)) {
$form->setData($feed->getArrayCopy());
} else {
$this->flashMessenger()->addInfoMessage('Unable to find that feed. Perhaps a new one?');
return $this->redirect()->toRoute(self::DEFAULT_ROUTE, array('action' => 'manage'));
}
}
}
if ($this->getRequest()->isPost()) {
$form->setData($this->getRequest()->getPost());
if ($form->isValid()) {
$feed = new FeedModel();
$feed->exchangeArray($form->getData());
$this->_feedTable->save($feed);
if (!is_null($this->_cache)) {
$this->_cache->removeItem(self::KEY_ALL_RESULTS);
}
$this->getEventManager()->trigger('Feed.Modify', $this, array('feedData' => $feed));
return $this->redirect()->toRoute(self::DEFAULT_ROUTE, array());
}
}
return new ViewModel(array('form' => $form, 'cancelTitle' => $feedId ? "Don't update the record" : "Don't create the record", 'messages' => array('info' => $this->flashMessenger()->hasInfoMessages())));
}
示例5: setOptions
/**
* Set options.
*
* @param array|Traversable|WinCacheOptions $options
* @return WinCache
* @see getOptions()
*/
public function setOptions($options)
{
if (!$options instanceof WinCacheOptions) {
$options = new WinCacheOptions($options);
}
return parent::setOptions($options);
}
示例6: setOptions
/**
* Set options.
*
* @param array|\Traversable|MemoryOptions $options
* @return Memory
* @see getOptions()
*/
public function setOptions($options)
{
if (!$options instanceof MemoryOptions) {
$options = new MemoryOptions($options);
}
return parent::setOptions($options);
}
示例7: setOptions
/**
* Set options.
*
* @param array|Traversable|ApcOptions $options
* @return Apc
* @see getOptions()
*/
public function setOptions($options)
{
if (!$options instanceof ApcOptions) {
$options = new ApcOptions($options);
}
return parent::setOptions($options);
}
示例8: persist
/**
* @param $entity
*
* @return mixed
* @throws \InvalidArgumentException If the ResultSetPrototype is not Hydrating
* @throws \InvalidArgumentException If a BaseEntity object is not provided
*/
public function persist($entity)
{
if (!$this->getResultSetPrototype() instanceof HydratingResultSet) {
throw new \InvalidArgumentException('Result Set Prototype is not configured correctly');
}
if (!$entity instanceof BaseEntity) {
throw new \InvalidArgumentException('Can only persist object entities');
}
$hydrator = $this->getResultSetPrototype()->getHydrator();
$data = $hydrator->extract($entity);
$sql = $this->getSql();
$identifierName = $this->getIdentifierName();
$identifier = null;
if (array_key_exists($identifierName, $data)) {
$identifier = $data[$identifierName];
unset($data[$identifierName]);
}
array_walk($data, function (&$value) {
if ($value instanceof \DateTime) {
$value = $value->format('Y-m-d H:i:s');
}
});
if (!empty($identifier)) {
// UPDATE
$data['lastModified'] = date('Y-m-d H:i:s');
$where = array();
$where[$identifierName] = $identifier;
$statement = $sql->prepareStatementForSqlObject($sql->update()->set($data)->where($where));
$result = $statement->execute();
unset($statement, $result);
// cleanup
} else {
// INSERT
$data['createdDatetime'] = date('Y-m-d H:i:s');
$data['status'] = '1';
$data['lastModified'] = date('Y-m-d H:i:s');
$insert = $sql->insert();
$insert->values($data);
$statement = $sql->prepareStatementForSqlObject($insert);
$result = $statement->execute();
$identifier = $result->getGeneratedValue();
unset($statement, $result);
// cleanup
$where = array();
$where[$identifierName] = $identifier;
}
// refresh data
$statement = $sql->prepareStatementForSqlObject($this->sql->select()->where($where));
$result = $statement->execute();
$rowData = $result->current();
unset($statement, $result);
// cleanup
$hydrator->hydrate($rowData, $entity);
if ($this->cacheAdapter instanceof CacheAdapter) {
$this->cacheAdapter->setItem($this->getCacheKeyHash($entity->getId()), $entity);
}
return $entity;
}
示例9: build
/**
* @inheritdoc
*/
public function build()
{
if ($this->built) {
return;
}
$key = 'assets-manager';
if ($this->cacheAdapter->hasItem($key)) {
$data = $this->cacheAdapter->getItem($key);
$assetManager = unserialize($data);
if ($assetManager instanceof AssetManager) {
$this->setAssetManager($assetManager);
return;
}
}
parent::build();
$this->cacheAdapter->setItem($key, serialize($this->getAssetManager()));
$this->built = true;
}
示例10: flush
/**
* Flush the whole storage
*
* @return bool
*/
public function flush()
{
if (!$this->cache instanceof FlushableInterface) {
return false;
}
try {
return $this->cache->flush();
} catch (ZendException\ExceptionInterface $ex) {
return false;
}
}
示例11: clearItem
/**
* Remove an item from the cache
* @param string $key
* @return boolean
*/
public function clearItem($key)
{
//check if caching is enabled
$arr_config = $this->getServiceLocator()->get("config");
if ($arr_config["front_end_application_config"]["cache_enabled"] == FALSE) {
return FALSE;
}
//end if
//adjust key
$key = $this->setIdentifier($key);
$this->storageFactory->removeItem($key);
}
示例12: __construct
/**
* Constructor
*
* @param array|Traversable|WinCacheOptions $options
* @throws Exception
* @return void
*/
public function __construct($options = null)
{
if (!extension_loaded('wincache')) {
throw new Exception\ExtensionNotLoadedException("WinCache extension is not loaded");
}
$enabled = ini_get('wincache.ucenabled');
if (PHP_SAPI == 'cli') {
$enabled = $enabled && (bool) ini_get('wincache.enablecli');
}
if (!$enabled) {
throw new Exception\ExtensionNotLoadedException("WinCache is disabled - see 'wincache.ucenabled' and 'wincache.enablecli'");
}
parent::__construct($options);
}
示例13: onFinish
/**
* Cache Response for future requests
*
* @param MvcEvent $e
* @return \Zend\Stdlib\ResponseInterface
*/
public function onFinish(MvcEvent $e)
{
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
return;
}
if (!$request->isGet()) {
return;
}
$response = $e->getResponse();
if ($response instanceof HttpResponse && !$response->isOk()) {
return;
}
// Do not continue if weren't able to compose a key
if (empty($this->cache_key)) {
return;
}
if (!$this->cacheAdapter->hasItem($this->cache_key)) {
$resourceIdentifier = $e->getRouteMatch()->getParam('resource');
$resource = call_user_func($this->getResourceLocatorService(), $resourceIdentifier);
if (!$resource instanceof Resource || !$resource->isCacheable()) {
return;
}
// Generate Response cache headers based on Resource CacheOptions
$cacheOptions = $resource->getCacheOptions();
$cacheControl = new CacheControl();
$cacheControl->addDirective($cacheOptions->getAccess());
$cacheControl->addDirective('max-age', $cacheOptions->getMaxAge());
$cacheControl->addDirective('expires', $cacheOptions->getExpires());
$cacheControl->addDirective('must-revalidate');
$dateTime = new \DateTime();
$dateTime->modify('+ ' . $cacheOptions->getExpires() . 'seconds');
$expires = new Expires();
$expires->setDate($dateTime);
$lastModified = new LastModified();
$lastModified->setDate(new \DateTime());
// Add Headers to Response Header
$response->getHeaders()->addHeader($cacheControl);
$response->getHeaders()->addHeader($expires);
$response->getHeaders()->addHeaderLine('Pragma: ' . $cacheOptions->getAccess());
$response->getHeaders()->addHeader(Etag::fromString('Etag: ' . md5($response->getBody())));
$response->getHeaders()->addHeader($lastModified);
// Set cache adapter's TTL using Resource cache expires value
$this->cacheAdapter->getOptions()->setTtl($cacheOptions->getExpires());
$this->cacheAdapter->setItem($this->cache_key, $response);
//return $response;
}
}
示例14: __construct
/**
* Constructor
*
* @param null|array|Traversable|MemcachedOptions $options
* @throws Exception
* @return void
*/
public function __construct($options = null)
{
if (static::$extMemcachedMajorVersion === null) {
$v = (string) phpversion('memcached');
static::$extMemcachedMajorVersion = $v !== '' ? (int) $v[0] : 0;
}
if (static::$extMemcachedMajorVersion < 1) {
throw new Exception\ExtensionNotLoadedException('Need ext/memcached version >= 1.0.0');
}
$this->memcached = new MemcachedResource();
parent::__construct($options);
// It's ok to add server as soon as possible because
// ext/memcached auto-connects to the server on first use
// TODO: Handle multiple servers
$options = $this->getOptions();
$this->memcached->addServer($options->getServer(), $options->getPort());
}
示例15: __construct
/**
* Constructor
*
* @param null|array|Traversable|ApcOptions $options
* @throws Exception
* @return void
*/
public function __construct($options = null)
{
if (version_compare('3.1.6', phpversion('apc')) > 0) {
throw new Exception\ExtensionNotLoadedException("Missing ext/apc >= 3.1.6");
}
$enabled = ini_get('apc.enabled');
if (PHP_SAPI == 'cli') {
$enabled = $enabled && (bool) ini_get('apc.enable_cli');
}
if (!$enabled) {
throw new Exception\ExtensionNotLoadedException("ext/apc is disabled - see 'apc.enabled' and 'apc.enable_cli'");
}
// init select map
if (static::$selectMap === null) {
static::$selectMap = array('value' => \APC_ITER_VALUE, 'mtime' => \APC_ITER_MTIME, 'ctime' => \APC_ITER_CTIME, 'atime' => \APC_ITER_ATIME, 'rtime' => \APC_ITER_DTIME, 'ttl' => \APC_ITER_TTL, 'num_hits' => \APC_ITER_NUM_HITS, 'ref_count' => \APC_ITER_REFCOUNT, 'mem_size' => \APC_ITER_MEM_SIZE, 'internal_key' => \APC_ITER_KEY);
}
parent::__construct($options);
}