Esempio n. 1
0
 /**
  * Build a new Structure (Object) from the given data.
  *
  * @param $object
  *
  * @return Structure
  */
 private function buildStructure($object)
 {
     $classReflection = new ReflectionObject($object);
     $structure = new Structure();
     $structure->setId(spl_object_hash($object));
     $structure->setNamespace($classReflection->getNamespaceName());
     $structure->setName($classReflection->getName());
     $structure->setFinal($classReflection->isFinal());
     if ($parent = $classReflection->getParentClass()) {
         $structure->setParent($parent->getName());
     }
     $structure->setInterfaces($classReflection->getInterfaceNames());
     $structure->setTraits($classReflection->getTraitNames());
     foreach ($classReflection->getProperties() as $propertyReflection) {
         $property = new Property();
         $visibility = $this->visiblity($propertyReflection);
         $propertyReflection->setAccessible(true);
         $property->setName($propertyReflection->getName());
         $value = $propertyReflection->getValue($object);
         if (is_object($value) || is_array($value)) {
             $property->setValue($this->cloneData($value));
         } else {
             $property->setValue($value);
         }
         $property->setType(gettype($value));
         if (is_string($value)) {
             $property->setLength(strlen($value));
         }
         $property->setVisibility($visibility);
         $property->setStatic($propertyReflection->isStatic());
         $structure->addProperty($property);
         $propertyReflection->setAccessible(false);
     }
     foreach ($classReflection->getConstants() as $constantName => $constantValue) {
         $property = new Property();
         $property->setType('constant');
         $property->setName($constantName);
         $property->setValue($constantValue);
         $property->setConstant(true);
         $structure->addProperty($property);
     }
     //docket method work
     foreach ($classReflection->getMethods() as $methodReflection) {
         $method = new Method();
         $method->setName($methodReflection->getName());
         $method->setFinal($methodReflection->isFinal());
         $method->setAbstract($methodReflection->isAbstract());
         $method->setStatic($methodReflection->isStatic());
         $method->setVisibility($this->visiblity($methodReflection));
         foreach ($methodReflection->getParameters() as $methodParameterReflection) {
             $methodParameter = new MethodParameter();
             $methodParameter->setName($methodParameterReflection->getName());
             if ($methodParameterReflection->isDefaultValueAvailable()) {
                 $methodParameter->setDefaultValue($methodParameterReflection->getDefaultValue());
             }
             $methodParameter->setTypeHintedClass($methodParameterReflection->getClass());
             $methodParameter->setPosition($methodParameterReflection->getPosition());
             $methodParameter->setDeclaringClass($methodParameterReflection->getDeclaringClass());
             $methodParameter->setDeclaringFunction($methodParameterReflection->getDeclaringFunction());
             $methodParameter->setExpectingArray($methodParameterReflection->isArray());
             $methodParameter->setExpectingCallable($methodParameterReflection->isCallable());
             $methodParameter->setOptional($methodParameterReflection->isOptional());
             $methodParameter->setExpectingReference($methodParameterReflection->isPassedByReference());
             $method->addParameter($methodParameter);
         }
         $structure->addMethod($method);
     }
     return $structure;
 }
Esempio n. 2
0
 /**
  * Dump a Structure (Object) to the screen.
  *
  * @param Structure $structure
  */
 private function buildStructure(Structure $structure)
 {
     $abstractOrFinal = $structure->isAbstract() ? 'abstract ' : $structure->isFinal() ? 'final ' : '';
     $this->dump .= sprintf('<samp class="parent">%sclass %s %s %s<span class="arrow"></span> {', $abstractOrFinal, $structure->getNamespace() ?: $structure->getName(), $structure->getParent(), $structure->getInterfaces());
     $this->dump .= sprintf('<samp class="child">id : %s</samp>', $structure->getId());
     $this->dump .= sprintf('<samp class="child">traits : %s </samp>', $structure->getTraits());
     if ($structure->hasProperties()) {
         $this->dump .= '<samp class="parent child"> properties : <span class="arrow"></span> {';
         foreach ($structure->getProperties() as $property) {
             $this->buildType($property);
         }
         $this->dump .= '}</samp>';
     }
     if ($structure->hasMethods()) {
         $this->dump .= '<samp class="parent child"> methods : <span class="arrow"></span> {';
         foreach ($structure->getMethods() as $method) {
             $this->buildType($method);
         }
         $this->dump .= '}</samp>';
     }
     $this->dump .= '}</samp>';
 }