public function instanceProvider()
 {
     $definitions = array();
     foreach ($this->definitionProvider() as $name => $definition) {
         if (!array_key_exists('message', $definition)) {
             $definition['message'] = 'test-' . $name;
         }
         $definition['name'] = $name;
         $definitions[] = array(ParamDefinitionFactory::singleton()->newDefinitionFromArray($definition));
     }
     return $definitions;
 }
예제 #2
0
 /**
  * @since 1.0
  *
  * @param Options $options
  *
  * @return ValueParser
  */
 public function getValueParser(Options $options)
 {
     $parser = $this->definition->getValueParser();
     if (get_class($parser) === 'ValueParsers\\NullParser') {
         $parserType = $options->isStringlyTyped() ? 'string-parser' : 'typed-parser';
         // TODO: inject factory
         $parserClass = ParamDefinitionFactory::singleton()->getComponentForType($this->definition->getType(), $parserType);
         if ($parserClass !== 'ValueParsers\\NullParser') {
             $parser = new $parserClass(new \ValueParsers\ParserOptions());
         }
     }
     return $parser;
 }
 /**
  * Returns a cleaned version of the list of parameter definitions.
  * This includes having converted all supported definition types to
  * ParamDefinition classes and having all keys set to the names of the
  * corresponding parameters.
  *
  * @since 1.0
  *
  * @param IParamDefinition[] $definitions
  *
  * @return IParamDefinition[]
  * @throws Exception
  */
 public static function getCleanDefinitions(array $definitions)
 {
     $cleanList = array();
     foreach ($definitions as $key => $definition) {
         if (is_array($definition)) {
             if (!array_key_exists('name', $definition) && is_string($key)) {
                 $definition['name'] = $key;
             }
             $definition = ParamDefinitionFactory::singleton()->newDefinitionFromArray($definition);
         }
         if (!$definition instanceof IParamDefinition) {
             throw new Exception('$definition not an instance of IParamDefinition');
         }
         $cleanList[$definition->getName()] = $definition;
     }
     return $cleanList;
 }