/** * Creates a Dispatcher instance from a class name. * * @param string $className Fully qualified class name. * @param string $action Action name. * @param array $params Parameters. * * @return Dispatcher */ public static function customDispatcher($className, $action, $params) { $dispatcher = new self(); $dispatcher->setClassName($className); $dispatcher->setAction($action); $dispatcher->setParams($params); return $dispatcher; }
public static function factory(array $data) { $rpc = new self(); $rpc->setId($data['tid']); $rpc->setAction($data['action']); $rpc->setMethod($data['method']); $rpc->setData($data['data'] ?: array()); $rpc->setParameters($data); return $rpc; }
/** * @param string $name * @param string $condition * @param string $action * @param int $priority * @param string $description * * @return Rule */ public static function factory($name, $condition, $action, $priority = 0, $description = '') { $rule = new self(); $rule->setName($name); $rule->setCondition($condition); $rule->setAction($action); $rule->setPriority($priority); $rule->setDescription($description); return $rule; }
/** * @param $category * @param $action * @param $label * @param $day * @param $month * @param $year * @return Event */ public static function getByDate($category, $action, $label, $day, $month, $year) { $event = new self(); try { $event->getDao()->getByDate($category, $action, $label, $day, $month, $year); } catch (\Exception $e) { $event->setTimestamp(mktime(1, 0, 0, $month, $day, $year)); $event->setCategory($category); $event->setAction($action); $event->setLabel($label); } return $event; }
/** * Build a new route and add it to the Map. * * @param array $methods Array containing http methods. * The supported methods are defined by Request::METHOD_* constants * @param string $routeStr A string that may contain parameters * that will be passed to the controller. * For example: * - /home * - /product/{productId} * - /tag/{slug} * @param array $info An array containing the following indexes: * - controller: Name of a controller class * - action: Method of the defined controller (Default: index) * - alias: Short name of the route, for easy referencing */ public static function create(array $methods, string $routeStr, array $info) { $middlewareList = isset($info['middleware']) ? (array) $info['middleware'] : []; array_walk_recursive(self::$middlewareGroupStack, function ($middleware) use(&$middlewareList) { $middlewareList[] = $middleware; }); $route = new self(); $route->setMethods($methods); $route->setAction(isset($info['action']) ? $info['action'] : 'index'); $route->setAlias(isset($info['alias']) ? $info['alias'] : ''); $route->setMiddlewareList($middlewareList); $route->setControllerName($info['controller']); $route->setMethods($methods); $route->setRouteStr($routeStr); Map::addRoute($route); }
/** * Creates a rule description instance with specified XML string. * * @param string $ruleDescriptionXml A XML string representing the * rule description. * * @return none */ public static function create($ruleDescriptionXml) { $ruleDescription = new self(); $root = simplexml_load_string($ruleDescriptionXml); $nameSpaces = $root->getNameSpaces(); $ruleDescriptionArray = (array) $root; if (array_key_exists('Filter', $ruleDescriptionArray)) { $filterItem = $ruleDescriptionArray['Filter']; $filterAttributes = $filterItem->attributes('i', true); $filterItemArray = (array) $filterItem; $filterType = (string) $filterAttributes['type']; $filter = null; switch ($filterType) { case 'TrueFilter': $filter = new TrueFilter(); break; case 'FalseFilter': $filter = new FalseFilter(); break; case 'CorrelationFilter': $filter = new CorrelationFilter(); if (array_key_exists('CorrelationId', $filterItemArray)) { $filter->setCorrelationId((string) $filterItemArray['CorrelationId']); } break; case 'SqlFilter': $filter = new SqlFilter(); if (array_key_exists('SqlExpression', $filterItemArray)) { $filter->setSqlExpression((string) $filterItemArray['SqlExpression']); } if (array_key_exists('CompatibilityLevel', $filterItemArray)) { $filter->setCompatibilityLevel((int) $filterItemArray['CompatibilityLevel']); } break; default: $filter = new Filter(); } $ruleDescription->setFilter($filter); } if (array_key_exists('Action', $ruleDescriptionArray)) { $actionItem = $ruleDescriptionArray['Action']; $actionAttributes = $actionItem->attributes('i', true); $actionType = (string) $actionAttributes['type']; $action = null; switch ($actionType) { case 'EmptyRuleAction': $action = new EmptyRuleAction(); break; case 'SqlRuleAction': $action = new SqlRuleAction(); if (array_key_exists('SqlExpression', $actionItem)) { $action->setSqlExpression((string) $actionItem['SqlExpression']); } break; default: $action = new Action(); } $ruleDescription->setAction($action); } if (array_key_exists('Name', $ruleDescriptionArray)) { $ruleDescription->setName((string) $ruleDescriptionArray['Name']); } return $ruleDescription; }