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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

InterceptorGenerator.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 3.80 KiB


 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\AccessInterceptorValueHolder\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  $valueHolder
 41       * @param \Zend\Code\Generator\PropertyGenerator  $prefixInterceptors
 42       * @param \Zend\Code\Generator\PropertyGenerator  $suffixInterceptors
 43       *
 44       * @return string
 45       */
 46      public static function createInterceptedMethodBody(
 47          $methodBody,
 48          MethodGenerator $method,
 49          PropertyGenerator $valueHolder,
 50          PropertyGenerator $prefixInterceptors,
 51          PropertyGenerator $suffixInterceptors
 52      ) {
 53          $name               = var_export($method->getName(), true);
 54          $valueHolder        = $valueHolder->getName();
 55          $prefixInterceptors = $prefixInterceptors->getName();
 56          $suffixInterceptors = $suffixInterceptors->getName();
 57          $params             = array();
 58   
 59          foreach ($method->getParameters() as $parameter) {
 60              $parameterName = $parameter->getName();
 61              $params[]      = var_export($parameterName, true) . ' => $' . $parameter->getName();
 62          }
 63   
 64          $paramsString = 'array(' . implode(', ', $params) . ')';
 65   
 66          return "if (isset(\$this->$prefixInterceptors" . "[$name])) {\n"
 67              . "    \$returnEarly       = false;\n"
 68              . "    \$prefixReturnValue = \$this->$prefixInterceptors" . "[$name]->__invoke("
 69              . "\$this, \$this->$valueHolder, $name, $paramsString, \$returnEarly);\n\n"
 70              . "    if (\$returnEarly) {\n"
 71              . "        return \$prefixReturnValue;\n"
 72              . "    }\n"
 73              . "}\n\n"
 74              . $methodBody . "\n\n"
 75              . "if (isset(\$this->$suffixInterceptors" . "[$name])) {\n"
 76              . "    \$returnEarly       = false;\n"
 77              . "    \$suffixReturnValue = \$this->$suffixInterceptors" . "[$name]->__invoke("
 78              . "\$this, \$this->$valueHolder, $name, $paramsString, \$returnValue, \$returnEarly);\n\n"
 79              . "    if (\$returnEarly) {\n"
 80              . "        return \$suffixReturnValue;\n"
 81              . "    }\n"
 82              . "}\n\n"
 83              . "return \$returnValue;";
 84      }
 85  }
 86