Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

UnsetPropertiesGenerator.php

Zuletzt modifiziert: 01.05.2026, 11:28 - Dateigröße: 2.83 KiB


 01  <?php
 02   
 03  declare(strict_types=1);
 04   
 05  namespace ProxyManager\ProxyGenerator\Util;
 06   
 07  /**
 08   * Generates code necessary to unset all the given properties from a particular given instance string name
 09   *
 10   * @author Marco Pivetta <ocramius@gmail.com>
 11   * @license MIT
 12   */
 13  final class UnsetPropertiesGenerator
 14  {
 15      private static $closureTemplate = <<<'PHP'
 16  \Closure::bind(function (\%s $instance) {
 17      %s
 18  }, $%s, %s)->__invoke($%s);
 19  PHP;
 20   
 21   
 22      public static function generateSnippet(Properties $properties, string $instanceName) : string
 23      {
 24          return self::generateUnsetAccessiblePropertiesCode($properties, $instanceName)
 25              . self::generateUnsetPrivatePropertiesCode($properties, $instanceName);
 26      }
 27   
 28      private static function generateUnsetAccessiblePropertiesCode(Properties $properties, string $instanceName) : string
 29      {
 30          $accessibleProperties = $properties->getAccessibleProperties();
 31   
 32          if (! $accessibleProperties) {
 33              return '';
 34          }
 35   
 36          return  self::generateUnsetStatement($accessibleProperties, $instanceName) . "\n\n";
 37      }
 38   
 39      private static function generateUnsetPrivatePropertiesCode(Properties $properties, string $instanceName) : string
 40      {
 41          $groups = $properties->getGroupedPrivateProperties();
 42   
 43          if (! $groups) {
 44              return '';
 45          }
 46   
 47          $unsetClosureCalls = [];
 48   
 49          /* @var $privateProperties \ReflectionProperty[] */
 50          foreach ($groups as $privateProperties) {
 51              /* @var $firstProperty \ReflectionProperty */
 52              $firstProperty  = reset($privateProperties);
 53   
 54              $unsetClosureCalls[] = self::generateUnsetClassPrivatePropertiesBlock(
 55                  $firstProperty->getDeclaringClass(),
 56                  $privateProperties,
 57                  $instanceName
 58              );
 59          }
 60   
 61          return implode("\n\n", $unsetClosureCalls) . "\n\n";
 62      }
 63   
 64      private static function generateUnsetClassPrivatePropertiesBlock(
 65          \ReflectionClass $declaringClass,
 66          array $properties,
 67          string $instanceName
 68      ) : string {
 69          $declaringClassName = $declaringClass->getName();
 70   
 71          return sprintf(
 72              self::$closureTemplate,
 73              $declaringClassName,
 74              self::generateUnsetStatement($properties, 'instance'),
 75              $instanceName,
 76              var_export($declaringClassName, true),
 77              $instanceName
 78          );
 79      }
 80   
 81      private static function generateUnsetStatement(array $properties, string $instanceName) : string
 82      {
 83          return 'unset('
 84              . implode(
 85                  ', ',
 86                  array_map(
 87                      function (\ReflectionProperty $property) use ($instanceName) : string {
 88                          return '$' . $instanceName . '->' . $property->getName();
 89                      },
 90                      $properties
 91                  )
 92              )
 93              . ');';
 94      }
 95  }
 96