Jyxo\Input\Factory::getValidatorByName PHP 메소드

getValidatorByName() 공개 메소드

Returns a particular validator by its name.
public getValidatorByName ( string | Jyxo\Input\ValidatorInterface $name, mixed | array $param = null ) : Jyxo\Input\ValidatorInterface
$name string | Jyxo\Input\ValidatorInterface Validator name
$param mixed | array Validator constructor parameters. In case of a single parameter it can be its value, an array of values otherwise. NULL in case of no parameter.
리턴 Jyxo\Input\ValidatorInterface
    public function getValidatorByName($name, $param = null) : \Jyxo\Input\ValidatorInterface
    {
        if ($name instanceof \Jyxo\Input\ValidatorInterface) {
            return $name;
        }
        $params = (array) $param;
        $className = $this->findClass($name, self::$validatorPrefix);
        if (!$className) {
            throw new Exception(sprintf('Could not found "%s" validator', $name));
        }
        return $this->getClass($className, $params);
    }

Usage Example

예제 #1
0
파일: Fluent.php 프로젝트: jyxo/php
 /**
  * Adds a conditional chain.
  *
  * If there are conditions in the current chain, adds the condition as a subchain.
  *
  * @param string $name Validator name
  * @param mixed $param Additional validator parameter
  * @return \Jyxo\Input\Fluent
  * @throws \BadMethodCallException There is no active variable
  */
 public function condition(string $name, $param = null) : self
 {
     $condChain = new Chain\Conditional($this->factory->getValidatorByName($name, $param));
     if (true === $this->chain->isEmpty()) {
         // The actual chain is empty, can be replaced by the condition
         $this->chain = $condChain;
         if (null === $this->currentName) {
             throw new \BadMethodCallException('No active variable');
         }
         $this->chains[$this->currentName] = $condChain;
     } else {
         $this->chain = $this->chain->addCondition($condChain);
     }
     return $this;
 }
All Usage Examples Of Jyxo\Input\Factory::getValidatorByName