コード例 #1
0
 public function findRepositoryName($className)
 {
     //Check repository name using convention of "Repository" suffix
     //in the same namespace.
     //C.o.C is awesome, you should use it !!
     $repoName = "{$className}Repository";
     if (class_exists($repoName) && in_array("Spot\\Domain\\Repository", class_implements($repoName)) && $repoName::repositoryOf() == $className) {
         return $repoName;
     }
     $repos = $this->reflection->find(substr($className, 0, strpos($className, "\\")), Match::instantiableOnly()->andIt(Match::subTypeOf("Spot\\Domain\\Repository")));
     foreach ($repos as $repo) {
         $repoName = $repo->name;
         if ($repoName::repositoryOf() == $className) {
             return $repoName;
         }
     }
     // search class inheritance hierarchies
     $candidates = [];
     $classParents = array_values(class_parents($className) ?: []);
     foreach ($repos as $repo) {
         $repoName = $repo->name;
         $index = array_search($repoName::repositoryOf(), $classParents);
         if ($index !== false) {
             $candidates[$index] = $repoName;
         }
     }
     if (!empty($candidates)) {
         // check closest candidates
         return $candidates[min(array_keys($candidates))];
     }
     throw new \RuntimeException("Repository of {$className} can't be found");
 }
コード例 #2
0
 /** @Provides @Named("symfony.console.commands") */
 static function provideCommands(Injector $injector, Reflection $reflection, array $namespaces = [], array $commands = [], array $groups = [])
 {
     $matcher = Match::subtypeOf("Symfony\\Component\\Console\\Command\\Command");
     foreach ($namespaces as $ns) {
         foreach ($reflection->find($ns, $matcher) as $type) {
             $commands[] = $injector->getInstance($type->name);
         }
     }
     foreach ($groups as $groupedCommands) {
         $commands = array_merge($commands, $groupedCommands);
     }
     return $commands;
 }
コード例 #3
0
 public function scan()
 {
     $mappings = [];
     $matcher = Match::annotatedWith("Spot\\App\\REST\\Resource");
     foreach ($this->namespaces as $ns) {
         foreach ($this->reflection->find($ns, $matcher) as $type) {
             $resource = $type->getAnnotation("Spot\\App\\REST\\Resource");
             foreach ($type->getMethods(Method::IS_PUBLIC) as $method) {
                 if (!$method->isAnnotatedWith("Spot\\App\\REST\\Impl\\RequestMethod")) {
                     continue;
                 }
                 $path = $method->getAnnotation("Spot\\App\\REST\\Path") ?: new Path();
                 $route = new Route();
                 $route->value = $resource->value . $path->value;
                 $route->method = (string) $method->getAnnotation("Spot\\App\\REST\\Impl\\RequestMethod");
                 $mappings[] = new ActionMapping($route, $method->getType()->name . "::" . $method->name);
             }
         }
     }
     return $mappings;
 }
コード例 #4
0
 public function scan()
 {
     $mappings = [];
     $matcher = Match::annotatedWith("Spot\\App\\Web\\Controller");
     foreach ($this->namespaces as $ns) {
         foreach ($this->reflection->find($ns, $matcher) as $type) {
             $typeRoute = $type->getAnnotation("Spot\\App\\Web\\Route") ?: new Route();
             foreach ($type->getMethods(Method::IS_PUBLIC) as $method) {
                 if (!$method->isAnnotatedWith("Spot\\App\\Web\\Route")) {
                     continue;
                 }
                 $route = $method->getAnnotation("Spot\\App\\Web\\Route");
                 $route->value = $typeRoute->value . $route->value;
                 $route->ajax = $route->ajax === null ? $typeRoute->ajax : $route->ajax;
                 $route->method = $route->method ?: $typeRoute->method ?: [Request::GET, Request::POST];
                 if (!isset($route->value[0]) || $route->value[0] != "/") {
                     throw new \LogicException("Controller uri must start with \"/\"");
                 }
                 $mappings[] = new ActionMapping($route, $method->getType()->name . "::" . $method->name);
             }
         }
     }
     return $mappings;
 }