[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 * 15 * This software consists of voluntary contributions made by many individuals 16 * and is licensed under the MIT license. 17 */ 18 19 namespace ProxyManager\Generator; 20 21 use Zend\Code\Generator\DocBlockGenerator; 22 use Zend\Code\Generator\MethodGenerator as ZendMethodGenerator; 23 use Zend\Code\Reflection\MethodReflection; 24 25 /** 26 * Method generator that fixes minor quirks in ZF2's method generator 27 * 28 * @author Marco Pivetta <ocramius@gmail.com> 29 * @license MIT 30 */ 31 class MethodGenerator extends ZendMethodGenerator 32 { 33 /** 34 * @var bool 35 */ 36 protected $returnsReference = false; 37 38 /** 39 * @param boolean $returnsReference 40 */ 41 public function setReturnsReference($returnsReference) 42 { 43 $this->returnsReference = (bool) $returnsReference; 44 } 45 46 /** 47 * @return boolean 48 */ 49 public function returnsReference() 50 { 51 return $this->returnsReference; 52 } 53 54 /** 55 * @override enforces generation of \ProxyManager\Generator\MethodGenerator 56 * 57 * {@inheritDoc} 58 */ 59 public static function fromReflection(MethodReflection $reflectionMethod) 60 { 61 /* @var $method self */ 62 $method = new static(); 63 64 $method->setSourceContent($reflectionMethod->getContents(false)); 65 $method->setSourceDirty(false); 66 67 if ($reflectionMethod->getDocComment() != '') { 68 $method->setDocBlock(DocBlockGenerator::fromReflection($reflectionMethod->getDocBlock())); 69 } 70 71 $method->setFinal($reflectionMethod->isFinal()); 72 $method->setVisibility(self::extractVisibility($reflectionMethod)); 73 74 foreach ($reflectionMethod->getParameters() as $reflectionParameter) { 75 $method->setParameter(ParameterGenerator::fromReflection($reflectionParameter)); 76 } 77 78 $method->setStatic($reflectionMethod->isStatic()); 79 $method->setName($reflectionMethod->getName()); 80 $method->setBody($reflectionMethod->getBody()); 81 $method->setReturnsReference($reflectionMethod->returnsReference()); 82 83 return $method; 84 } 85 86 /** 87 * Retrieves the visibility for the given method reflection 88 * 89 * @param MethodReflection $reflectionMethod 90 * 91 * @return string 92 */ 93 private static function extractVisibility(MethodReflection $reflectionMethod) 94 { 95 if ($reflectionMethod->isPrivate()) { 96 return static::VISIBILITY_PRIVATE; 97 } 98 99 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 }
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 |