Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

base.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 3.25 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  namespace phpbb\extension;
015   
016  use Symfony\Component\DependencyInjection\ContainerInterface;
017   
018  /**
019  * A base class for extensions without custom enable/disable/purge code.
020  */
021  class base implements \phpbb\extension\extension_interface
022  {
023      /** @var ContainerInterface */
024      protected $container;
025   
026      /** @var \phpbb\finder */
027      protected $finder;
028   
029      /** @var \phpbb\db\migrator */
030      protected $migrator;
031   
032      /** @var string */
033      protected $extension_name;
034   
035      /** @var string */
036      protected $extension_path;
037   
038      /** @var string[] */
039      private $migrations = false;
040   
041      /**
042      * Constructor
043      *
044      * @param ContainerInterface $container Container object
045      * @param \phpbb\finder $extension_finder
046      * @param \phpbb\db\migrator $migrator
047      * @param string $extension_name Name of this extension (from ext.manager)
048      * @param string $extension_path Relative path to this extension
049      */
050      public function __construct(ContainerInterface $container, \phpbb\finder $extension_finder, \phpbb\db\migrator $migrator, $extension_name, $extension_path)
051      {
052          $this->container = $container;
053          $this->extension_finder = $extension_finder;
054          $this->migrator = $migrator;
055   
056          $this->extension_name = $extension_name;
057          $this->extension_path = $extension_path;
058      }
059   
060      /**
061      * {@inheritdoc}
062      */
063      public function is_enableable()
064      {
065          return true;
066      }
067   
068      /**
069      * Single enable step that installs any included migrations
070      *
071      * @param mixed $old_state State returned by previous call of this method
072      * @return false Indicates no further steps are required
073      */
074      public function enable_step($old_state)
075      {
076          $migrations = $this->get_migration_file_list();
077   
078          $this->migrator->set_migrations($migrations);
079   
080          $this->migrator->update();
081   
082          return !$this->migrator->finished();
083      }
084   
085      /**
086      * Single disable step that does nothing
087      *
088      * @param mixed $old_state State returned by previous call of this method
089      * @return false Indicates no further steps are required
090      */
091      public function disable_step($old_state)
092      {
093          return false;
094      }
095   
096      /**
097      * Single purge step that reverts any included and installed migrations
098      *
099      * @param mixed $old_state State returned by previous call of this method
100      * @return false Indicates no further steps are required
101      */
102      public function purge_step($old_state)
103      {
104          $migrations = $this->get_migration_file_list();
105   
106          $this->migrator->set_migrations($migrations);
107   
108          foreach ($migrations as $migration)
109          {
110              while ($this->migrator->migration_state($migration) !== false)
111              {
112                  $this->migrator->revert($migration);
113   
114                  return true;
115              }
116          }
117   
118          return false;
119      }
120   
121      /**
122      * Get the list of migration files from this extension
123      *
124      * @return array
125      */
126      protected function get_migration_file_list()
127      {
128          if ($this->migrations !== false)
129          {
130              return $this->migrations;
131          }
132   
133          // Only have the finder search in this extension path directory
134          $migrations = $this->extension_finder
135              ->extension_directory('/migrations')
136              ->find_from_extension($this->extension_name, $this->extension_path);
137   
138          $migrations = $this->extension_finder->get_classes_from_files($migrations);
139   
140          return $migrations;
141      }
142  }
143