Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • Wei\Validator\All
  • Wei\Validator\AllOf
  • Wei\Validator\Alnum
  • Wei\Validator\Alpha
  • Wei\Validator\BaseValidator
  • Wei\Validator\Between
  • Wei\Validator\Blank
  • Wei\Validator\Callback
  • Wei\Validator\CharLength
  • Wei\Validator\Chinese
  • Wei\Validator\Color
  • Wei\Validator\Contains
  • Wei\Validator\CreditCard
  • Wei\Validator\Date
  • Wei\Validator\DateTime
  • Wei\Validator\Decimal
  • Wei\Validator\Digit
  • Wei\Validator\Dir
  • Wei\Validator\DivisibleBy
  • Wei\Validator\DoubleByte
  • Wei\Validator\Email
  • Wei\Validator\EndsWith
  • Wei\Validator\EqualTo
  • Wei\Validator\Exists
  • Wei\Validator\FieldExists
  • Wei\Validator\File
  • Wei\Validator\GreaterThan
  • Wei\Validator\GreaterThanOrEqual
  • Wei\Validator\IdCardCn
  • Wei\Validator\IdCardHk
  • Wei\Validator\IdCardMo
  • Wei\Validator\IdCardTw
  • Wei\Validator\IdenticalTo
  • Wei\Validator\Image
  • Wei\Validator\In
  • Wei\Validator\Ip
  • Wei\Validator\Length
  • Wei\Validator\LessThan
  • Wei\Validator\LessThanOrEqual
  • Wei\Validator\Lowercase
  • Wei\Validator\Luhn
  • Wei\Validator\MaxLength
  • Wei\Validator\MinLength
  • Wei\Validator\MobileCn
  • Wei\Validator\NaturalNumber
  • Wei\Validator\NoneOf
  • Wei\Validator\Null
  • Wei\Validator\Number
  • Wei\Validator\OneOf
  • Wei\Validator\Password
  • Wei\Validator\Phone
  • Wei\Validator\PhoneCn
  • Wei\Validator\PlateNumberCn
  • Wei\Validator\PositiveInteger
  • Wei\Validator\PostcodeCn
  • Wei\Validator\Present
  • Wei\Validator\QQ
  • Wei\Validator\RecordExists
  • Wei\Validator\Regex
  • Wei\Validator\Required
  • Wei\Validator\SomeOf
  • Wei\Validator\StartsWith
  • Wei\Validator\Time
  • Wei\Validator\Tld
  • Wei\Validator\Type
  • Wei\Validator\Uppercase
  • Wei\Validator\Url
  • Wei\Validator\Uuid
  • Overview
  • Namespace
  • Function
  1: <?php
  2: /**
  3:  * Wei Framework
  4:  *
  5:  * @copyright   Copyright (c) 2008-2015 Twin Huang
  6:  * @license     http://opensource.org/licenses/mit-license.php MIT License
  7:  */
  8: 
  9: namespace Wei;
 10: 
 11: /**
 12:  * A cache service proxy
 13:  *
 14:  * @author      Twin Huang <twinhuang@qq.com>
 15:  */
 16: class Cache extends BaseCache
 17: {
 18:     /**
 19:      * The storage wei object
 20:      *
 21:      * @var BaseCache
 22:      */
 23:     protected $object;
 24: 
 25:     /**
 26:      * The storage wei name
 27:      *
 28:      * @ver string
 29:      */
 30:     protected $driver = 'apc';
 31: 
 32:     /**
 33:      * Constructor
 34:      *
 35:      * @param array $options
 36:      */
 37:     public function __construct(array $options = array())
 38:     {
 39:         parent::__construct($options);
 40: 
 41:         if (!$this->object) {
 42:             $this->setDriver($this->driver);
 43:         }
 44:     }
 45: 
 46:     /**
 47:      * Set cache driver
 48:      *
 49:      * @param string $driver
 50:      * @return $this
 51:      * @throws \InvalidArgumentException
 52:      */
 53:     public function setDriver($driver)
 54:     {
 55:         $class = $this->wei->getClass($driver);
 56: 
 57:         if (!class_exists($class)) {
 58:             throw new \InvalidArgumentException(sprintf('Cache driver class "%s" not found', $class));
 59:         }
 60: 
 61:         if (!is_subclass_of($class, 'Wei\BaseCache')) {
 62:             throw new \InvalidArgumentException(sprintf('Cache driver class "%s" must extend "Wei\BaseCache"', $class));
 63:         }
 64: 
 65:         $this->driver = $driver;
 66:         $this->object = $this->wei->get($driver);
 67:         return $this;
 68:     }
 69: 
 70:     /**
 71:      * Returns current cache driver
 72:      *
 73:      * @return string
 74:      */
 75:     public function getDriver()
 76:     {
 77:         return $this->driver;
 78:     }
 79: 
 80:     /**
 81:      * {@inheritdoc}
 82:      */
 83:     public function get($key, $expire = null, $fn = null)
 84:     {
 85:         $result = $this->object->get($key);
 86:         return $this->processGetResult($key, $result, $expire, $fn);
 87:     }
 88: 
 89:     /**
 90:      * {@inheritdoc}
 91:      */
 92:     public function set($key, $value, $expire = 0)
 93:     {
 94:         return $this->object->set($key, $value, $expire);
 95:     }
 96: 
 97:     /**
 98:      * {@inheritdoc}
 99:      */
100:     public function remove($key)
101:     {
102:         return $this->object->remove($key);
103:     }
104: 
105:     /**
106:      * {@inheritdoc}
107:      */
108:     public function exists($key)
109:     {
110:         return $this->object->exists($key);
111:     }
112: 
113:     /**
114:      * {@inheritdoc}
115:      */
116:     public function add($key, $value, $expire = 0)
117:     {
118:         return $this->object->add($key, $value, $expire);
119:     }
120: 
121:     /**
122:      * {@inheritdoc}
123:      */
124:     public function replace($key, $value, $expire = 0)
125:     {
126:         return $this->object->replace($key, $value, $expire);
127:     }
128: 
129:     /**
130:      * {@inheritdoc}
131:      */
132:     public function incr($key, $offset = 1)
133:     {
134:         return $this->object->incr($key, $offset);
135:     }
136: 
137:     /**
138:      * {@inheritdoc}
139:      */
140:     public function clear()
141:     {
142:         return $this->object->clear();
143:     }
144: }
145: 
Wei Framework API documentation generated by ApiGen