[ Index ] |
PHP Cross Reference of phpBB-3.3.2-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 declare(strict_types=1); 20 21 namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util; 22 23 use ProxyManager\Generator\MethodGenerator; 24 use ProxyManager\Generator\Util\ProxiedMethodReturnExpression; 25 use Zend\Code\Generator\PropertyGenerator; 26 27 /** 28 * Utility to create pre- and post- method interceptors around a given method body 29 * 30 * @author Marco Pivetta <ocramius@gmail.com> 31 * @license MIT 32 * 33 * @private - this class is just here as a small utility for this component, don't use it in your own code 34 */ 35 class InterceptorGenerator 36 { 37 /** 38 * @param string $methodBody the body of the previously generated code. 39 * It MUST assign the return value to a variable 40 * `$returnValue` instead of directly returning 41 * @param \ProxyManager\Generator\MethodGenerator $method 42 * @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors 43 * @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors 44 * @param \ReflectionMethod|null $originalMethod 45 * 46 * @return string 47 */ 48 public static function createInterceptedMethodBody( 49 string $methodBody, 50 MethodGenerator $method, 51 PropertyGenerator $prefixInterceptors, 52 PropertyGenerator $suffixInterceptors, 53 ?\ReflectionMethod $originalMethod 54 ) : string { 55 $name = var_export($method->getName(), true); 56 $prefixInterceptorsName = $prefixInterceptors->getName(); 57 $suffixInterceptorsName = $suffixInterceptors->getName(); 58 $params = []; 59 60 foreach ($method->getParameters() as $parameter) { 61 $parameterName = $parameter->getName(); 62 $params[] = var_export($parameterName, true) . ' => $' . $parameter->getName(); 63 } 64 65 $paramsString = 'array(' . implode(', ', $params) . ')'; 66 67 return "if (isset(\$this->$prefixInterceptorsName" . "[$name])) {\n" 68 . " \$returnEarly = false;\n" 69 . " \$prefixReturnValue = \$this->$prefixInterceptorsName" . "[$name]->__invoke(" 70 . "\$this, \$this, $name, $paramsString, \$returnEarly);\n\n" 71 . " if (\$returnEarly) {\n" 72 . ' ' . ProxiedMethodReturnExpression::generate('$prefixReturnValue', $originalMethod) . "\n" 73 . " }\n" 74 . "}\n\n" 75 . $methodBody . "\n\n" 76 . "if (isset(\$this->$suffixInterceptorsName" . "[$name])) {\n" 77 . " \$returnEarly = false;\n" 78 . " \$suffixReturnValue = \$this->$suffixInterceptorsName" . "[$name]->__invoke(" 79 . "\$this, \$this, $name, $paramsString, \$returnValue, \$returnEarly);\n\n" 80 . " if (\$returnEarly) {\n" 81 . ' ' . ProxiedMethodReturnExpression::generate('$suffixReturnValue', $originalMethod) . "\n" 82 . " }\n" 83 . "}\n\n" 84 . ProxiedMethodReturnExpression::generate('$returnValue', $originalMethod); 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:28:18 2020 | Cross-referenced by PHPXref 0.7.1 |