예제 #1
0
 /**
  * Scan the filesystem for swagger annotations and build swagger-documentation.
  *
  * @param string|array|Finder $directory The directory(s) or filename(s)
  * @param array $options 
  *   exclude: string|array $exclude The directory(s) or filename(s) to exclude (as absolute or relative paths)
  *   analyser: defaults to StaticAnalyser
  *   analysis: defaults to a new Analysis
  *   processors: defaults to the registered processors in Analysis
  * @return Swagger
  */
 function scan($directory, $options = array())
 {
     $analyser = @$options['analyser'] ?: new StaticAnalyser();
     $analysis = @$options['analysis'] ?: new Analysis();
     $processors = @$options['processors'] ?: Analysis::processors();
     $exclude = @$options['exclude'] ?: null;
     // Crawl directory and parse all files
     $finder = Util::finder($directory, $exclude);
     foreach ($finder as $file) {
         $analysis->addAnalysis($analyser->fromFile($file->getPathname()));
     }
     // Post processing
     $analysis->process($processors);
     // Validation (Generate notices & warnings)
     $analysis->validate();
     return $analysis->swagger;
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function getServiceConfig()
 {
     return array('aliases' => array('service.swagger' => 'Swagger\\Annotations\\Swagger'), 'factories' => array('SwaggerModule\\Options\\ModuleOptions' => function ($serviceManager) {
         $config = $serviceManager->get('Config');
         $config = isset($config['swagger']) ? $config['swagger'] : null;
         if ($config === null) {
             throw new RuntimeException('Configuration for SwaggerModule was not found');
         }
         return new SwaggerModuleOptions($config);
     }, 'Swagger\\Annotations\\Swagger' => function ($serviceManager) {
         /** @var $options \SwaggerModule\Options\ModuleOptions */
         $options = $serviceManager->get('SwaggerModule\\Options\\ModuleOptions');
         $analyser = new SwaggerStaticAnalyser();
         $analysis = new SwaggerAnalysis();
         $processors = SwaggerAnalysis::processors();
         // Crawl directory and parse all files
         $paths = $options->getPaths();
         foreach ($paths as $directory) {
             $finder = SwaggerUtil::finder($directory);
             foreach ($finder as $file) {
                 $analysis->addAnalysis($analyser->fromFile($file->getPathname()));
             }
         }
         // Post processing
         $analysis->process($processors);
         // Validation (Generate notices & warnings)
         $analysis->validate();
         // Pass options to analyzer
         $resourceOptions = $options->getResourceOptions();
         if (!empty($resourceOptions['defaultBasePath'])) {
             $analysis->swagger->basePath = $resourceOptions['defaultBasePath'];
         }
         if (!empty($resourceOptions['defaultHost'])) {
             $analysis->swagger->host = $resourceOptions['defaultHost'];
         }
         if (!empty($resourceOptions['schemes'])) {
             $analysis->swagger->schemes = $resourceOptions['schemes'];
         }
         return $analysis->swagger;
     }));
 }