Example #1
0
 /**
  * @param string|null $class
  */
 public function __construct($class = null)
 {
     if ($class) {
         $this->class = $class;
         $propertyClass = Factory::$propertyClass;
         foreach (Reflection::getClass($class)->getProperties() as $property) {
             $this->add(new $propertyClass($class, $property->getName(), $property));
         }
     }
 }
Example #2
0
 /**
  * @param string|null $class
  */
 public function __construct($class = null)
 {
     if ($class) {
         $this->class = $class;
         $methodClass = Factory::$methodClass;
         foreach (Reflection::getClassMethods($class) as $method) {
             $this->add(new $methodClass($class, $method->getName(), array(), $method));
         }
     }
 }
Example #3
0
 /**
  * @param string              $class
  * @param string              $property
  * @param \ReflectionProperty $reflection
  *
  * @throws \RuntimeException
  */
 public function __construct($class, $property, \ReflectionProperty $reflection = null)
 {
     if (is_string($class)) {
         if (empty($class)) {
             throw new \RuntimeException('Class name can not be empty');
         }
         if (!class_exists($class)) {
             throw new \RuntimeException('Class is not defined');
         }
     } else {
         if (!is_object($class)) {
             throw new \RuntimeException('Invalid class type, type - ' . gettype($class));
         }
     }
     $this->class = $class;
     if (!is_string($property) || empty($property)) {
         throw new \RuntimeException('Property can not be null and should be string');
     }
     $this->name = $property;
     $this->setReflection($reflection);
     if (property_exists($class, $property)) {
         $reflection = $this->getReflection();
         /** @var \ReflectionProperty $reflection */
         if ($reflection->isPublic()) {
             $this->setAccess(Access::ACCESS_PUBLIC);
         } else {
             if ($reflection->isPrivate()) {
                 $this->setAccess(Access::ACCESS_PRIVATE);
             } else {
                 if ($reflection->isProtected()) {
                     $this->setAccess(Access::ACCESS_PROTECTED);
                 }
             }
         }
         $reflection->setAccessible(true);
         if (is_object($class)) {
             $this->setValue($reflection->getValue($class));
         } else {
             $properties = Reflection::getClass($class)->getDefaultProperties();
             if (array_key_exists($property, $properties)) {
                 $this->setValue($properties[$property]);
             }
         }
     }
 }
Example #4
0
 /**
  * @return \ReflectionFunctionAbstract|null
  */
 protected function createReflection()
 {
     if (function_exists($this->getName())) {
         return Reflection::getFunction($this->getName());
     }
     return null;
 }
Example #5
0
 /**
  * @return \ReflectionFunctionAbstract|null
  */
 protected function createReflection()
 {
     if (method_exists($this->getClass(), $this->getName())) {
         return Reflection::getClassMethod($this->getClass(), $this->getName());
     }
     return null;
 }