示例#1
0
 /**
  * @dataProvider loadProvider
  */
 public function testLoad($samplePath, $expectedClass)
 {
     $that = $this;
     $completed = false;
     $callback = function ($class, $path) use($that, $expectedClass, $samplePath, &$completed) {
         if (!$expectedClass) {
             $this->fail("Expected not to cross {$path} as it should not contain a PHP class");
         }
         $that->assertEquals($expectedClass, $class, 'Loader determines the correct class with full namesapce');
         $this->assertEquals($samplePath, $path, 'Loader returns fully qualified path');
         $completed = true;
     };
     $this->instance->setCallback($callback);
     $this->instance->load($samplePath);
     if (!$completed && $expectedClass) {
         $this->fail("Did not reach callback, meaning file or class was not found");
     }
 }
示例#2
0
 /**
  * @param string $path Directory path to compile
  */
 public function compile($path)
 {
     $this->loader->setCallback(function ($class, $file) {
         $reflClass = new \ReflectionClass($class);
         //Ignore abstract classes
         if ($reflClass->isAbstract()) {
             return;
         }
         $classAnnotations = $this->reader->getClassAnnotations($reflClass);
         $this->compileClass($reflClass, $classAnnotations);
         foreach ($reflClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflMethod) {
             /** @var $reflMethod \ReflectionMethod */
             $methodAnnotations = $this->reader->getMethodAnnotations($reflMethod);
             $this->compileMethod($reflClass, $reflMethod, $methodAnnotations);
         }
     });
     $this->loader->load($path);
 }