コード例 #1
0
 /**
  * Get instance of array benchmarker
  *
  * @throws Exception
  * @param string $array
  * @return Adapter_Plain|Adapter_Object|Adapter_Fixed|Adapter_Judy
  */
 public static function instance($array)
 {
     switch ($array) {
         case self::ARRAY_PLAIN:
             self::$array = array();
             return new Adapter_Plain();
         case self::ARRAY_OBJECT:
             self::$array = new ArrayObject();
             return new Adapter_Object();
         case self::ARRAY_FIXED:
             self::$array = new SplFixedArray();
             return new Adapter_Fixed();
         case self::ARRAY_JUDY:
             self::$array = new Judy(Judy::INT_TO_MIXED);
             return new Adapter_Judy();
     }
     throw new Exception('Array type you passed is currently not supported.');
 }
コード例 #2
0
 /**
  * Get instance of client benchmarker
  *
  * @throws Exception
  * @param string $client
  * @param string $serializer
  * @return Benchmarker_Memcache|Benchmarker_Memcached|Benchmarker_Redis
  */
 public static function instance($client, $serializer = self::SERIALIZER_PHP)
 {
     switch ($serializer) {
         case self::SERIALIZER_INTERNAL:
         case self::SERIALIZER_IGBINARY:
         case self::SERIALIZER_PHP:
             self::$serializer = $serializer;
             break;
         default:
             throw new Exception('Serializer you passed is currently not supported.');
     }
     switch ($client) {
         case self::CLIENT_PREDIS:
             self::$client = new Predis();
             return new Adapter_Redis();
         case self::CLIENT_REDIS:
             self::$client = new Redis();
             self::$client->connect('127.0.0.1');
             return new Adapter_Redis();
         case self::CLIENT_MEMCACHED:
             self::$client = new Memcached();
             self::$client->addServer('127.0.0.1', 11211);
             return new Adapter_Memcached();
         case self::CLIENT_MEMCACHE:
             self::$client = new Memcache();
             self::$client->addServer('127.0.0.1', 11211);
             return new Adapter_Memcache();
     }
     throw new Exception('Client you passed is currently not supported.');
 }