コード例 #1
0
 /**
  * 'Compiles'
  * @throws cfhCompile_Compiler_Exception
  * @throws cfhCompile_ClassRegistry_Exception
  * @throws cfhCompile_CodeWriter_Exception
  */
 public function compile()
 {
     if (!$this->codeReader instanceof cfhCompile_CodeReader_ReadStrategy_Interface) {
         throw new cfhCompile_Compiler_Exception('Invalid or undefined code reader.');
     }
     if (!$this->codeWriter instanceof cfhCompile_CodeWriter_WriteStrategy_Interface) {
         throw new cfhCompile_Compiler_Exception('Invalid or undefined code writer.');
     }
     try {
         $this->classChildren = array();
         $this->classesWritten = array();
         $this->classRegistry->clear();
         $this->notify(cfhCompile_Compiler_Event::EVENT_BEGIN);
         $this->codeWriter->begin();
         foreach ($this->classIterator as $class) {
             $this->classRegistry->register($class);
             $this->notify(cfhCompile_Compiler_Event::EVENT_CLASS, $class);
             $this->checkDependancysAndWrite($class);
         }
         // remove dependancys for non existant classes...
         foreach ($this->classChildren as $parent => $children) {
             if (!$this->classRegistry->fetch($parent)) {
                 $class = new cfhCompile_Class_Manual($parent);
                 $this->classRegistry->register($class);
                 $this->notify(cfhCompile_Compiler_Event::EVENT_NOTFOUND, $class);
                 $this->classesWritten[$parent] = TRUE;
                 unset($this->classChildren[$parent]);
                 foreach ($children as $child) {
                     $this->checkDependancysAndWrite($this->classRegistry->fetch($child));
                 }
             }
         }
         // loop through dependancys and try to write classes that
         // have all the dependancys written.
         do {
             $total = count($this->classesWritten);
             foreach ($this->classChildren as $parent => $children) {
                 $this->checkDependancysAndWrite($this->classRegistry->fetch($parent));
             }
         } while ($total != count($this->classesWritten));
         // Loop through all classes and make sure they are written.
         foreach ($this->classRegistry as $class) {
             $this->write($class);
         }
         $this->classChildren = array();
         $this->classesWritten = array();
         $this->notify(cfhCompile_Compiler_Event::EVENT_COMMIT);
         $this->codeWriter->commit($this->classRegistry);
         $this->classRegistry->clear();
     } catch (Exception $e) {
         $this->notify(cfhCompile_Compiler_Event::EVENT_ROLLBACK);
         $this->codeWriter->rollback($this->classRegistry);
         $this->classRegistry->clear();
         throw $e;
     }
 }
コード例 #2
0
 public function testClear()
 {
     $r = new cfhCompile_ClassRegistry();
     $this->assertNull($r->fetch('Test'));
     $r->register($this->mockClass);
     $this->assertSame($this->mockClass, $r->fetch('Test'));
     $this->assertEquals(1, $r->count());
     $r->clear();
     $this->assertNull($r->fetch('Test'));
     $this->assertEquals(0, $r->count());
 }