[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10 namespace Zend\Code; 11 12 class NameInformation 13 { 14 /** 15 * @var string 16 */ 17 protected $namespace = null; 18 19 /** 20 * @var array 21 */ 22 protected $uses = array(); 23 24 /** 25 * @param string $namespace 26 * @param array $uses 27 */ 28 public function __construct($namespace = null, array $uses = array()) 29 { 30 if ($namespace) { 31 $this->setNamespace($namespace); 32 } 33 if ($uses) { 34 $this->setUses($uses); 35 } 36 } 37 38 /** 39 * @param string $namespace 40 * @return NameInformation 41 */ 42 public function setNamespace($namespace) 43 { 44 $this->namespace = (string) $namespace; 45 return $this; 46 } 47 48 /** 49 * @return string 50 */ 51 public function getNamespace() 52 { 53 return $this->namespace; 54 } 55 56 /** 57 * @return bool 58 */ 59 public function hasNamespace() 60 { 61 return ($this->namespace !== null); 62 } 63 64 /** 65 * @param array $uses 66 * @return NameInformation 67 */ 68 public function setUses(array $uses) 69 { 70 $this->uses = array(); 71 $this->addUses($uses); 72 73 return $this; 74 } 75 76 /** 77 * @param array $uses 78 * @return NameInformation 79 */ 80 public function addUses(array $uses) 81 { 82 foreach ($uses as $use => $as) { 83 if (is_int($use)) { 84 $this->addUse($as); 85 } elseif (is_string($use)) { 86 $this->addUse($use, $as); 87 } 88 } 89 90 return $this; 91 } 92 93 /** 94 * @param array|string $use 95 * @param string $as 96 */ 97 public function addUse($use, $as = null) 98 { 99 if (is_array($use) && array_key_exists('use', $use) && array_key_exists('as', $use)) { 100 $uses = $use; 101 $use = $uses['use']; 102 $as = $uses['as']; 103 } 104 105 $use = trim($use, '\\'); 106 if ($as === null) { 107 $as = trim($use, '\\'); 108 $nsSeparatorPosition = strrpos($as, '\\'); 109 if ($nsSeparatorPosition !== false && $nsSeparatorPosition !== 0 && $nsSeparatorPosition != strlen($as)) { 110 $as = substr($as, $nsSeparatorPosition + 1); 111 } 112 } 113 114 $this->uses[$use] = $as; 115 } 116 117 /** 118 * @return array 119 */ 120 public function getUses() 121 { 122 return $this->uses; 123 } 124 125 /** 126 * @param string $name 127 * @return string 128 */ 129 public function resolveName($name) 130 { 131 if ($this->namespace && !$this->uses && strlen($name) > 0 && $name{0} != '\\') { 132 return $this->namespace . '\\' . $name; 133 } 134 135 if (!$this->uses || strlen($name) <= 0 || $name{0} == '\\') { 136 return ltrim($name, '\\'); 137 } 138 139 if ($this->namespace || $this->uses) { 140 $firstPart = $name; 141 if (($firstPartEnd = strpos($firstPart, '\\')) !== false) { 142 $firstPart = substr($firstPart, 0, $firstPartEnd); 143 } else { 144 $firstPartEnd = strlen($firstPart); 145 } 146 if (($fqns = array_search($firstPart, $this->uses)) !== false) { 147 return substr_replace($name, $fqns, 0, $firstPartEnd); 148 } 149 if ($this->namespace) { 150 return $this->namespace . '\\' . $name; 151 } 152 } 153 154 return $name; 155 } 156 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |