Пример #1
0
 /**
  * Compile built classes
  *
  * @param $source   Reflection_Source
  * @param $compiler PHP\Compiler
  * @return boolean
  */
 public function compile(Reflection_Source $source, PHP\Compiler $compiler = null)
 {
     $builder = Builder::current();
     $builder->build = false;
     $compiled = false;
     foreach ($source->getClasses() as $class) {
         $replacement = $builder->getComposition($class->name);
         if (is_array($replacement)) {
             foreach (Class_Builder::build($class->name, $replacement, true) as $built_source) {
                 $compiler->addSource((new Reflection_Source())->setSource('<?php' . LF . $built_source));
                 $compiled = true;
             }
         }
     }
     $builder->build = true;
     return $compiled;
 }
Пример #2
0
 /**
  * Gets replacement class name for a parent class name or a list of traits to implement
  *
  * @param $class_name string can be short or full class name
  * @return string
  */
 private function replacementClassName($class_name)
 {
     if ($this->enabled) {
         $result = isset($this->replacements[$class_name]) ? $this->replacements[$class_name] : $class_name;
         if (is_array($result)) {
             if ($this->build) {
                 $this->compositions[$class_name] = $result;
                 $built_class_name = Class_Builder::builtClassName($class_name);
                 if (file_exists(Application::current()->getCacheDir() . '/compiled/' . str_replace('/', '-', Names::classToPath($built_class_name)))) {
                     $result = $built_class_name;
                 } else {
                     $result = Class_Builder::build($class_name, $result);
                 }
                 $this->replacements[$class_name] = $result;
             } else {
                 $result = $class_name;
             }
         } elseif (!$this->build && self::isBuilt($result)) {
             $result = $class_name;
         }
     } else {
         $result = $class_name;
     }
     return $class_name != $result && !self::isBuilt($result) ? $this->replacementClassName($result) : $result;
 }