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 |
InterceptorGenerator.php
01 <?php
02 /*
03 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
04 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
05 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
06 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
07 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
08 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
09 * 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\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util;
20
21 use ProxyManager\Generator\MethodGenerator;
22 use Zend\Code\Generator\PropertyGenerator;
23
24 /**
25 * Utility to create pre- and post- method interceptors around a given method body
26 *
27 * @author Marco Pivetta <ocramius@gmail.com>
28 * @license MIT
29 *
30 * @internal - this class is just here as a small utility for this component,
31 * don't use it in your own code
32 */
33 class InterceptorGenerator
34 {
35 /**
36 * @param string $methodBody the body of the previously generated code.
37 * It MUST assign the return value to a variable
38 * `$returnValue` instead of directly returning
39 * @param \ProxyManager\Generator\MethodGenerator $method
40 * @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors
41 * @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors
42 *
43 * @return string
44 */
45 public static function createInterceptedMethodBody(
46 $methodBody,
47 MethodGenerator $method,
48 PropertyGenerator $prefixInterceptors,
49 PropertyGenerator $suffixInterceptors
50 ) {
51 $name = var_export($method->getName(), true);
52 $prefixInterceptors = $prefixInterceptors->getName();
53 $suffixInterceptors = $suffixInterceptors->getName();
54 $params = array();
55
56 foreach ($method->getParameters() as $parameter) {
57 $parameterName = $parameter->getName();
58 $params[] = var_export($parameterName, true) . ' => $' . $parameter->getName();
59 }
60
61 $paramsString = 'array(' . implode(', ', $params) . ')';
62
63 return "if (isset(\$this->$prefixInterceptors" . "[$name])) {\n"
64 . " \$returnEarly = false;\n"
65 . " \$prefixReturnValue = \$this->$prefixInterceptors" . "[$name]->__invoke("
66 . "\$this, \$this, $name, $paramsString, \$returnEarly);\n\n"
67 . " if (\$returnEarly) {\n"
68 . " return \$prefixReturnValue;\n"
69 . " }\n"
70 . "}\n\n"
71 . $methodBody . "\n\n"
72 . "if (isset(\$this->$suffixInterceptors" . "[$name])) {\n"
73 . " \$returnEarly = false;\n"
74 . " \$suffixReturnValue = \$this->$suffixInterceptors" . "[$name]->__invoke("
75 . "\$this, \$this, $name, $paramsString, \$returnValue, \$returnEarly);\n\n"
76 . " if (\$returnEarly) {\n"
77 . " return \$suffixReturnValue;\n"
78 . " }\n"
79 . "}\n\n"
80 . "return \$returnValue;";
81 }
82 }
83