web/lib/Zend/Controller/Router/Route/Hostname.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
--- a/web/lib/Zend/Controller/Router/Route/Hostname.php	Thu May 07 15:10:09 2015 +0200
+++ b/web/lib/Zend/Controller/Router/Route/Hostname.php	Thu May 07 15:16:02 2015 +0200
@@ -15,8 +15,8 @@
  * @category   Zend
  * @package    Zend_Controller
  * @subpackage Router
- * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @version    $Id: Hostname.php 24593 2012-01-05 20:35:02Z matthew $
+ * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
+ * @version    $Id$
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
 
@@ -28,19 +28,37 @@
  *
  * @package    Zend_Controller
  * @subpackage Router
- * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  * @see        http://manuals.rubyonrails.com/read/chapter/65
  */
 class Zend_Controller_Router_Route_Hostname extends Zend_Controller_Router_Route_Abstract
 {
 
-    protected $_hostVariable   = ':';
+    /**
+     * Host variable
+     *
+     * @var string
+     */
+    protected $_hostVariable = ':';
+
+    /**
+     * Regex delimiter
+     *
+     * @var string
+     */
     protected $_regexDelimiter = '#';
-    protected $_defaultRegex   = null;
+
+    /**
+     * Default regex string
+     *
+     * @var string|null
+     */
+    protected $_defaultRegex = null;
 
     /**
      * Holds names of all route's pattern variable names. Array index holds a position in host.
+     *
      * @var array
      */
     protected $_variables = array();
@@ -48,12 +66,14 @@
     /**
      * Holds Route patterns for all host parts. In case of a variable it stores it's regex
      * requirement or null. In case of a static part, it holds only it's direct value.
+     *
      * @var array
      */
     protected $_parts = array();
 
     /**
      * Holds user submitted default values for route's variables. Name and value pairs.
+     *
      * @var array
      */
     protected $_defaults = array();
@@ -61,12 +81,14 @@
     /**
      * Holds user submitted regular expression patterns for route's variables' values.
      * Name and value pairs.
+     *
      * @var array
      */
     protected $_requirements = array();
 
     /**
      * Default scheme
+     *
      * @var string
      */
     protected $_scheme = null;
@@ -74,6 +96,7 @@
     /**
      * Associative array filled on match() that holds matched path values
      * for given variable names.
+     *
      * @var array
      */
     protected $_values = array();
@@ -88,6 +111,7 @@
     /**
      * Helper var that holds a count of route pattern's static parts
      * for validation
+     *
      * @var int
      */
     private $_staticCount = 0;
@@ -96,7 +120,6 @@
      * Set the request object
      *
      * @param  Zend_Controller_Request_Abstract|null $request
-     * @return void
      */
     public function setRequest(Zend_Controller_Request_Abstract $request = null)
     {
@@ -122,12 +145,14 @@
      * Instantiates route based on passed Zend_Config structure
      *
      * @param Zend_Config $config Configuration object
+     * @return Zend_Controller_Router_Route_Hostname
      */
     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();
         $scheme = (isset($config->scheme)) ? $config->scheme : null;
+
         return new self($config->route, $defs, $reqs, $scheme);
     }
 
@@ -136,9 +161,9 @@
      * to a corresponding atomic parts. These parts are assigned
      * a position which is later used for matching and preparing values.
      *
-     * @param string $route Map used to match with later submitted hostname
+     * @param string $route    Map used to match with later submitted hostname
      * @param array  $defaults Defaults for map variables with keys as variable names
-     * @param array  $reqs Regular expression requirements for variables (keys as variable names)
+     * @param array  $reqs     Regular expression requirements for variables (keys as variable names)
      * @param string $scheme
      */
     public function __construct($route, $defaults = array(), $reqs = array(), $scheme = null)
@@ -151,8 +176,8 @@
         if ($route != '') {
             foreach (explode('.', $route) as $pos => $part) {
                 if (substr($part, 0, 1) == $this->_hostVariable) {
-                    $name = substr($part, 1);
-                    $this->_parts[$pos] = (isset($reqs[$name]) ? $reqs[$name] : $this->_defaultRegex);
+                    $name                   = substr($part, 1);
+                    $this->_parts[$pos]     = (isset($reqs[$name]) ? $reqs[$name] : $this->_defaultRegex);
                     $this->_variables[$pos] = $name;
                 } else {
                     $this->_parts[$pos] = $part;
@@ -187,7 +212,7 @@
         }
 
         $hostStaticCount = 0;
-        $values = array();
+        $values          = array();
 
         $host = trim($host, '.');
 
@@ -200,7 +225,7 @@
                     return false;
                 }
 
-                $name = isset($this->_variables[$pos]) ? $this->_variables[$pos] : null;
+                $name     = isset($this->_variables[$pos]) ? $this->_variables[$pos] : null;
                 $hostPart = urldecode($hostPart);
 
                 // If it's a static part, match directly
@@ -209,7 +234,12 @@
                 }
 
                 // If it's a variable with requirement, match a regex. If not - everything matches
-                if ($this->_parts[$pos] !== null && !preg_match($this->_regexDelimiter . '^' . $this->_parts[$pos] . '$' . $this->_regexDelimiter . 'iu', $hostPart)) {
+                if ($this->_parts[$pos] !== null
+                    && !preg_match(
+                        $this->_regexDelimiter . '^' . $this->_parts[$pos] . '$' . $this->_regexDelimiter . 'iu',
+                        $hostPart
+                    )
+                ) {
                     return false;
                 }
 
@@ -239,14 +269,16 @@
         $this->_values = $values;
 
         return $return;
-
     }
 
     /**
      * Assembles user submitted parameters forming a hostname defined by this route
      *
-     * @param  array $data An array of variable and value pairs used as parameters
+     * @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
+     * @param  boolean $encode
+     * @param  boolean $partial
+     * @throws Zend_Controller_Router_Exception
      * @return string Route path with user submitted parameters
      */
     public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
@@ -282,10 +314,14 @@
         $return = '';
 
         foreach (array_reverse($host, true) as $key => $value) {
-            if ($flag || !isset($this->_variables[$key]) || $value !== $this->getDefault($this->_variables[$key]) || $partial) {
-                if ($encode) $value = urlencode($value);
+            if ($flag || !isset($this->_variables[$key]) || $value !== $this->getDefault($this->_variables[$key])
+                || $partial
+            ) {
+                if ($encode) {
+                    $value = urlencode($value);
+                }
                 $return = '.' . $value . $return;
-                $flag = true;
+                $flag   = true;
             }
         }
 
@@ -302,7 +338,7 @@
             }
         }
 
-        $url      = $scheme . '://' . $url;
+        $url = $scheme . '://' . $url;
 
         return $url;
     }
@@ -313,10 +349,12 @@
      * @param string $name Array key of the parameter
      * @return string Previously set default
      */
-    public function getDefault($name) {
+    public function getDefault($name)
+    {
         if (isset($this->_defaults[$name])) {
             return $this->_defaults[$name];
         }
+
         return null;
     }
 
@@ -325,7 +363,8 @@
      *
      * @return array Route defaults
      */
-    public function getDefaults() {
+    public function getDefaults()
+    {
         return $this->_defaults;
     }