コード例 #1
0
ファイル: Parser.php プロジェクト: nunodotferreira/ApiGen
 /**
  * {@inheritdoc}
  */
 public function parse(array $files)
 {
     foreach ($files as $file) {
         try {
             $this->broker->processFile($file->getPathname());
         } catch (FileProcessingException $exception) {
             $this->errors[] = $exception;
         }
     }
     $this->extractBrokerDataForParserResult($this->broker);
     return $this->parserStorage;
 }
コード例 #2
0
 protected function setUp()
 {
     $container = $this->getMock('Go\\Core\\AspectContainer');
     $reader = $this->getMock('Doctrine\\Common\\Annotations\\Reader');
     $loader = $this->getMock('Go\\Core\\AspectLoader', array(), array($container, $reader));
     $this->adviceMatcher = new AdviceMatcher($loader, $container);
     $brokerInstance = new Broker(new Broker\Backend\Memory());
     $brokerInstance->processFile(__FILE__);
     $this->reflectionClass = $brokerInstance->getClass(__CLASS__);
 }
コード例 #3
0
ファイル: Generator.php プロジェクト: sirone/apigen
 /**
  * Loads template-specific macro and helper libraries.
  *
  * @param \ApiGen\Template $template Template instance
  */
 private function registerCustomTemplateMacros(Template $template)
 {
     $latte = new Nette\Latte\Engine();
     if (!empty($this->config->template['options']['extensions'])) {
         $this->output("Loading custom template macro and helper libraries\n");
         $broker = new Broker(new Broker\Backend\Memory(), 0);
         $baseDir = dirname($this->config->template['config']);
         foreach ((array) $this->config->template['options']['extensions'] as $fileName) {
             $pathName = $baseDir . DIRECTORY_SEPARATOR . $fileName;
             if (is_file($pathName)) {
                 try {
                     $reflectionFile = $broker->processFile($pathName, true);
                     foreach ($reflectionFile->getNamespaces() as $namespace) {
                         foreach ($namespace->getClasses() as $class) {
                             if ($class->isSubclassOf('ApiGen\\MacroSet')) {
                                 // Macro set
                                 include $pathName;
                                 call_user_func(array($class->getName(), 'install'), $latte->compiler);
                                 $this->output(sprintf("  %s (macro set)\n", $class->getName()));
                             } elseif ($class->implementsInterface('ApiGen\\IHelperSet')) {
                                 // Helpers set
                                 include $pathName;
                                 $className = $class->getName();
                                 $template->registerHelperLoader(callback(new $className($template), 'loader'));
                                 $this->output(sprintf("  %s (helper set)\n", $class->getName()));
                             }
                         }
                     }
                 } catch (\Exception $e) {
                     throw new \Exception(sprintf('Could not load macros and helpers from file "%s"', $pathName), 0, $e);
                 }
             } else {
                 throw new \Exception(sprintf('Helper file "%s" does not exist.', $pathName));
             }
         }
     }
     $template->registerFilter($latte);
 }
コード例 #4
0
 /**
  * Tests getting of static variables.
  */
 public function testStaticVariables()
 {
     static $testName = 'staticVariables';
     $rfl = $this->getMethodReflection($testName);
     $this->assertSame($rfl->internal->getStaticVariables(), $rfl->token->getStaticVariables());
     $this->assertSame(array('string' => 'string', 'integer' => 1, 'float' => 1.1, 'boolean' => true, 'null' => null, 'array' => array(1 => 1), 'array2' => array(1 => 1, 2 => 2), 'constants' => array('self constant', 'parent constant')), $rfl->token->getStaticVariables());
     // The same test with parsing method bodies turned off
     $broker = new Broker(new Broker\Backend\Memory(), Broker::OPTION_DEFAULT & ~Broker::OPTION_PARSE_FUNCTION_BODY);
     $broker->processFile($this->getFilePath($testName));
     $reflection = $broker->getClass($this->getClassName($testName))->getMethod($this->getMethodName($testName));
     $this->assertSame(array(), $reflection->getStaticVariables());
 }
コード例 #5
0
ファイル: Core.php プロジェクト: wick-ed/semcrement
 /**
  * Will run an inspection for a certain file/directory and will return a version instance
  * resulting from the changes compared to former inspections
  *
  * @param string $srcPath Path to the file/directory to inspect
  *
  * @return \Herrera\Version\Builder
  *
  * @throws \Exception
  */
 public function runInspection($srcPath)
 {
     // check if we got something we can work with
     if (!is_readable($srcPath)) {
         throw new \Exception(sprintf('Cannot read from source path %s', $srcPath));
     }
     $broker = new Broker(new Memory());
     if (is_dir($srcPath)) {
         $broker->processDirectory($srcPath);
     } else {
         $broker->processFile($srcPath);
     }
     // iterate all php files and check for an API annotation
     $inspector = $this->getInspector();
     foreach ($broker->getClasses() as $classReflection) {
         // we can continue iteration if we did not get any valuable information from this file
         if (!$classReflection instanceof \TokenReflection\ReflectionClass) {
             continue;
         }
         // if we got the API annotation we have to work with it
         if ($classReflection->hasAnnotation(ApiAnnotation::ANNOTATION)) {
             $formerReflection = $this->cache->load($classReflection->getName());
             // check for possible changes
             $inspector->inspect($classReflection, $formerReflection);
             // save the current reflection object as a base for later comparison
             $this->cache->store($classReflection);
         }
     }
     // get the result and increment the version accordingly
     $result = $inspector->getResult();
     $incrementationMethod = 'increment' . ucfirst(strtolower($result->getIncrementVersion()));
     $version = $this->getBaseVersion();
     if (method_exists($version, $incrementationMethod)) {
         $version->{$incrementationMethod}();
     }
     return $version;
 }
コード例 #6
0
 private function getTokenizedReflectionClass(\ReflectionClass $class)
 {
     $this->broker->processFile($class->getFileName());
     return $this->broker->getClass($class->name);
 }