public function create($isAjax = false) { parent::create(); if (!$this->callback) { throw new Mesour\InvalidStateException('Callback is required for string content.'); } if (!$isAjax && $this->getParent()->hasAjaxLoading()) { return ''; } $this->onRender($this); return Mesour\Components\Utils\Helpers::invokeArgs($this->callback, [$this]); }
public function create($isAjax = false) { parent::create(); if (!$isAjax && $this->getParent()->hasAjaxLoading()) { return ''; } $template = $this->getTemplateFile(); if ($this->callback) { Mesour\Components\Utils\Helpers::invokeArgs($this->callback, [$this, $template]); } $this->onRender($this, $template); return $template->render(true); }
public function setAttributes(array $attributes) { $this->attributes = []; foreach ($attributes as $key => $attribute) { $arguments = [$key]; if (is_array($attribute)) { $arguments = array_merge($arguments, array_values($attribute)); } else { $arguments[] = $attribute; } Mesour\Components\Utils\Helpers::invokeArgs([$this, 'setAttribute'], $arguments); } return $this; }
public function __call($name, $args) { try { if (substr($name, 0, 2) === 'on') { if (!$this->getReflection()->hasProperty($name)) { throw new Mesour\Components\MethodCallException(); } elseif ($this->getReflection()->getProperty($name)->isPrivate()) { throw new Mesour\InvalidStateException('Property ' . $name . ' must be public or protected.'); } elseif (!is_array($this->{$name})) { throw new Mesour\UnexpectedValueException('Property ' . $name . ' must be array.'); } else { foreach ($this->{$name} as $callback) { Mesour\Components\Utils\Helpers::invokeArgs($callback, $args); } } } else { throw new Mesour\Components\MethodCallException(); } } catch (Mesour\Components\MethodCallException $e) { throw new Mesour\MethodCallException(sprintf('Cannot call undefined method %s::$%s.', $name, static::class)); } }
/** * @param array|null $permission * @param mixed $role * @param Mesour\Components\Security\IAuthorizator $authorizator * @return bool */ protected function checkIsAllowed($permission, $role, Mesour\Components\Security\IAuthorizator $authorizator) { return !$permission || Mesour\Components\Utils\Helpers::invokeArgs([$authorizator, 'isAllowed'], array_merge([$role], $permission)); }
/** * Returns the rule type associated with the specified Resource, Role, and privilege. * @param string|Permission::ALL * @param string|Permission::ALL * @param string|Permission::ALL * @return mixed NULL if a rule does not exist or assertion fails, otherwise returns ALLOW or DENY */ private function getRuleType($resource, $role, $privilege) { if (!($rules = $this->getRules($resource, $role))) { return null; } if ($privilege === self::ALL) { if (isset($rules['allPrivileges'])) { $rule = $rules['allPrivileges']; } else { return null; } } elseif (!isset($rules['byPrivilege'][$privilege])) { return null; } else { $rule = $rules['byPrivilege'][$privilege]; } if ($rule['assert'] === null || Mesour\Components\Utils\Helpers::invokeArgs($rule['assert'], [$this, $role, $resource, $privilege])) { return $rule['type']; } elseif ($resource !== self::ALL || $role !== self::ALL || $privilege !== self::ALL) { return null; } elseif (self::ALLOW === $rule['type']) { return self::DENY; } else { return self::ALLOW; } }
public function render() { $wrapper = $this->getWrapperPrototype(); $this->onRender($this, $wrapper); foreach ($this->items as $item) { $li = $this->createLiPrototype(); if ($this->callback) { Mesour\Components\Utils\Helpers::invokeArgs($this->callback, [$li, $item[0], $item[1]]); } else { $li->add($item[1]); } $this->onRenderRow($li, $item[0], $item[1]); $wrapper->add($li); } return $wrapper; }
public function isMatch(Mesour\Components\ComponentModel\IComponent $component, $value, array $parameters = []) { return Mesour\Components\Utils\Helpers::invokeArgs([$component, $this->getMethodName()], $parameters) === $value; }
/** * Called only if called component === $this and handler exists * @param string $methodName */ private function callHandler($methodName) { $method = $this->getReflection()->getMethod($methodName); $parameters = $method->getParameters(); $args = []; foreach ($parameters as $parameter) { $name = $parameter->getName(); $parsedName = $this->createLinkName() . '-' . $name; $currentValue = $this->getApplication()->getRequest()->get('m_' . $parsedName); if (!is_null($currentValue)) { if (($parameter->isArray() || $parameter->isDefaultValueAvailable() && is_array($parameter->getDefaultValue())) && !is_array($currentValue)) { throw new Mesour\UnexpectedValueException(sprintf('Invalid request. Argument must be an array. "%s" given.', gettype($currentValue))); } $value = $currentValue; } else { if ($parameter->isDefaultValueAvailable()) { $value = $parameter->getDefaultValue(); } else { throw new Mesour\InvalidArgumentException(sprintf('Invalid request. Required parameter %s doest not exists.', $parsedName)); } } $args[] = $value; } Mesour\Components\Utils\Helpers::invokeArgs([$this, $methodName], $args); $this->getSession()->saveState(); }
/** * @param array $args * @return int|mixed */ protected function tryInvokeCallback(array $args = []) { return $this->callback ? Mesour\Components\Utils\Helpers::invokeArgs($this->callback, $args) : self::NO_CALLBACK; }