Exemple #1
0
 public static function processParameters($path, array $parameters = array())
 {
     preg_match_all('/\\{([a-zA-Z.]+)\\}/', $path, $matches);
     $paramNames = $matches[1];
     $roots = array_unique(array_map(function ($name) {
         return explode('.', $name)[0];
     }, $paramNames));
     if (count($roots) > count($parameters)) {
         throw InvalidParameterDefinitionException::countMismatch(count($matches[0]), count($parameters));
     }
     $result = [];
     foreach ($parameters as $parameter) {
         if (!$parameter instanceof ParameterDefinitionInterface) {
             throw InvalidParameterDefinitionException::invalidParameter($parameter);
         }
         $result[$parameter->getName()] = $parameter;
     }
     $pathParams = array_filter($paramNames, function ($paramName) {
         return strpos($paramName, '.') !== false;
     });
     foreach ($pathParams as $pathParam) {
         $exploded = explode('.', $pathParam, 2);
         list($root, $propPath) = $exploded;
         if (!PropertyAccess::isPathAccessible($result[$root]->getType(), $propPath)) {
             throw new InvalidResourceDefinitionException(sprintf('Path `%s` declared on `%s` is not accessible', $propPath, $root));
         }
     }
     return $result;
 }
 /**
  * @test
  */
 public function it_returns_false_for_undefined_properties()
 {
     static::assertFalse(PropertyAccess::isPathAccessible(Book::class, 'dogName'));
 }