v7‰PNG  IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ± üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0A­ºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT PK\< zyy Abstract.phpnu[setParams($params); } /** * Add or modify a parameter to use when instantiating an action controller * * @param string $name * @param mixed $value * @return Am_Mvc_Router */ public function setParam($name, $value) { $name = (string) $name; $this->_invokeParams[$name] = $value; return $this; } /** * Set parameters to pass to action controller constructors * * @param array $params * @return Am_Mvc_Router */ public function setParams(array $params) { $this->_invokeParams = array_merge($this->_invokeParams, $params); return $this; } /** * Retrieve a single parameter from the controller parameter stack * * @param string $name * @return mixed */ public function getParam($name) { if(isset($this->_invokeParams[$name])) { return $this->_invokeParams[$name]; } return null; } /** * Retrieve action controller instantiation parameters * * @return array */ public function getParams() { return $this->_invokeParams; } /** * Clear the controller parameter stack * * By default, clears all parameters. If a parameter name is given, clears * only that parameter; if an array of parameter names is provided, clears * each. * * @param null|string|array single key or array of keys for params to clear * @return Am_Mvc_Router */ public function clearParams($name = null) { if (null === $name) { $this->_invokeParams = array(); } elseif (is_string($name) && isset($this->_invokeParams[$name])) { unset($this->_invokeParams[$name]); } elseif (is_array($name)) { foreach ($name as $key) { if (is_string($key) && isset($this->_invokeParams[$key])) { unset($this->_invokeParams[$key]); } } } return $this; } } PK\}H Interface.phpnu[_urlDelimiter); $this->_defaults = (array) $defaults; $this->_requirements = (array) $reqs; $this->_translator = $translator; $this->_locale = $locale; if ($route !== '') { foreach (explode($this->_urlDelimiter, $route) as $pos => $part) { if (substr($part, 0, 1) == $this->_urlVariable && substr($part, 1, 1) != $this->_urlVariable) { $name = substr($part, 1); if (substr($name, 0, 1) === '@' && substr($name, 1, 1) !== '@') { $name = substr($name, 1); $this->_translatable[] = $name; $this->_isTranslated = true; } $this->_parts[$pos] = (isset($reqs[$name]) ? $reqs[$name] : $this->_defaultRegex); $this->_variables[$pos] = $name; } else { if (substr($part, 0, 1) == $this->_urlVariable) { $part = substr($part, 1); } if (substr($part, 0, 1) === '@' && substr($part, 1, 1) !== '@') { $this->_isTranslated = true; } $this->_parts[$pos] = $part; if ($part !== '*') { $this->_staticCount++; } } } } } /** * Matches a user submitted path with parts defined by a map. Assigns and * returns an array of variables on a successful match. * * @param string $path Path used to match against this routing map * @return array|false An array of assigned values or a false on a mismatch */ public function match($path, $partial = false) { $pathStaticCount = 0; $values = array(); $matchedPath = ''; if (!$partial) { $path = trim($path, $this->_urlDelimiter); } if ($path !== '') { $path = explode($this->_urlDelimiter, $path); foreach ($path as $pos => $pathPart) { // Path is longer than a route, it's not a match if (!array_key_exists($pos, $this->_parts)) { if ($partial) { break; } else { return false; } } $matchedPath .= $pathPart . $this->_urlDelimiter; // If it's a wildcard, get the rest of URL as wildcard data and stop matching if ($this->_parts[$pos] == '*') { $count = count($path); for($i = $pos; $i < $count; $i+=2) { $var = urldecode($path[$i]); if (!isset($this->_wildcardData[$var]) && !isset($this->_defaults[$var]) && !isset($values[$var])) { $this->_wildcardData[$var] = (isset($path[$i+1])) ? urldecode($path[$i+1]) : null; } } $matchedPath = implode($this->_urlDelimiter, $path); break; } $name = isset($this->_variables[$pos]) ? $this->_variables[$pos] : null; $pathPart = urldecode($pathPart); // Translate value if required $part = $this->_parts[$pos]; if ($this->_isTranslated && (substr($part, 0, 1) === '@' && substr($part, 1, 1) !== '@' && $name === null) || $name !== null && in_array($name, $this->_translatable)) { if (substr($part, 0, 1) === '@') { $part = substr($part, 1); } if (($originalPathPart = array_search($pathPart, $translateMessages)) !== false) { $pathPart = $originalPathPart; } } if (substr($part, 0, 2) === '@@') { $part = substr($part, 1); } // If it's a static part, match directly if ($name === null && $part != $pathPart) { return false; } // If it's a variable with requirement, match a regex. If not - everything matches if ($part !== null && !preg_match($this->_regexDelimiter . '^' . $part . '$' . $this->_regexDelimiter . 'iu', $pathPart)) { return false; } // If it's a variable store it's value for later if ($name !== null) { $values[$name] = $pathPart; } else { $pathStaticCount++; } } } // Check if all static mappings have been matched if ($this->_staticCount != $pathStaticCount) { return false; } $return = $values + $this->_wildcardData + $this->_defaults; // Check if all map variables have been initialized foreach ($this->_variables as $var) { if (!array_key_exists($var, $return)) { return false; } elseif ($return[$var] == '' || $return[$var] === null) { // Empty variable? Replace with the default value. $return[$var] = $this->_defaults[$var]; } } $this->setMatchedPath(rtrim($matchedPath, $this->_urlDelimiter)); $this->_values = $values; return $return; } /** * Assembles user submitted parameters forming a URL path defined by this route * * @param array $data An array of variable and value pairs used as parameters * @param boolean $reset Whether or not to set route defaults with those provided in $data * @return string Route path with user submitted parameters */ public function assemble($data = array(), $reset = false, $encode = false, $partial = false) { $url = array(); $flag = false; foreach ($this->_parts as $key => $part) { $name = isset($this->_variables[$key]) ? $this->_variables[$key] : null; $useDefault = false; if (isset($name) && array_key_exists($name, $data) && $data[$name] === null) { $useDefault = true; } if (isset($name)) { if (isset($data[$name]) && !$useDefault) { $value = $data[$name]; unset($data[$name]); } elseif (!$reset && !$useDefault && isset($this->_values[$name])) { $value = $this->_values[$name]; } elseif (!$reset && !$useDefault && isset($this->_wildcardData[$name])) { $value = $this->_wildcardData[$name]; } elseif (array_key_exists($name, $this->_defaults)) { $value = $this->_defaults[$name]; } else { //--//require_once 'Zend/Controller/Router/Exception.php'; throw new Am_Mvc_Router_Exception($name . ' is not specified'); } if ($this->_isTranslated && in_array($name, $this->_translatable)) { $url[$key] = $translator->translate($value, $locale); } else { $url[$key] = $value; } } elseif ($part != '*') { if ($this->_isTranslated && substr($part, 0, 1) === '@') { if (substr($part, 1, 1) !== '@') { $url[$key] = $translator->translate(substr($part, 1), $locale); } else { $url[$key] = substr($part, 1); } } else { if (substr($part, 0, 2) === '@@') { $part = substr($part, 1); } $url[$key] = $part; } } else { if (!$reset) $data += $this->_wildcardData; $defaults = $this->getDefaults(); foreach ($data as $var => $value) { if ($value !== null && (!isset($defaults[$var]) || $value != $defaults[$var])) { $url[$key++] = $var; $url[$key++] = $value; $flag = true; } } } } $return = ''; foreach (array_reverse($url, true) as $key => $value) { $defaultValue = null; if (isset($this->_variables[$key])) { $defaultValue = $this->getDefault($this->_variables[$key]); if ($this->_isTranslated && $defaultValue !== null && isset($this->_translatable[$this->_variables[$key]])) { $defaultValue = $translator->translate($defaultValue, $locale); } } if ($flag || $value !== $defaultValue || $partial) { if ($encode) $value = urlencode($value); $return = $this->_urlDelimiter . $value . $return; $flag = true; } } return trim($return, $this->_urlDelimiter); } /** * Return a single parameter of route's defaults * * @param string $name Array key of the parameter * @return string Previously set default */ public function getDefault($name) { if (isset($this->_defaults[$name])) { return $this->_defaults[$name]; } return null; } /** * Return an array of defaults * * @return array Route defaults */ public function getDefaults() { return $this->_defaults; } /** * Get all variables which are used by the route * * @return array */ public function getVariables() { return $this->_variables; } public static function getInstance(Zend_Config $config) { $reqs = ($config->reqs instanceof Zend_Config) ? $config->reqs->toArray() : array(); $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); return new self($config->route, $defs, $reqs); } } PK\H4""Route/Regex.phpnu[defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); $map = ($config->map instanceof Zend_Config) ? $config->map->toArray() : array(); $reverse = (isset($config->reverse)) ? $config->reverse : null; return new self($config->route, $defs, $map, $reverse); } public function __construct($route, $defaults = array(), $map = array(), $reverse = null) { $this->_regex = $route; $this->_defaults = (array) $defaults; $this->_map = (array) $map; $this->_reverse = $reverse; } public function getVersion() { return 1; } /** * Matches a user submitted path with a previously defined route. * Assigns and returns an array of defaults on a successful match. * * @param string $path Path used to match against this routing map * @return array|false An array of assigned values or a false on a mismatch */ public function match($path, $partial = false) { if (!$partial) { $path = trim(urldecode($path), self::URI_DELIMITER); $regex = '#^' . $this->_regex . '$#i'; } else { $regex = '#^' . $this->_regex . '#i'; } $res = preg_match($regex, $path, $values); if ($res === 0) { return false; } if ($partial) { $this->setMatchedPath($values[0]); } // array_filter_key()? Why isn't this in a standard PHP function set yet? :) foreach ($values as $i => $value) { if (!is_int($i) || $i === 0) { unset($values[$i]); } } $this->_values = $values; $values = $this->_getMappedValues($values); $defaults = $this->_getMappedValues($this->_defaults, false, true); $return = $values + $defaults; return $return; } /** * Maps numerically indexed array values to it's associative mapped counterpart. * Or vice versa. Uses user provided map array which consists of index => name * parameter mapping. If map is not found, it returns original array. * * Method strips destination type of keys form source array. Ie. if source array is * indexed numerically then every associative key will be stripped. Vice versa if reversed * is set to true. * * @param array $values Indexed or associative array of values to map * @param boolean $reversed False means translation of index to association. True means reverse. * @param boolean $preserve Should wrong type of keys be preserved or stripped. * @return array An array of mapped values */ protected function _getMappedValues($values, $reversed = false, $preserve = false) { if (count($this->_map) == 0) { return $values; } $return = array(); foreach ($values as $key => $value) { if (is_int($key) && !$reversed) { if (array_key_exists($key, $this->_map)) { $index = $this->_map[$key]; } elseif (false === ($index = array_search($key, $this->_map))) { $index = $key; } $return[$index] = $values[$key]; } elseif ($reversed) { $index = $key; if (!is_int($key)) { if (array_key_exists($key, $this->_map)) { $index = $this->_map[$key]; } else { $index = array_search($key, $this->_map, true); } } if (false !== $index) { $return[$index] = $values[$key]; } } elseif ($preserve) { $return[$key] = $value; } } return $return; } /** * Assembles a URL path defined by this route * * @param array $data An array of name (or index) and value pairs used as parameters * @return string Route path with user submitted parameters */ public function assemble($data = array(), $reset = false, $encode = false, $partial = false) { if ($this->_reverse === null) { //--//require_once 'Zend/Controller/Router/Exception.php'; throw new Am_Mvc_Router_Exception('Cannot assemble. Reversed route is not specified.'); } $defaultValuesMapped = $this->_getMappedValues($this->_defaults, true, false); $matchedValuesMapped = $this->_getMappedValues($this->_values, true, false); $dataValuesMapped = $this->_getMappedValues($data, true, false); // handle resets, if so requested (By null value) to do so if (($resetKeys = array_search(null, $dataValuesMapped, true)) !== false) { foreach ((array) $resetKeys as $resetKey) { if (isset($matchedValuesMapped[$resetKey])) { unset($matchedValuesMapped[$resetKey]); unset($dataValuesMapped[$resetKey]); } } } // merge all the data together, first defaults, then values matched, then supplied $mergedData = $defaultValuesMapped; $mergedData = $this->_arrayMergeNumericKeys($mergedData, $matchedValuesMapped); $mergedData = $this->_arrayMergeNumericKeys($mergedData, $dataValuesMapped); if ($encode) { foreach ($mergedData as $key => &$value) { $value = urlencode($value); } } ksort($mergedData); $return = @vsprintf($this->_reverse, $mergedData); if ($return === false) { //--//require_once 'Zend/Controller/Router/Exception.php'; throw new Am_Mvc_Router_Exception('Cannot assemble. Too few arguments?'); } return $return; } /** * Return a single parameter of route's defaults * * @param string $name Array key of the parameter * @return string Previously set default */ public function getDefault($name) { if (isset($this->_defaults[$name])) { return $this->_defaults[$name]; } } /** * Return an array of defaults * * @return array Route defaults */ public function getDefaults() { return $this->_defaults; } /** * Get all variables which are used by the route * * @return array */ public function getVariables() { $variables = array(); foreach ($this->_map as $key => $value) { if (is_numeric($key)) { $variables[] = $value; } else { $variables[] = $key; } } return $variables; } /** * _arrayMergeNumericKeys() - allows for a strict key (numeric's included) array_merge. * php's array_merge() lacks the ability to merge with numeric keys. * * @param array $array1 * @param array $array2 * @return array */ protected function _arrayMergeNumericKeys(Array $array1, Array $array2) { $returnArray = $array1; foreach ($array2 as $array2Index => $array2Value) { $returnArray[$array2Index] = $array2Value; } return $returnArray; } } PK\a{s  Route/Static.phpnu[defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); return new self($config->route, $defs); } /** * Prepares the route for mapping. * * @param string $route Map used to match with later submitted URL path * @param array $defaults Defaults for map variables with keys as variable names */ public function __construct($route, $defaults = array()) { $this->_route = trim($route, self::URI_DELIMITER); $this->_defaults = (array) $defaults; } /** * Matches a user submitted path with a previously defined route. * Assigns and returns an array of defaults on a successful match. * * @param string $path Path used to match against this routing map * @return array|false An array of assigned values or a false on a mismatch */ public function match($path, $partial = false) { if ($partial) { if ((empty($path) && empty($this->_route)) || (substr($path, 0, strlen($this->_route)) === $this->_route) ) { $this->setMatchedPath($this->_route); return $this->_defaults; } } else { if (trim($path, self::URI_DELIMITER) == $this->_route) { return $this->_defaults; } } return false; } /** * Assembles a URL path defined by this route * * @param array $data An array of variable and value pairs used as parameters * @return string Route path with user submitted parameters */ public function assemble($data = array(), $reset = false, $encode = false, $partial = false) { return $this->_route; } /** * Return a single parameter of route's defaults * * @param string $name Array key of the parameter * @return string Previously set default */ public function getDefault($name) { if (isset($this->_defaults[$name])) { return $this->_defaults[$name]; } return null; } /** * Return an array of defaults * * @return array Route defaults */ public function getDefaults() { return $this->_defaults; } } PK\$- - Route/Abstract.phpnu[_matchedPath = $path; } /** * Get partially matched path * * @return string */ public function getMatchedPath() { return $this->_matchedPath; } /** * Check or set wether this is an abstract route or not * * @param boolean $flag * @return boolean */ public function isAbstract($flag = null) { if ($flag !== null) { $this->_isAbstract = $flag; } return $this->_isAbstract; } /** * Create a new chain * * @param Am_Mvc_Router_Route_Abstract $route * @param string $separator * @return Am_Mvc_Router_Route_Chain */ public function chain(Am_Mvc_Router_Route_Abstract $route, $separator = '/') { //--//require_once 'Zend/Controller/Router/Route/Chain.php'; $chain = new Am_Mvc_Router_Route_Chain(); $chain->chain($this)->chain($route, $separator); return $chain; } } PK\bRoute/Interface.phpnu[defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); return new self($config->route, $defs); } /** * Add a route to this chain * * @param Am_Mvc_Router_Route_Abstract $route * @param string $separator * @return Am_Mvc_Router_Route_Chain */ public function chain(Am_Mvc_Router_Route_Abstract $route, $separator = self::URI_DELIMITER) { $this->_routes[] = $route; $this->_separators[] = $separator; return $this; } /** * Matches a user submitted path with a previously defined route. * Assigns and returns an array of defaults on a successful match. * * @param Am_Mvc_Request_Http $request Request to get the path info from * @param null $partial * @return array|false An array of assigned values or a false on a mismatch */ public function match($request, $partial = null) { $path = trim($request->getPathInfo(), self::URI_DELIMITER); $subPath = $path; $values = array(); $numRoutes = count($this->_routes); $matchedPath = null; foreach ($this->_routes as $key => $route) { if ($key > 0 && $matchedPath !== null && $subPath !== '' && $subPath !== false ) { $separator = substr($subPath, 0, strlen($this->_separators[$key])); if ($separator !== $this->_separators[$key]) { return false; } $subPath = substr($subPath, strlen($separator)); } // TODO: Should be an interface method. Hack for 1.0 BC if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) { $match = $subPath; } else { $request->setPathInfo($subPath); $match = $request; } $res = $route->match($match, true, ($key == $numRoutes - 1)); if ($res === false) { return false; } $matchedPath = $route->getMatchedPath(); if ($matchedPath !== null) { $subPath = substr($subPath, strlen($matchedPath)); $separator = substr($subPath, 0, strlen($this->_separators[$key])); } $values = $res + $values; } $request->setPathInfo($path); if ($subPath !== '' && $subPath !== false) { return false; } return $values; } /** * Assembles a URL path defined by this route * * @param array $data An array of variable and value pairs used as parameters * @param bool $reset * @param bool $encode * @return string Route path with user submitted parameters */ public function assemble($data = array(), $reset = false, $encode = false) { $value = ''; $numRoutes = count($this->_routes); foreach ($this->_routes as $key => $route) { if ($key > 0) { $value .= $this->_separators[$key]; } $value .= $route->assemble($data, $reset, $encode, (($numRoutes - 1) > $key)); if (method_exists($route, 'getVariables')) { $variables = $route->getVariables(); foreach ($variables as $variable) { $data[$variable] = null; } } } return $value; } /** * Set the request object for this and the child routes * * @param Am_Mvc_Request|null $request * @return void */ public function setRequest(Am_Mvc_Request $request = null) { $this->_request = $request; foreach ($this->_routes as $route) { if (method_exists($route, 'setRequest')) { $route->setRequest($request); } } } /** * Return a single parameter of route's defaults * * @param string $name Array key of the parameter * @return string Previously set default */ public function getDefault($name) { $default = null; foreach ($this->_routes as $route) { if (method_exists($route, 'getDefault')) { $current = $route->getDefault($name); if (null !== $current) { $default = $current; } } } return $default; } /** * Return an array of defaults * * @return array Route defaults */ public function getDefaults() { $defaults = array(); foreach ($this->_routes as $route) { if (method_exists($route, 'getDefaults')) { $defaults = array_merge($defaults, $route->getDefaults()); } } return $defaults; } } PK\Ij Route/Module.phpnu[defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); $request = Am_Di::getInstance()->request; return new self($defs, $request); } /** * Constructor * * @param array $defaults Defaults for map variables with keys as variable names * @param Am_Mvc_Request $request Request object */ public function __construct(array $defaults = array(), Am_Mvc_Request $request = null) { $this->_defaults = $defaults; if (isset($request)) { $this->_request = $request; } } /** * Set request keys based on values in request object * * @return void */ protected function _setRequestKeys() { if (null !== $this->_request) { $this->_moduleKey = $this->_request->getModuleKey(); $this->_controllerKey = $this->_request->getControllerKey(); $this->_actionKey = $this->_request->getActionKey(); } $this->_defaults += array( $this->_controllerKey => 'index', $this->_actionKey => 'index', $this->_moduleKey => 'default', ); $this->_keysSet = true; } /** * Matches a user submitted path. Assigns and returns an array of variables * on a successful match. * * If a request object is registered, it uses its setModuleName(), * setControllerName(), and setActionName() accessors to set those values. * Always returns the values as an array. * * @param string $path Path used to match against this routing map * @return array An array of assigned values or a false on a mismatch */ public function match($path, $partial = false) { $this->_setRequestKeys(); $values = array(); $params = array(); if (!$partial) { $path = trim($path, self::URI_DELIMITER); } else { $matchedPath = $path; } if ($path != '') { $path = explode(self::URI_DELIMITER, $path); if (($path[0] == 'default') || in_array($path[0], Am_Di::getInstance()->modules->getEnabled())) { $values[$this->_moduleKey] = array_shift($path); $this->_moduleValid = true; } if (count($path) && !empty($path[0])) { $values[$this->_controllerKey] = array_shift($path); } if (count($path) && !empty($path[0])) { $values[$this->_actionKey] = array_shift($path); } if ($numSegs = count($path)) { for ($i = 0; $i < $numSegs; $i = $i + 2) { $key = urldecode($path[$i]); $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null; $params[$key] = (isset($params[$key]) ? (array_merge((array) $params[$key], array($val))): $val); } } } if ($partial) { $this->setMatchedPath($matchedPath); } $this->_values = $values + $params; return $this->_values + $this->_defaults; } /** * Assembles user submitted parameters forming a URL path defined by this route * * @param array $data An array of variable and value pairs used as parameters * @param bool $reset Weither to reset the current params * @return string Route path with user submitted parameters */ public function assemble($data = array(), $reset = false, $encode = true, $partial = false) { if (!$this->_keysSet) { $this->_setRequestKeys(); } $params = (!$reset) ? $this->_values : array(); foreach ($data as $key => $value) { if ($value !== null) { $params[$key] = $value; } elseif (isset($params[$key])) { unset($params[$key]); } } $params += $this->_defaults; $url = ''; if ($this->_moduleValid || array_key_exists($this->_moduleKey, $data)) { if ($params[$this->_moduleKey] != $this->_defaults[$this->_moduleKey]) { $module = $params[$this->_moduleKey]; } } unset($params[$this->_moduleKey]); $controller = $params[$this->_controllerKey]; unset($params[$this->_controllerKey]); $action = $params[$this->_actionKey]; unset($params[$this->_actionKey]); foreach ($params as $key => $value) { $key = ($encode) ? urlencode($key) : $key; if (is_array($value)) { foreach ($value as $arrayValue) { $arrayValue = ($encode) ? urlencode($arrayValue) : $arrayValue; $url .= self::URI_DELIMITER . $key; $url .= self::URI_DELIMITER . $arrayValue; } } else { if ($encode) $value = urlencode($value); $url .= self::URI_DELIMITER . $key; $url .= self::URI_DELIMITER . $value; } } if (!empty($url) || $action !== $this->_defaults[$this->_actionKey]) { if ($encode) $action = urlencode($action); $url = self::URI_DELIMITER . $action . $url; } if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) { if ($encode) $controller = urlencode($controller); $url = self::URI_DELIMITER . $controller . $url; } if (isset($module)) { if ($encode) $module = urlencode($module); $url = self::URI_DELIMITER . $module . $url; } return ltrim($url, self::URI_DELIMITER); } /** * Return a single parameter of route's defaults * * @param string $name Array key of the parameter * @return string Previously set default */ public function getDefault($name) { if (isset($this->_defaults[$name])) { return $this->_defaults[$name]; } } /** * Return an array of defaults * * @return array Route defaults */ public function getDefaults() { return $this->_defaults; } } PK\S>>> Exception.phpnu[>> eException.phpnu[PK