Source of file PluginOptions.php
Size: 6,976 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Cache/Storage/Plugin/PluginOptions.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Cache\Storage\Plugin; use Zend\Cache\Exception; use Zend\Serializer\Adapter\AdapterInterface as SerializerAdapter; use Zend\Serializer\Serializer as SerializerFactory; use Zend\Stdlib\AbstractOptions; class PluginOptions extends AbstractOptions { /** * Used by: * - ClearByFactor * @var int */ protected $clearingFactor = 0; /** * Used by: * - ExceptionHandler * @var callable */ protected $exceptionCallback; /** * Used by: * - IgnoreUserAbort * @var bool */ protected $exitOnAbort = true; /** * Used by: * - OptimizeByFactor * @var int */ protected $optimizingFactor = 0; /** * Used by: * - Serializer * @var string|SerializerAdapter */ protected $serializer; /** * Used by: * - Serializer * @var array */ protected $serializerOptions = array(); /** * Used by: * - ExceptionHandler * @var bool */ protected $throwExceptions = true; /** * Set automatic clearing factor * * Used by: * - ClearExpiredByFactor * * @param int $clearingFactor * @return PluginOptions */ public function setClearingFactor($clearingFactor) { $this->clearingFactor = $this->normalizeFactor($clearingFactor); return $this; } /** * Get automatic clearing factor * * Used by: * - ClearExpiredByFactor * * @return int */ public function getClearingFactor() { return $this->clearingFactor; } /** * Set callback to call on intercepted exception * * Used by: * - ExceptionHandler * * @param callable $exceptionCallback * @throws Exception\InvalidArgumentException * @return PluginOptions */ public function setExceptionCallback($exceptionCallback) { if ($exceptionCallback !== null && !is_callable($exceptionCallback, true)) { throw new Exception\InvalidArgumentException('Not a valid callback'); } $this->exceptionCallback = $exceptionCallback; return $this; } /** * Get callback to call on intercepted exception * * Used by: * - ExceptionHandler * * @return null|callable */ public function getExceptionCallback() { return $this->exceptionCallback; } /** * Exit if connection aborted and ignore_user_abort is disabled. * * @param bool $exitOnAbort * @return PluginOptions */ public function setExitOnAbort($exitOnAbort) { $this->exitOnAbort = (bool) $exitOnAbort; return $this; } /** * Exit if connection aborted and ignore_user_abort is disabled. * * @return bool */ public function getExitOnAbort() { return $this->exitOnAbort; } /** * Set automatic optimizing factor * * Used by: * - OptimizeByFactor * * @param int $optimizingFactor * @return PluginOptions */ public function setOptimizingFactor($optimizingFactor) { $this->optimizingFactor = $this->normalizeFactor($optimizingFactor); return $this; } /** * Set automatic optimizing factor * * Used by: * - OptimizeByFactor * * @return int */ public function getOptimizingFactor() { return $this->optimizingFactor; } /** * Set serializer * * Used by: * - Serializer * * @param string|SerializerAdapter $serializer * @throws Exception\InvalidArgumentException * @return Serializer */ public function setSerializer($serializer) { if (!is_string($serializer) && !$serializer instanceof SerializerAdapter) { throw new Exception\InvalidArgumentException(sprintf( '%s expects either a string serializer name or Zend\Serializer\Adapter\AdapterInterface instance; ' . 'received "%s"', __METHOD__, (is_object($serializer) ? get_class($serializer) : gettype($serializer)) )); } $this->serializer = $serializer; return $this; } /** * Get serializer * * Used by: * - Serializer * * @return SerializerAdapter */ public function getSerializer() { if (!$this->serializer instanceof SerializerAdapter) { // use default serializer if (!$this->serializer) { $this->setSerializer(SerializerFactory::getDefaultAdapter()); // instantiate by class name + serializer_options } else { $options = $this->getSerializerOptions(); $this->setSerializer(SerializerFactory::factory($this->serializer, $options)); } } return $this->serializer; } /** * Set configuration options for instantiating a serializer adapter * * Used by: * - Serializer * * @param mixed $serializerOptions * @return PluginOptions */ public function setSerializerOptions($serializerOptions) { $this->serializerOptions = $serializerOptions; return $this; } /** * Get configuration options for instantiating a serializer adapter * * Used by: * - Serializer * * @return array */ public function getSerializerOptions() { return $this->serializerOptions; } /** * Set flag indicating we should re-throw exceptions * * Used by: * - ExceptionHandler * * @param bool $throwExceptions * @return PluginOptions */ public function setThrowExceptions($throwExceptions) { $this->throwExceptions = (bool) $throwExceptions; return $this; } /** * Should we re-throw exceptions? * * Used by: * - ExceptionHandler * * @return bool */ public function getThrowExceptions() { return $this->throwExceptions; } /** * Normalize a factor * * Cast to int and ensure we have a value greater than zero. * * @param int $factor * @return int * @throws Exception\InvalidArgumentException */ protected function normalizeFactor($factor) { $factor = (int) $factor; if ($factor < 0) { throw new Exception\InvalidArgumentException( "Invalid factor '{$factor}': must be greater or equal 0" ); } return $factor; } } |