Beispiel #1
0
 /**
  * @return Code
  */
 public function getCode()
 {
     if ($this->code === null) {
         $this->code = Factory::createCode($this->getReflection());
     }
     return $this->code;
 }
Beispiel #2
0
 /**
  * @param string|object    $class
  * @param \ReflectionClass $reflection
  *
  * @throws \RuntimeException
  */
 public function __construct($class, \ReflectionClass $reflection = null)
 {
     if (is_string($class)) {
         if (!class_exists($class)) {
             throw new \RuntimeException('Class ' . $class . ' is not defined');
         }
     }
     $this->class = $class;
     $this->constants = Factory::createConstantCollection();
     $this->properties = Factory::createPropertyCollection($class);
     $this->methods = Factory::createMethodCollection($class);
 }
Beispiel #3
0
 /**
  * @param string $name
  *
  * @throws \RuntimeException
  *
  * @return boolean
  */
 public function rename($name)
 {
     if ($this->getName() == $name) {
         return true;
     }
     if (property_exists($this->getClass(), $name)) {
         throw new \RuntimeException('Property ' . $name . ' already defined in ' . $this->getClass());
     }
     if (Factory::getExecutor()->renameProperty($this, $name)) {
         $this->name = $name;
         return true;
     }
     return false;
 }
Beispiel #4
0
 /**
  * @param RunkitFunction $item
  *
  * @return bool
  */
 protected function addInternal($item)
 {
     return Factory::getExecutor()->addFunction($item->getName(), $item->getArguments(), $item->getCode());
 }
Beispiel #5
0
 /**
  * @param string $name
  *
  * @throws \RuntimeException
  *
  * @return boolean
  */
 public function rename($name)
 {
     if (defined($name)) {
         throw new \RuntimeException('Constant with name ' . $name . ' already defined');
     }
     if ($this->getName() == $name) {
         return true;
     }
     if (Factory::getExecutor()->renameConstant($this, $name)) {
         $this->name = $name;
         return true;
     }
     return false;
 }
Beispiel #6
0
 public function testGetExecutor()
 {
     $executor = Factory::getExecutor();
     $this->assertInstanceOf('Runkit\\Executor', $executor);
 }
Beispiel #7
0
 /**
  * @param Runkit $item
  *
  * @return boolean
  */
 protected function removeInternal($item)
 {
     return Factory::getExecutor()->removeConstant($item->getName());
 }
Beispiel #8
0
 /**
  * Remove function from scope
  *
  * @return boolean
  */
 public function remove()
 {
     $name = $this->getName();
     return function_exists($name) ? Factory::getExecutor()->removeFunction($name) : true;
 }
Beispiel #9
0
 /**
  * @param RunkitMethod $item
  *
  * @return mixed
  */
 protected function addInternal($item)
 {
     return Factory::getExecutor()->addMethod($item);
 }
Beispiel #10
0
 /**
  * @param RunkitProperty $item
  *
  * @return mixed
  */
 protected function addInternal($item)
 {
     return Factory::getExecutor()->addProperty($item);
 }
Beispiel #11
0
 /**
  * @param string $name
  *
  * @throws \RuntimeException
  *
  * @return boolean
  */
 public function rename($name)
 {
     if (method_exists($this->getClass(), $this->getName())) {
         if (method_exists($this->getClass(), $name)) {
             throw new \RuntimeException('Method with name ' . $name . ' already exists in class ' . $this->getClass());
         }
         if (Factory::getExecutor()->renameMethod($this->getClass(), $this->getName(), $name)) {
             $this->name = $name;
             return true;
         }
     }
     return false;
 }