Ejemplo n.º 1
0
 /**
  * Allows to call setIf, getIf, setThen, getThen, setElse and getElse
  * functions
  * 
  * @param string $name      Method name
  * @param array  $arguments Method arguments
  * 
  * @return mixed
  * 
  * @throws \REBuilder\Exception\Generic
  */
 function __call($name, $arguments)
 {
     if (preg_match("/^(get|set)(If|Then|Else)\$/", $name, $match)) {
         $type = strtolower($match[2]);
         $currentChild = $this->_getConditionalChild($type);
         if ($match[1] === "get") {
             return $currentChild;
         } else {
             $testClass = $this->_childrenOrder[$type];
             if (!count($arguments) || !$arguments[0] instanceof $testClass) {
                 throw new \REBuilder\Exception\Generic("{$name} requires a " . $this->_getClassName($testClass));
             }
             if ($currentChild) {
                 $this->_safeAdd = true;
                 $this->removeChild($currentChild);
             }
             return $this->addChildAt($arguments[0]);
         }
     }
     return parent::__call($name, $arguments);
 }
Ejemplo n.º 2
0
 /**
  * Allows to call setStart, getStart, setEnd and getEnd functions
  * 
  * @param string $name      Method name
  * @param array  $arguments Method arguments
  * 
  * @return mixed
  * 
  * @throws \REBuilder\Exception\Generic
  */
 function __call($name, $arguments)
 {
     if (preg_match("/^(get|set)(Start|End)\$/", $name, $match)) {
         $index = $match[2] === "Start" ? 0 : 1;
         if ($match[1] === "get") {
             return isset($this->_children[$index]) ? $this->_children[$index] : null;
         } else {
             if (!count($arguments) || !$arguments[0] instanceof AbstractPattern) {
                 throw new \REBuilder\Exception\Generic("{$name} requires a pattern");
             } elseif (!$arguments[0]->canBeAddedToCharClassRange()) {
                 throw new \REBuilder\Exception\Generic($this->_getClassName($arguments[0]) . " cannot be added to character class ranges");
             }
             return $this->removeChildAt($index)->addChildAt($arguments[0], $index);
         }
     }
     return parent::__call($name, $arguments);
 }