PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/application/libraries/Zend/Controller/Router/Route/Static.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 127 lines | 49 code | 12 blank | 66 comment | 8 complexity | a47a6cae6a2dc6b0e627b4e4a8faf2ef MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Controller
  17. * @subpackage Router
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @version $Id: Static.php 24182 2011-07-03 13:43:05Z adamlundrigan $
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /** Zend_Controller_Router_Route_Abstract */
  23. require_once 'Zend/Controller/Router/Route/Abstract.php';
  24. /**
  25. * StaticRoute is used for managing static URIs.
  26. *
  27. * It's a lot faster compared to the standard Route implementation.
  28. *
  29. * @package Zend_Controller
  30. * @subpackage Router
  31. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class Zend_Controller_Router_Route_Static extends Zend_Controller_Router_Route_Abstract
  35. {
  36. protected $_route = null;
  37. protected $_defaults = array();
  38. public function getVersion() {
  39. return 1;
  40. }
  41. /**
  42. * Instantiates route based on passed Zend_Config structure
  43. *
  44. * @param Zend_Config $config Configuration object
  45. */
  46. public static function getInstance(Zend_Config $config)
  47. {
  48. $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
  49. return new self($config->route, $defs);
  50. }
  51. /**
  52. * Prepares the route for mapping.
  53. *
  54. * @param string $route Map used to match with later submitted URL path
  55. * @param array $defaults Defaults for map variables with keys as variable names
  56. */
  57. public function __construct($route, $defaults = array())
  58. {
  59. $this->_route = trim($route, self::URI_DELIMITER);
  60. $this->_defaults = (array) $defaults;
  61. }
  62. /**
  63. * Matches a user submitted path with a previously defined route.
  64. * Assigns and returns an array of defaults on a successful match.
  65. *
  66. * @param string $path Path used to match against this routing map
  67. * @return array|false An array of assigned values or a false on a mismatch
  68. */
  69. public function match($path, $partial = false)
  70. {
  71. if ($partial) {
  72. if ((empty($path) && empty($this->_route))
  73. || (substr($path, 0, strlen($this->_route)) === $this->_route)
  74. ) {
  75. $this->setMatchedPath($this->_route);
  76. return $this->_defaults;
  77. }
  78. } else {
  79. if (trim($path, self::URI_DELIMITER) == $this->_route) {
  80. return $this->_defaults;
  81. }
  82. }
  83. return false;
  84. }
  85. /**
  86. * Assembles a URL path defined by this route
  87. *
  88. * @param array $data An array of variable and value pairs used as parameters
  89. * @return string Route path with user submitted parameters
  90. */
  91. public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
  92. {
  93. return $this->_route;
  94. }
  95. /**
  96. * Return a single parameter of route's defaults
  97. *
  98. * @param string $name Array key of the parameter
  99. * @return string Previously set default
  100. */
  101. public function getDefault($name) {
  102. if (isset($this->_defaults[$name])) {
  103. return $this->_defaults[$name];
  104. }
  105. return null;
  106. }
  107. /**
  108. * Return an array of defaults
  109. *
  110. * @return array Route defaults
  111. */
  112. public function getDefaults() {
  113. return $this->_defaults;
  114. }
  115. }