isValid() 공개 정적인 메소드

public static isValid ( callable $callback ) : boolean
$callback callable
리턴 boolean
예제 #1
0
 /**
  * @group unit
  */
 public function testFailIsValid()
 {
     $isValid = CallbackStrategy::isValid(new \stdClass());
     $this->assertFalse($isValid);
     $isValid = CallbackStrategy::isValid('array_pop_pop_pop_pop_pop_pop');
     $this->assertFalse($isValid);
 }
예제 #2
0
 /**
  * @param mixed|Closure|String|StrategyInterface $strategyName
  * @return \Elastica\Connection\Strategy\StrategyInterface
  * @throws \Elastica\Exception\InvalidException
  */
 public static function create($strategyName)
 {
     $strategy = null;
     if ($strategyName instanceof StrategyInterface) {
         $strategy = $strategyName;
     } else {
         if (CallbackStrategy::isValid($strategyName)) {
             $strategy = new CallbackStrategy($strategyName);
             /*
                     } else if (is_string($strategyName) && class_exists($strategyName)) {
                         $strategy = new $strategyName(); */
         } else {
             if (is_string($strategyName)) {
                 $pathToStrategy = '\\Elastica\\Connection\\Strategy\\' . $strategyName;
                 if (class_exists($pathToStrategy)) {
                     $strategy = new $pathToStrategy();
                 }
             }
         }
     }
     if (!$strategy instanceof StrategyInterface) {
         throw new InvalidException('Can\'t load strategy class');
     }
     return $strategy;
 }
예제 #3
0
 /**
  * @param mixed|callable|string|StrategyInterface $strategyName
  *
  * @throws \Elastica\Exception\InvalidException
  *
  * @return \Elastica\Connection\Strategy\StrategyInterface
  */
 public static function create($strategyName)
 {
     if ($strategyName instanceof StrategyInterface) {
         return $strategyName;
     }
     if (CallbackStrategy::isValid($strategyName)) {
         return new CallbackStrategy($strategyName);
     }
     if (is_string($strategyName)) {
         $requiredInterface = '\\Elastica\\Connection\\Strategy\\StrategyInterface';
         $predefinedStrategy = '\\Elastica\\Connection\\Strategy\\' . $strategyName;
         if (class_exists($predefinedStrategy) && class_implements($predefinedStrategy, $requiredInterface)) {
             return new $predefinedStrategy();
         }
         if (class_exists($strategyName) && class_implements($strategyName, $requiredInterface)) {
             return new $strategyName();
         }
     }
     throw new InvalidException('Can\'t create strategy instance by given argument');
 }
예제 #4
0
 public function testFailIsValid()
 {
     $callback = new \stdClass();
     $isValid = CallbackStrategy::isValid($callback);
     $this->assertFalse($isValid);
 }