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 that stored data in Couchbase
 13:  *
 14:  * @author      Twin Huang <twinhuang@qq.com>
 15:  * @link        https://github.com/couchbase/php-ext-couchbase
 16:  */
 17: class Couchbase extends BaseCache
 18: {
 19:     /**
 20:      * An array of hostnames[:port] where the Couchbase cluster is running. The
 21:      * port number is optional (and only needed if you're using a non-standard
 22:      * port).
 23:      *
 24:      * @var array|string
 25:      */
 26:     protected $hosts = '127.0.0.1:8091';
 27: 
 28:     /**
 29:      * The username used for authentication to the cluster
 30:      *
 31:      * @var string
 32:      */
 33:     protected $user;
 34: 
 35:     /**
 36:      * The password used to authenticate to the cluster
 37:      *
 38:      * @var string
 39:      */
 40:     protected $password;
 41: 
 42:     /**
 43:      * The name of the bucket to connect to
 44:      *
 45:      * @var string
 46:      */
 47:     protected $bucket = 'default';
 48: 
 49:     /**
 50:      * If a persistent object should be used or not
 51:      *
 52:      * @var bool
 53:      */
 54:     protected $persistent = true;
 55: 
 56:     /**
 57:      * The couchbase object
 58:      *
 59:      * @var \Couchbase
 60:      */
 61:     protected $object;
 62: 
 63:     /**
 64:      * Constructor
 65:      *
 66:      * @param array $options
 67:      */
 68:     public function __construct(array $options = array())
 69:     {
 70:         parent::__construct($options);
 71: 
 72:         if (!$this->object) {
 73:             $this->object = new \Couchbase($this->hosts, $this->user, $this->password, $this->bucket, $this->persistent);
 74:         }
 75:     }
 76: 
 77:     /**
 78:      * {@inheritdoc}
 79:      */
 80:     public function get($key, $expire = null, $fn = null)
 81:     {
 82:         $result = $this->object->get($this->namespace . $key);
 83:         return $this->processGetResult($key, $result, $expire, $fn);
 84:     }
 85: 
 86:     /**
 87:      * {@inheritdoc}
 88:      */
 89:     public function set($key, $value, $expire = 0)
 90:     {
 91:         return $this->object->set($this->namespace . $key, $value, $expire);
 92:     }
 93: 
 94:     /**
 95:      * {@inheritdoc}
 96:      */
 97:     public function remove($key)
 98:     {
 99:         return $this->object->delete($this->namespace . $key);
100:     }
101: 
102:     /**
103:      * {@inheritdoc}
104:      */
105:     public function exists($key)
106:     {
107:         if ($this->object->add($key, true)) {
108:             $this->object->delete($key);
109:             return false;
110:         }
111:         return true;
112:     }
113: 
114:     /**
115:      * {@inheritdoc}
116:      */
117:     public function add($key, $value, $expire = 0)
118:     {
119:         return (bool)$this->object->add($this->namespace . $key, $value, $expire);
120:     }
121: 
122:     /**
123:      * {@inheritdoc}
124:      */
125:     public function replace($key, $value, $expire = 0)
126:     {
127:         return (bool)$this->object->replace($this->namespace . $key, $value, $expire);
128:     }
129: 
130:     /**
131:      * {@inheritdoc}
132:      */
133:     public function incr($key, $offset = 1)
134:     {
135:         return $this->object->inc($this->namespace . $key, $offset, true, 0, $offset);
136:     }
137: 
138:     /**
139:      * {@inheritdoc}
140:      *
141:      * @throws \CouchbaseServerException when flush is disabled for the bucket
142:      * @link http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-admin-web-console-data-buckets-createedit.html
143:      * @link http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-admin-cli-flushing.html
144:      */
145:     public function clear()
146:     {
147:         return $this->object->flush();
148:     }
149: 
150:     /**
151:      * {@inheritdoc}
152:      */
153:     public function getMulti(array $keys)
154:     {
155:         return $this->object->getMulti($keys);
156:     }
157: 
158:     /**
159:      * {@inheritdoc}
160:      */
161:     public function setMulti(array $items, $expire = 0)
162:     {
163:         $results = $this->object->setMulti($items, $expire);
164:         foreach ($results as &$result) {
165:             $result = (bool)$result;
166:         }
167:         return $results;
168:     }
169: 
170:     /**
171:      * Get couchbase object
172:      *
173:      * @return \Couchbase
174:      */
175:     public function getObject()
176:     {
177:         return $this->object;
178:     }
179: 
180:     /**
181:      * Set couchbase object
182:      *
183:      * @param \Couchbase $object
184:      * @return $this
185:      */
186:     public function setObject(\Couchbase $object)
187:     {
188:         $this->object = $object;
189:         return $this;
190:     }
191: }
192: 
Wei Framework API documentation generated by ApiGen