Beispiel #1
0
 public function getInstanceDef($className)
 {
     list($className, $instanceName) = $this->extractClassAndInstanceName($className);
     if (isset($this->classDefs[$className])) {
         $classDef = $this->classDefs[$className];
     } else {
         $classDef = new ClassDefinition($className);
         $this->classDefs[$className] = $classDef;
     }
     return $classDef->getInstance($instanceName);
 }
Beispiel #2
0
 /**
  * Creates a definition for a class
  *
  * @param CompilationContext $compilationContext
  * @param string $namespace
  * @param array $topStatement
  * @param array $docblock
  */
 public function preCompileClass(CompilationContext $compilationContext, $namespace, $topStatement, $docblock)
 {
     $classDefinition = new ClassDefinition($namespace, $topStatement['name']);
     $classDefinition->setIsExternal($this->_external);
     if (isset($topStatement['extends'])) {
         $classDefinition->setExtendsClass($this->getFullName($topStatement['extends']));
     }
     if (isset($topStatement['implements'])) {
         foreach ($topStatement['implements'] as &$implement) {
             $implement['value'] = $this->getFullName($implement['value']);
         }
         $classDefinition->setImplementsInterfaces($topStatement['implements']);
     }
     if (isset($topStatement['abstract'])) {
         $classDefinition->setIsAbstract($topStatement['abstract']);
     }
     if (isset($topStatement['final'])) {
         $classDefinition->setIsFinal($topStatement['final']);
     }
     if (is_array($docblock)) {
         $classDefinition->setDocBlock($docblock["value"]);
     }
     if (isset($topStatement['definition'])) {
         $definition = $topStatement['definition'];
         if (isset($definition['properties'])) {
             foreach ($definition['properties'] as $property) {
                 /**
                  * Add property to the definition
                  */
                 $classDefinition->addProperty(new ClassProperty($classDefinition, $property['visibility'], $property['name'], isset($property['default']) ? $property['default'] : null, isset($property['docblock']) ? $property['docblock'] : null, $property));
                 /**
                  * Check and process shortcuts
                  */
                 if (isset($property['shortcuts'])) {
                     $this->_processShorcuts($property, $classDefinition);
                 }
             }
         }
         /**
          * Register constants
          */
         if (isset($definition['constants'])) {
             foreach ($definition['constants'] as $constant) {
                 $classDefinition->addConstant(new ClassConstant($constant['name'], isset($constant['default']) ? $constant['default'] : null, isset($constant['docblock']) ? $constant['docblock'] : null));
             }
         }
         /**
          * Register methods
          */
         if (isset($definition['methods'])) {
             foreach ($definition['methods'] as $method) {
                 $classDefinition->addMethod(new ClassMethod($classDefinition, $method['visibility'], $method['name'], isset($method['parameters']) ? new ClassMethodParameters($method['parameters']) : null, isset($method['statements']) ? new StatementsBlock($method['statements']) : null, isset($method['docblock']) ? $method['docblock'] : null, isset($method['return-type']) ? $method['return-type'] : null, $method), $method);
             }
         }
     }
     $this->_classDefinition = $classDefinition;
     /**
      * Assign current class definition to the compilation context
      */
     $compilationContext->classDefinition = $classDefinition;
     /**
      * Run pre-compilation passes
      */
     $classDefinition->preCompile($compilationContext);
 }
 /**
  * Transform class/interface name to FQN format
  * @todo WHY WHY :'(
  *
  * @param string $className
  * @return string
  */
 public function getFullName($className)
 {
     $namespace = isset($this->currentMethod) && $this->currentMethod instanceof FunctionDefinition ? $this->currentMethod->getNamespace() : $this->classDefinition->getNamespace();
     return Utils::getFullName($className, $namespace, $this->aliasManager);
 }
Beispiel #4
0
 /**
  * Transform class/interface name to FQN format
  * @todo WHY WHY :'(
  *
  * @param string $className
  * @return string
  */
 public function getFullName($className)
 {
     return Utils::getFullName($className, $this->classDefinition->getNamespace(), $this->aliasManager);
 }
Beispiel #5
0
 /**
  * Builds a class definition from reflection
  *
  * @param \ReflectionClass $class
  */
 public static function buildFromReflection(\ReflectionClass $class)
 {
     $classDefinition = new ClassDefinition($class->getNamespaceName(), $class->getName());
     $methods = $class->getMethods();
     if (count($methods) > 0) {
         foreach ($methods as $method) {
             $parameters = array();
             foreach ($method->getParameters() as $row) {
                 $parameters[] = array('type' => 'parameter', 'name' => $row->getName(), 'const' => 0, 'data-type' => 'variable', 'mandatory' => !$row->isOptional());
             }
             $classMethod = new ClassMethod($classDefinition, array(), $method->getName(), new ClassMethodParameters($parameters));
             $classMethod->setIsStatic($method->isStatic());
             $classMethod->setIsInternal(true);
             $classDefinition->addMethod($classMethod);
         }
     }
     $constants = $class->getConstants();
     if (count($constants) > 0) {
         foreach ($constants as $constantName => $constantValue) {
             $type = self::_convertPhpConstantType(gettype($constantValue));
             $classConstant = new ClassConstant($constantName, array('value' => $constantValue, 'type' => $type), null);
             $classDefinition->addConstant($classConstant);
         }
     }
     $classDefinition->setIsInternal(true);
     return $classDefinition;
 }