Example #1
0
 /**
  * If the method has a format is[A-Z] then it's a behavior name.
  *
  * @param string $method
  * @param array  $arguments
  *
  * @return mixed
  */
 public function __call($method, $arguments = array())
 {
     $parts = KInflector::explode($method);
     if ($parts[0] == 'is' && isset($parts[1])) {
         $behavior = lcfirst(substr($method, 2));
         return !is_null($this->_repository->getBehavior($behavior));
     }
     return parent::__call($method, $arguments);
 }
Example #2
0
 public function __call($method, $arguments)
 {
     if (substr($method, 0, 3) === 'can') {
         $parts = KInflector::explode($method);
         array_shift($parts);
         array_unshift($parts, 'core');
         $permission = implode('.', $parts);
         return $this[$permission];
     }
     return parent::__call($method, $arguments);
 }
Example #3
0
 /**
  * Search the mixin method map and call the method or forward the call to each row for processing.
  * 
  * Function is also capable of checking is a behavior has been mixed successful using is[Behavior] function. If the
  * behavior exists the function will return TRUE, otherwise FALSE.
  *
  * @param  string   $method    The function name
  * @param  array    $arguments The function arguments
  * @throws BadMethodCallException   If method could not be found
  * @return mixed The result of the function
  */
 public function __call($method, $arguments)
 {
     $parts = KInflector::explode($method);
     //If the method is of the form is[Bahavior] handle it
     if ($parts[0] == 'is' && isset($parts[1])) {
         if (isset($this->_mixed_methods[$method])) {
             return true;
         }
         return false;
     } else {
         //If the mixed method exists call it for all the rows
         if (isset($this->_mixed_methods[$method])) {
             foreach ($this as $i => $row) {
                 $row->__call($method, $arguments);
             }
             return $this;
         }
     }
     throw new BadMethodCallException('Call to undefined method :' . $method);
 }
 /**
  * Search the mixin method map and call the method or trigger an error
  *
  * This functions overloads KDatabaseRowAbstract::__call and implements
  * a just in time mixin strategy. Available table behaviors are only mixed
  * when needed.
  *
  * @param  string 	The function name
  * @param  array  	The function arguments
  * @throws BadMethodCallException 	If method could not be found
  * @return mixed The result of the function
  */
 public function __call($method, array $arguments)
 {
     if ($this->isConnected()) {
         $parts = KInflector::explode($method);
         //Check if a behavior is mixed
         if ($parts[0] == 'is' && isset($parts[1])) {
             if (!isset($this->_mixed_methods[$method])) {
                 //Lazy mix behaviors
                 $behavior = strtolower($parts[1]);
                 if ($this->getTable()->hasBehavior($behavior)) {
                     $this->mixin($this->getTable()->getBehavior($behavior));
                     return true;
                 }
                 return false;
             }
             return true;
         }
     }
     return parent::__call($method, $arguments);
 }
 /**
  * Add a command by it's name
  *
  * @param   string  Method name
  * @param   array   Array containing all the arguments for the original call
  * @see addCommand()
  */
 public function __call($method, $args)
 {
     $parts = KInflector::explode($method);
     if ($parts[0] == 'add' && isset($parts[1])) {
         $config = isset($args[0]) ? $args[0] : array();
         $this->addCommand(strtolower($parts[1]), $config);
         return $this;
     }
     return parent::__call($method, $args);
 }
 /**
  * @dataProvider provideNames
  */
 public function testExplode($classified, $separator, $split, $exploded)
 {
     $this->assertEquals(KInflector::explode($classified), $exploded);
 }
Example #7
0
    /**
     * Execute a controller action by it's name. 
	 *
	 * Function is also capable of checking is a behavior has been mixed succesfully
	 * using is[Behavior] function. If the behavior exists the function will return 
	 * TRUE, otherwise FALSE.
     * 
     * @param   string  Method name
     * @param   array   Array containing all the arguments for the original call
     * @see execute()
     */
    public function __call($method, $args)
    {
        //Handle action alias method
        if(in_array($method, $this->getActions())) 
        {
            //Get the data
            $data = !empty($args) ? $args[0] : array();
            
            //Create a context object
            if(!($data instanceof KCommandContext))
            {
                $context = $this->getCommandContext();
                $context->data   = $data;
                $context->result = false;
            } 
            else $context = $data;
            
            //Execute the action
            return $this->execute($method, $context);
        }
        
        //Check if a behavior is mixed
		$parts = KInflector::explode($method);

		if($parts[0] == 'is' && isset($parts[1]))
		{
		    //Lazy mix behaviors
		    $behavior = strtolower($parts[1]);
		    
            if(!isset($this->_mixed_methods[$method]))
            { 
                if($this->hasBehavior($behavior)) 
                {
                    $this->mixin($this->getBehavior($behavior));
                    return true;
		        }
		  
			    return false;
            }
            
            return true;
		}
     
        return parent::__call($method, $args);
    }
Example #8
0
 /**
  * The captured method is used as the attribute of this
  * tag
  *
  * @param $method
  * @param $args
  * @return object LibBaseTemplateHelperHtmlTag class instance
  */
 public function __call($method, $args)
 {
     $parts = KInflector::explode($method);
     $name = implode('-', $parts);
     return $this->set($name, $args[0]);
 }
 /**
  * Search the behaviors to see if this table behaves as.
  *
  * Function is also capable of checking is a behavior has been mixed succesfully
  * using is[Behavior] function. If the behavior exists the function will return
  * TRUE, otherwise FALSE.
  *
  * @param  string 	The function name
  * @param  array  	The function arguments
  * @throws BadMethodCallException 	If method could not be found
  * @return mixed The result of the function
  */
 public function __call($method, $arguments)
 {
     // If the method is of the form is[Bahavior] handle it.
     $parts = KInflector::explode($method);
     if ($parts[0] == 'is' && isset($parts[1])) {
         if ($this->hasBehavior(strtolower($parts[1]))) {
             return true;
         }
         return false;
     }
     return parent::__call($method, $arguments);
 }
Example #10
0
 /**
  * Adds a missed method as $key/$value.
  *
  * @param string $method
  * @param array  $arguments
  * 
  * @return LibBaseTemplateObject
  */
 public function __call($method, $arguments)
 {
     $attribute = implode('-', KInflector::explode($method));
     $this->setAttribute($attribute, $arguments[0], isset($arguments[1]) ? $arguments[1] : null);
     return $this;
 }
 /**
  * Search the mixin method map and call the method or trigger an error
  *
  * Function is also capable of checking is a behavior has been mixed succesfully
  * using is[Behavior] function. If the behavior exists the function will return 
  * TRUE, otherwise FALSE.
  *
  * @param  string 	The function name
  * @param  array  	The function arguments
  * @throws BadMethodCallException 	If method could not be found
  * @return mixed The result of the function
  */
 public function __call($method, array $arguments)
 {
     // If the method is of the form is[Bahavior] handle it.
     $parts = KInflector::explode($method);
     if ($parts[0] == 'is' && isset($parts[1])) {
         if (isset($this->_mixed_methods[$method])) {
             return true;
         }
         return false;
     }
     return parent::__call($method, $arguments);
 }
Example #12
0
 /**
  * If the missed method is implemented by the query object then delegate the call to the query object
  * 
  * @see KObject::__call()
  */
 public function __call($method, $arguments = array())
 {
     $parts = KInflector::explode($method);
     if ($parts[0] == 'is' && isset($parts[1])) {
         $behavior = lcfirst(substr($method, 2));
         return $this->_repository->hasBehavior($behavior);
     }
     //forward a call to the query
     if (method_exists($this->getQuery(), $method) || !$this->_repository->entityMethodExists($method)) {
         $result = call_object_method($this->getQuery(), $method, $arguments);
         if ($result instanceof AnDomainQuery) {
             $result = $this;
         }
     } else {
         $result = parent::__call($method, $arguments);
     }
     return $result;
 }
Example #13
0
 /**
  * Implements magic method. Dynamically mixes a mixin
  * 
  * @param string $method Method name
  * @param array  $args   Array of arugments
  * 
  * @return mixed
  */
 public function __call($method, $args)
 {
     //If the method hasn't been mixed yet, load all the behaviors
     if (!isset($this->_mixed_methods[$method])) {
         $key = 'behavior.' . $method;
         if (!self::_cache($this)->offsetExists($key)) {
             self::_cache($this)->offsetSet($key, false);
             $behaviors = $this->getRepository()->getBehaviors();
             foreach ($behaviors as $behavior) {
                 if (in_array($method, $behavior->getMixableMethods())) {
                     //only mix the mixin that has $method
                     self::_cache($this)->offsetSet($key, $behavior);
                     break;
                 }
             }
         }
         if ($behavior = self::_cache($this)->offsetGet($key)) {
             $this->mixin($behavior);
         }
     }
     $parts = KInflector::explode($method);
     if ($parts[0] == 'is') {
         if (isset($this->_mixed_methods[$method])) {
             return true;
         } else {
             return false;
         }
     }
     if (!isset($this->_mixed_methods[$method])) {
         if ($parts[0] == 'get' || $parts[0] == 'set') {
             $property = lcfirst(KInflector::implode(array_slice($parts, 1)));
             $property = $this->getEntityDescription()->getProperty($property);
             if ($property) {
                 if ($parts[0] == 'get') {
                     return $this->getData($property->getName());
                 } else {
                     return $this->setData($property->getName(), array_shift($args));
                 }
             }
         }
     }
     return parent::__call($method, $args);
 }
Example #14
0
/**
 * Return an array of class prefix.
 *
 * @param object $object An object
 * @param array  $config An array of configuration
 *
 * @return array
 */
function get_prefix($object, $config = array())
{
    if (!is_array($config) || is_numeric(key($config))) {
        $config = array('append' => (array) $config);
    }
    $config = array_merge(array('break' => 'K', 'append' => null), $config);
    $classes = array();
    $class = is_string($object) ? $object : get_class($object);
    $break = $config['break'];
    $append = $config['append'];
    while ($class) {
        if (strpos($class, $break) === 0) {
            break;
        }
        $parts = KInflector::explode($class);
        if ($parts[0] == 'lib') {
            $classes[] = 'Com' . ucfirst($parts[1]);
            $classes[] = ucfirst($parts[0]) . ucfirst($parts[1]);
        } elseif ($parts[0] == 'com') {
            $classes[] = ucfirst($parts[0]) . ucfirst($parts[1]);
            $classes[] = 'Lib' . ucfirst($parts[1]);
        } else {
            $classes[] = ucfirst($parts[0]);
        }
        $class = get_parent_class($class);
    }
    $classes = array_unique($classes);
    if ($append) {
        $array = array();
        settype($append, 'array');
        foreach ($classes as $key => $class) {
            foreach ($append as $word) {
                $array[] = $class . $word;
            }
        }
        $classes = $array;
    }
    return $classes;
}
Example #15
0
 /**
  * Overloaded call function to handle behaviors and forward all 
  * calls to to the object regardless
  *
  * @param  string   The function name
  * @param  array    The function arguments
  * @return mixed The result of the function
  */
 public function __call($method, $arguments)
 {
     $object = $this->getObject();
     $parts = KInflector::explode($method);
     if ($parts[0] == 'is' && isset($parts[1])) {
         $behavior = lcfirst(substr($method, 2));
         return !is_null($this->getRepository()->getBehavior($behavior));
     } else {
         return call_object_method($object, $method, $arguments);
     }
 }
Example #16
0
 /**
  * Sets status or a header
  * 
  * @param string $key     A string key
  * @param string $value   A string value
  * 
  * @return void
  */
 public function __set($key, $value)
 {
     if ($key == 'status') {
         $this->setStatus($value);
     } elseif ($key == 'redirect') {
         $this->setRedirect($value);
     } elseif ($key == 'content') {
         $this->setContent($value);
     } else {
         $key = implode('-', array_map('ucfirst', KInflector::explode($key)));
         $this->setHeader($key, $value);
     }
 }