Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
NameInformation.php
001 <?php
002 /**
003 * Zend Framework (http://framework.zend.com/)
004 *
005 * @link http://github.com/zendframework/zf2 for the canonical source repository
006 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
007 * @license http://framework.zend.com/license/new-bsd New BSD License
008 */
009
010 namespace Zend\Code;
011
012 class NameInformation
013 {
014 /**
015 * @var string
016 */
017 protected $namespace = null;
018
019 /**
020 * @var array
021 */
022 protected $uses = array();
023
024 /**
025 * @param string $namespace
026 * @param array $uses
027 */
028 public function __construct($namespace = null, array $uses = array())
029 {
030 if ($namespace) {
031 $this->setNamespace($namespace);
032 }
033 if ($uses) {
034 $this->setUses($uses);
035 }
036 }
037
038 /**
039 * @param string $namespace
040 * @return NameInformation
041 */
042 public function setNamespace($namespace)
043 {
044 $this->namespace = (string) $namespace;
045 return $this;
046 }
047
048 /**
049 * @return string
050 */
051 public function getNamespace()
052 {
053 return $this->namespace;
054 }
055
056 /**
057 * @return bool
058 */
059 public function hasNamespace()
060 {
061 return ($this->namespace !== null);
062 }
063
064 /**
065 * @param array $uses
066 * @return NameInformation
067 */
068 public function setUses(array $uses)
069 {
070 $this->uses = array();
071 $this->addUses($uses);
072
073 return $this;
074 }
075
076 /**
077 * @param array $uses
078 * @return NameInformation
079 */
080 public function addUses(array $uses)
081 {
082 foreach ($uses as $use => $as) {
083 if (is_int($use)) {
084 $this->addUse($as);
085 } elseif (is_string($use)) {
086 $this->addUse($use, $as);
087 }
088 }
089
090 return $this;
091 }
092
093 /**
094 * @param array|string $use
095 * @param string $as
096 */
097 public function addUse($use, $as = null)
098 {
099 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 }
157