Example #1
0
 /**
  * Helper method to get all REST services.
  *
  * @todo Build a cache for this!
  *
  * @return  array
  */
 protected function getRestServices()
 {
     /**
      * Lambda function to get all service classes that exists in application.
      *
      * @param   string  $file
      *
      * @return  null|\stdClass
      */
     $iterator = function ($file) {
         // Specify service class name with namespace
         $className = '\\App\\Services\\' . str_replace('.php', '', basename($file));
         // Get reflection about controller class
         $reflectionClass = new \ReflectionClass($className);
         if (!$reflectionClass->isAbstract() && $reflectionClass->implementsInterface('\\App\\Services\\Interfaces\\Rest')) {
             $bits = explode('\\', $reflectionClass->getName());
             // Create output
             $output = new \stdClass();
             $output->class = $reflectionClass->getName();
             $output->name = 'service.' . end($bits);
             return $output;
         }
         return null;
     };
     return array_filter(array_map($iterator, glob($this->app->getRootDir() . 'src/App/Services/*.php')));
 }
 /**
  * Getter for mount points and actual controller classes for those.
  *
  * @todo Build a cache for this!
  *
  * @return  array
  */
 private function getMountPoints()
 {
     // Create doc block factory
     $factory = DocBlockFactory::createInstance();
     /**
      * Lambda function to iterate all controller classes to return mount points to each of them.
      *
      * @param   string  $file
      *
      * @return  null|\stdClass
      */
     $iterator = function ($file) use($factory) {
         // Specify controller class name with namespace
         $className = '\\App\\Controllers\\' . str_replace('.php', '', basename($file));
         // Get reflection about controller class
         $reflectionClass = new \ReflectionClass($className);
         // We're not interested about abstract classes
         if ($reflectionClass->isAbstract()) {
             return null;
         }
         // Get 'mountPoint' tags from class comment block
         $tags = $factory->create($reflectionClass->getDocComment())->getTagsByName('mountPoint');
         // Nice, we have one 'mountPoint' tag in comments, so we'll use that
         if (count($tags) === 1) {
             $tag = $tags[0];
             // Normalize mount point name
             $mountPoint = trim(str_replace('@' . $tag->getName(), '', $tag->render()));
             // Create output
             $output = new \stdClass();
             $output->mountPoint = $mountPoint;
             $output->controller = $className;
             return $output;
         }
         return null;
     };
     return array_filter(array_map($iterator, glob($this->app->getRootDir() . 'src/App/Controllers/*.php')));
 }
Example #3
0
 /**
  * Getter method for DoctrineMigrationsProvider options.
  *
  * @see https://github.com/kurlltd/silex-doctrine-migrations-provider#usage
  *
  * @return array
  */
 private function getDoctrineMigrationsProviderOptions()
 {
     return ['migrations.directory' => $this->silexApp->getRootDir() . 'resources/migrations', 'migrations.name' => 'App Migrations', 'migrations.namespace' => 'App\\Migrations', 'migrations.table_name' => 'db_migrations'];
 }