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); }
/** * 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); }
/** * Search the mixin method map and call the method or trigger an error * * This function implements a just in time mixin strategy. Available table behaviors are only mixed when needed. * Lazy mixing is triggered by calling KDatabaseRowsetTable::is[Behaviorable](); * * @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) { if ($this->isConnected()) { $parts = KStringInflector::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)); } else { return false; } } } } return parent::__call($method, $arguments); }