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 |
MethodGenerator.php
001 <?php
002 /*
003 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
004 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
005 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
006 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
007 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
008 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
009 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
010 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
011 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
012 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
013 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014 *
015 * This software consists of voluntary contributions made by many individuals
016 * and is licensed under the MIT license.
017 */
018
019 namespace ProxyManager\Generator;
020
021 use Zend\Code\Generator\DocBlockGenerator;
022 use Zend\Code\Generator\MethodGenerator as ZendMethodGenerator;
023 use Zend\Code\Reflection\MethodReflection;
024
025 /**
026 * Method generator that fixes minor quirks in ZF2's method generator
027 *
028 * @author Marco Pivetta <ocramius@gmail.com>
029 * @license MIT
030 */
031 class MethodGenerator extends ZendMethodGenerator
032 {
033 /**
034 * @var bool
035 */
036 protected $returnsReference = false;
037
038 /**
039 * @param boolean $returnsReference
040 */
041 public function setReturnsReference($returnsReference)
042 {
043 $this->returnsReference = (bool) $returnsReference;
044 }
045
046 /**
047 * @return boolean
048 */
049 public function returnsReference()
050 {
051 return $this->returnsReference;
052 }
053
054 /**
055 * @override enforces generation of \ProxyManager\Generator\MethodGenerator
056 *
057 * {@inheritDoc}
058 */
059 public static function fromReflection(MethodReflection $reflectionMethod)
060 {
061 /* @var $method self */
062 $method = new static();
063
064 $method->setSourceContent($reflectionMethod->getContents(false));
065 $method->setSourceDirty(false);
066
067 if ($reflectionMethod->getDocComment() != '') {
068 $method->setDocBlock(DocBlockGenerator::fromReflection($reflectionMethod->getDocBlock()));
069 }
070
071 $method->setFinal($reflectionMethod->isFinal());
072 $method->setVisibility(self::extractVisibility($reflectionMethod));
073
074 foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
075 $method->setParameter(ParameterGenerator::fromReflection($reflectionParameter));
076 }
077
078 $method->setStatic($reflectionMethod->isStatic());
079 $method->setName($reflectionMethod->getName());
080 $method->setBody($reflectionMethod->getBody());
081 $method->setReturnsReference($reflectionMethod->returnsReference());
082
083 return $method;
084 }
085
086 /**
087 * Retrieves the visibility for the given method reflection
088 *
089 * @param MethodReflection $reflectionMethod
090 *
091 * @return string
092 */
093 private static function extractVisibility(MethodReflection $reflectionMethod)
094 {
095 if ($reflectionMethod->isPrivate()) {
096 return static::VISIBILITY_PRIVATE;
097 }
098
099 if ($reflectionMethod->isProtected()) {
100 return static::VISIBILITY_PROTECTED;
101 }
102
103 return static::VISIBILITY_PUBLIC;
104 }
105
106 /**
107 * @override fixes by-reference return value in zf2's method generator
108 *
109 * {@inheritDoc}
110 */
111 public function generate()
112 {
113 $output = '';
114 $indent = $this->getIndentation();
115
116 if (null !== ($docBlock = $this->getDocBlock())) {
117 $docBlock->setIndentation($indent);
118
119 $output .= $docBlock->generate();
120 }
121
122 $output .= $indent . $this->generateMethodDeclaration() . self::LINE_FEED . $indent . '{' . self::LINE_FEED;
123
124 if ($this->body) {
125 $output .= preg_replace('#^(.+?)$#m', $indent . $indent . '$1', trim($this->body))
126 . self::LINE_FEED;
127 }
128
129 $output .= $indent . '}' . self::LINE_FEED;
130
131 return $output;
132 }
133
134 /**
135 * @return string
136 */
137 private function generateMethodDeclaration()
138 {
139 $output = $this->generateVisibility()
140 . ' function '
141 . (($this->returnsReference()) ? '& ' : '')
142 . $this->getName() . '(';
143
144 $parameterOutput = array();
145
146 foreach ($this->getParameters() as $parameter) {
147 $parameterOutput[] = $parameter->generate();
148 }
149
150 return $output . implode(', ', $parameterOutput) . ')';
151 }
152
153 /**
154 * @return string
155 */
156 private function generateVisibility()
157 {
158 return $this->isAbstract() ? 'abstract ' : (($this->isFinal()) ? 'final ' : '')
159 . ($this->getVisibility() . (($this->isStatic()) ? ' static' : ''));
160 }
161 }
162