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

PluginCollection.php

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


 001  <?php
 002   
 003  /**
 004  * @package   s9e\TextFormatter
 005  * @copyright Copyright (c) 2010-2022 The s9e authors
 006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
 007  */
 008  namespace s9e\TextFormatter\Configurator\Collections;
 009   
 010  use InvalidArgumentException;
 011  use RuntimeException;
 012  use s9e\TextFormatter\Configurator;
 013  use s9e\TextFormatter\Plugins\ConfiguratorBase;
 014   
 015  class PluginCollection extends NormalizedCollection
 016  {
 017      /**
 018      * @var Configurator
 019      */
 020      protected $configurator;
 021   
 022      /**
 023      * Constructor
 024      *
 025      * @param Configurator $configurator
 026      */
 027      public function __construct(Configurator $configurator)
 028      {
 029          $this->configurator = $configurator;
 030      }
 031   
 032      /**
 033      * Finalize all of this collection's plugins
 034      *
 035      * @return void
 036      */
 037      public function finalize()
 038      {
 039          foreach ($this->items as $plugin)
 040          {
 041              $plugin->finalize();
 042          }
 043      }
 044   
 045      /**
 046      * Validate a plugin name
 047      *
 048      * @param  string $pluginName
 049      * @return string
 050      */
 051      public function normalizeKey($pluginName)
 052      {
 053          if (!preg_match('#^[A-Z][A-Za-z_0-9]+$#D', $pluginName))
 054          {
 055              throw new InvalidArgumentException("Invalid plugin name '" . $pluginName . "'");
 056          }
 057   
 058          return $pluginName;
 059      }
 060   
 061      /**
 062      * Create a plugin instance/ensure it implements the correct interface
 063      *
 064      * @param  mixed $value Either a class name or an object that implements ConfiguratorBase
 065      * @return ConfiguratorBase
 066      */
 067      public function normalizeValue($value)
 068      {
 069          if (is_string($value) && class_exists($value))
 070          {
 071              $value = new $value($this->configurator);
 072          }
 073   
 074          if ($value instanceof ConfiguratorBase)
 075          {
 076              return $value;
 077          }
 078   
 079          throw new InvalidArgumentException('PluginCollection::normalizeValue() expects a class name or an object that implements s9e\\TextFormatter\\Plugins\\ConfiguratorBase');
 080      }
 081   
 082      /**
 083      * Load a default plugin
 084      *
 085      * @param  string $pluginName    Name of the plugin
 086      * @param  array  $overrideProps Properties of the plugin will be overwritten with those
 087      * @return ConfiguratorBase
 088      */
 089      public function load($pluginName, array $overrideProps = [])
 090      {
 091          // Validate the plugin name / class
 092          $pluginName = $this->normalizeKey($pluginName);
 093          $className  = 's9e\\TextFormatter\\Plugins\\' . $pluginName . '\\Configurator';
 094   
 095          if (!class_exists($className))
 096          {
 097              throw new RuntimeException("Class '" . $className . "' does not exist");
 098          }
 099   
 100          // Create the plugin
 101          $plugin = new $className($this->configurator, $overrideProps);
 102   
 103          // Save it
 104          $this->set($pluginName, $plugin);
 105   
 106          // Return it
 107          return $plugin;
 108      }
 109   
 110      /**
 111      * {@inheritdoc}
 112      */
 113      public function asConfig()
 114      {
 115          $plugins = parent::asConfig();
 116   
 117          // Adjust plugins' default properties
 118          foreach ($plugins as $pluginName => &$pluginConfig)
 119          {
 120              $plugin = $this->get($pluginName);
 121   
 122              // Add base properties
 123              $pluginConfig += $plugin->getBaseProperties();
 124   
 125              // Remove quickMatch if it's false
 126              if ($pluginConfig['quickMatch'] === false)
 127              {
 128                  unset($pluginConfig['quickMatch']);
 129              }
 130   
 131              // Remove regexpLimit if there's no regexp
 132              if (!isset($pluginConfig['regexp']))
 133              {
 134                  unset($pluginConfig['regexpLimit']);
 135              }
 136   
 137              // Remove className if it's a default plugin using its default name. Its class name will
 138              // be generated by the parser automatically
 139              $className = 's9e\\TextFormatter\\Plugins\\' . $pluginName . '\\Parser';
 140              if ($pluginConfig['className'] === $className)
 141              {
 142                  unset($pluginConfig['className']);
 143              }
 144          }
 145          unset($pluginConfig);
 146   
 147          return $plugins;
 148      }
 149  }