Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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 |
base.php
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 $extension_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 $this->get_migration_file_list();
077
078 $this->migrator->update();
079
080 return !$this->migrator->finished();
081 }
082
083 /**
084 * Single disable step that does nothing
085 *
086 * @param mixed $old_state State returned by previous call of this method
087 * @return false Indicates no further steps are required
088 */
089 public function disable_step($old_state)
090 {
091 return false;
092 }
093
094 /**
095 * Single purge step that reverts any included and installed migrations
096 *
097 * @param mixed $old_state State returned by previous call of this method
098 * @return false Indicates no further steps are required
099 */
100 public function purge_step($old_state)
101 {
102 $migrations = $this->get_migration_file_list();
103
104 foreach ($migrations as $migration)
105 {
106 while ($this->migrator->migration_state($migration) !== false)
107 {
108 $this->migrator->revert($migration);
109
110 return true;
111 }
112 }
113
114 return false;
115 }
116
117 /**
118 * Get the list of migration files from this extension
119 *
120 * @return array
121 */
122 protected function get_migration_file_list()
123 {
124 if ($this->migrations !== false)
125 {
126 return $this->migrations;
127 }
128
129 // Only have the finder search in this extension path directory
130 $migrations = $this->extension_finder
131 ->extension_directory('/migrations')
132 ->find_from_extension($this->extension_name, $this->extension_path);
133
134 $migrations = $this->extension_finder->get_classes_from_files($migrations);
135
136 $this->migrator->set_migrations($migrations);
137
138 $migrations = $this->migrator->get_migrations();
139
140 return $migrations;
141 }
142 }
143