Пример #1
0
 /**
  * @param string $class
  * @return Robot
  */
 private function newRobot($Class)
 {
     Check::argument($Class and class_exists($Class), new ClientException("Robot class not found: {$Class}"));
     $robot = new $Class();
     if ($robot instanceof Robot) {
         return $robot;
     }
     throw new ClientException("class {$Class} is not a Vindinium\\Robot");
 }
Пример #2
0
 /**
  * @param object $value [description]
  * @param string|array $type one of 'bool', 'int', 'float', string', 'Namespace\\Class'
  * @return object
  */
 private function valueToType($value, $type)
 {
     if (is_array($type)) {
         Check::argument(is_array($value));
         $result = array();
         foreach ($value as $v) {
             $result[] = $this->valueToType($v, $type[0]);
         }
         return $result;
     }
     static $ALLOWED_TYPES = array('bool', 'int', 'float', 'string');
     if (in_array($type, $ALLOWED_TYPES)) {
         settype($value, $type);
     } elseif (class_exists($type)) {
         $value = new $type($value);
     } else {
         // @codeCoverageIgnoreStart
         throw new \InvalidArgumentException("unknown type: {$type}");
         // @codeCoverageIgnoreEnd
     }
     return $value;
 }