|
3 | 3 | * |
4 | 4 | * Pages extension for the phpBB Forum Software package. |
5 | 5 | * |
6 | | - * @copyright (c) 2015 phpBB Limited <https://www.phpbb.com> |
| 6 | + * @copyright (c) 2015, 2025 phpBB Limited <https://www.phpbb.com> |
7 | 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | 8 | * |
9 | 9 | */ |
| 10 | +// phpcs:disable PSR1.Files.SideEffects |
10 | 11 |
|
11 | 12 | namespace phpbb\pages\routing; |
12 | 13 |
|
13 | | -use phpbb\db\driver\driver_interface; |
14 | | -use Symfony\Component\Config\Loader\Loader; |
15 | | -use Symfony\Component\Routing\Route; |
16 | | -use Symfony\Component\Routing\RouteCollection; |
| 14 | +use Symfony\Component\HttpKernel\Kernel; |
| 15 | + |
| 16 | +if (!defined('IN_PHPBB')) |
| 17 | +{ |
| 18 | + exit; |
| 19 | +} |
17 | 20 |
|
18 | 21 | /** |
19 | | - * Loads routes defined in Page's database. |
| 22 | + * This code determines which page_loader class to use based on the Symfony version. |
| 23 | + * Symfony 7+ (phpBB4) uses page_loader_phpbb4, otherwise page_loader_phpbb3. |
| 24 | + * |
| 25 | + * @noinspection PhpMultipleClassDeclarationsInspection |
20 | 26 | */ |
21 | | -class page_loader extends Loader |
| 27 | +if (!class_exists(page_loader::class, false)) |
22 | 28 | { |
23 | | - /** @var driver_interface */ |
24 | | - protected $db; |
25 | | - |
26 | | - /** @var string */ |
27 | | - protected $pages_table; |
28 | | - |
29 | | - /** |
30 | | - * Constructor |
31 | | - * |
32 | | - * @param driver_interface $db Database connection |
33 | | - * @param string $pages_table Table name |
34 | | - * @access public |
35 | | - */ |
36 | | - public function __construct(driver_interface $db, $pages_table) |
| 29 | + // phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses |
| 30 | + if (version_compare(Kernel::VERSION, '7.0.0', '>=')) |
37 | 31 | { |
38 | | - $this->db = $db; |
39 | | - $this->pages_table = $pages_table; |
| 32 | + class page_loader extends page_loader_phpbb4 {} |
40 | 33 | } |
41 | | - |
42 | | - /** |
43 | | - * Loads routes defined in Page's database. |
44 | | - * |
45 | | - * @param string $resource Resource (not used, but required by parent interface) |
46 | | - * @param string|null $type The resource type |
47 | | - * |
48 | | - * @return RouteCollection A RouteCollection instance |
49 | | - * |
50 | | - * @api |
51 | | - */ |
52 | | - public function load($resource, $type = null) |
53 | | - { |
54 | | - $collection = new RouteCollection(); |
55 | | - |
56 | | - $sql = 'SELECT page_id, page_route |
57 | | - FROM ' . $this->pages_table; |
58 | | - $result = $this->db->sql_query($sql); |
59 | | - while ($row = $this->db->sql_fetchrow($result)) |
60 | | - { |
61 | | - $route = new Route('/' . $row['page_route']); |
62 | | - $route->setDefault('_controller', 'phpbb.pages.controller:display'); |
63 | | - $route->setDefault('route', $row['page_route']); |
64 | | - $collection->add('phpbb_pages_dynamic_route_' . $row['page_id'], $route); |
65 | | - } |
66 | | - $this->db->sql_freeresult(); |
67 | | - |
68 | | - return $collection; |
69 | | - } |
70 | | - |
71 | | - /** |
72 | | - * {@inheritdoc} |
73 | | - * |
74 | | - * @api |
75 | | - */ |
76 | | - public function supports($resource, $type = null) |
| 34 | + else |
77 | 35 | { |
78 | | - return $type === 'phpbb_pages_route'; |
| 36 | + class page_loader extends page_loader_phpbb3 {} |
79 | 37 | } |
| 38 | + // phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses |
80 | 39 | } |
| 40 | +// phpcs:enable PSR1.Files.SideEffects |
0 commit comments