-
Notifications
You must be signed in to change notification settings - Fork 25
Symfony 7 and phpBB 4 compatibility #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iMattPro
wants to merge
5
commits into
phpbb-extensions:master
Choose a base branch
from
iMattPro:compatibility
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+501
−59
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| <?php | ||
| /** | ||
| * | ||
| * Pages extension for the phpBB Forum Software package. | ||
| * | ||
| * @copyright (c) 2015, 2025 phpBB Limited <https://www.phpbb.com> | ||
| * @license GNU General Public License, version 2 (GPL-2.0) | ||
| * | ||
| */ | ||
|
|
||
| namespace phpbb\pages\routing; | ||
|
|
||
| use phpbb\db\driver\driver_interface; | ||
| use Symfony\Component\Routing\Route; | ||
| use Symfony\Component\Routing\RouteCollection; | ||
|
|
||
| /** | ||
| * Core loader logic for loading routes from the database. | ||
| */ | ||
| class page_loader_core | ||
| { | ||
| /** @var driver_interface */ | ||
| protected $db; | ||
|
|
||
| /** @var string */ | ||
| protected $pages_table; | ||
|
|
||
| /** | ||
| * Constructor for the page_loader_core class. | ||
| * | ||
| * @param driver_interface $db The database driver instance. | ||
| * @param string $pages_table The name of the pages table in the database. | ||
| */ | ||
| public function __construct(driver_interface $db, string $pages_table) | ||
| { | ||
| $this->db = $db; | ||
| $this->pages_table = $pages_table; | ||
| } | ||
|
|
||
| /** | ||
| * Loads routes defined in Page's database. | ||
| * | ||
| * @return RouteCollection A RouteCollection instance | ||
| */ | ||
| public function load_routes(): RouteCollection | ||
| { | ||
| $collection = new RouteCollection(); | ||
|
|
||
| $sql = 'SELECT page_id, page_route | ||
| FROM ' . $this->pages_table; | ||
| $result = $this->db->sql_query($sql); | ||
| while ($row = $this->db->sql_fetchrow($result)) | ||
| { | ||
| $route = new Route('/' . $row['page_route']); | ||
| $route->setDefault('_controller', 'phpbb.pages.controller:display'); | ||
| $route->setDefault('route', $row['page_route']); | ||
| $collection->add('phpbb_pages_dynamic_route_' . $row['page_id'], $route); | ||
| } | ||
| $this->db->sql_freeresult($result); | ||
|
|
||
| return $collection; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the loader supports the specified type. | ||
| * | ||
| * @param mixed $type The type to check support for. | ||
| * @return bool True if the type is supported, false otherwise. | ||
| */ | ||
| public function supports_type($type): bool | ||
| { | ||
| return $type === 'phpbb_pages_route'; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
| /** | ||
| * | ||
| * Pages extension for the phpBB Forum Software package. | ||
| * | ||
| * @copyright (c) 2015, 2025 phpBB Limited <https://www.phpbb.com> | ||
| * @license GNU General Public License, version 2 (GPL-2.0) | ||
| * | ||
| */ | ||
|
|
||
| namespace phpbb\pages\routing; | ||
|
|
||
| use InvalidArgumentException; | ||
| use phpbb\db\driver\driver_interface; | ||
| use Symfony\Component\Config\Loader\Loader; | ||
| use Symfony\Component\Routing\RouteCollection; | ||
|
|
||
| /** | ||
| * phpBB 3 and Symfony 3 through 6 adapter for page loader. | ||
| */ | ||
| class page_loader_phpbb3 extends Loader | ||
| { | ||
| /** @var page_loader_core */ | ||
| protected $core; | ||
|
|
||
| /** | ||
| * Constructor for the page_loader_phpbb3 class. | ||
| * | ||
| * @param driver_interface $db The database driver instance. | ||
| * @param string $pages_table The name of the pages table in the database. | ||
| */ | ||
| public function __construct(driver_interface $db, string $pages_table) | ||
| { | ||
iMattPro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->core = new page_loader_core($db, $pages_table); | ||
| } | ||
|
|
||
| /** | ||
| * Loads routes from the database. | ||
| * | ||
| * @param mixed $resource The resource to load routes from. | ||
| * @param string|null $type The type of the resource, or null if not specified. | ||
| * @return RouteCollection The collection of loaded routes. | ||
| */ | ||
| public function load($resource, $type = null) | ||
| { | ||
| if (!is_string($type) && $type !== null) | ||
| { | ||
| throw new InvalidArgumentException('Type must be string or null'); | ||
| } | ||
iMattPro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return $this->core->load_routes(); | ||
| } | ||
|
|
||
| /** | ||
| * Determines if the given resource is supported based on its type. | ||
| * | ||
| * @param mixed $resource The resource to be checked. | ||
| * @param string|null $type The type of the resource, or null for default processing. | ||
| * @return bool True if the resource type is supported, false otherwise. | ||
| */ | ||
| public function supports($resource, $type = null): bool | ||
| { | ||
| return $this->core->supports_type($type); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
| /** | ||
| * | ||
| * Pages extension for the phpBB Forum Software package. | ||
| * | ||
| * @copyright (c) 2015, 2025 phpBB Limited <https://www.phpbb.com> | ||
| * @license GNU General Public License, version 2 (GPL-2.0) | ||
| * | ||
| */ | ||
|
|
||
| namespace phpbb\pages\routing; | ||
|
|
||
| use phpbb\db\driver\driver_interface; | ||
| use Symfony\Component\Config\Loader\Loader; | ||
| use Symfony\Component\Routing\RouteCollection; | ||
|
|
||
| /** | ||
| * phpBB 4 and Symfony 7 adapter for page loader. | ||
| */ | ||
| class page_loader_phpbb4 extends Loader | ||
| { | ||
| /** @var page_loader_core */ | ||
| protected page_loader_core $core; | ||
|
|
||
| /** | ||
| * Constructor for the page_loader_phpbb4 class. | ||
| * | ||
| * @param driver_interface $db The database driver instance. | ||
| * @param string $pages_table The name of the pages table in the database. | ||
| */ | ||
| public function __construct(driver_interface $db, string $pages_table) | ||
| { | ||
| $this->core = new page_loader_core($db, $pages_table); | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * Loads a set of routes from a specified resource. | ||
| * | ||
| * @param mixed $resource The resource to load routes from. | ||
| * @param string|null $type The type of the resource, or null if not specified. | ||
| * @return RouteCollection The collection of loaded routes. | ||
| */ | ||
| public function load(mixed $resource, ?string $type = null): RouteCollection | ||
| { | ||
| return $this->core->load_routes(); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the loader supports the specified resource and type. | ||
| * | ||
| * @param mixed $resource The resource to check support for. | ||
| * @param string|null $type The type of the resource, or null if not specified. | ||
| * @return bool True if the loader supports the resource and type, false otherwise. | ||
| */ | ||
| public function supports(mixed $resource, ?string $type = null): bool | ||
| { | ||
| return $this->core->supports_type($type); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| <?php | ||
| /** | ||
| * | ||
| * Pages extension for the phpBB Forum Software package. | ||
| * | ||
| * @copyright (c) 2025 phpBB Limited <https://www.phpbb.com> | ||
| * @license GNU General Public License, version 2 (GPL-2.0) | ||
| * | ||
| */ | ||
|
|
||
| namespace phpbb\pages\tests\routing; | ||
|
|
||
| class page_loader_core_test extends \phpbb_database_test_case | ||
| { | ||
| protected static function setup_extensions() | ||
| { | ||
| return array('phpbb/pages'); | ||
| } | ||
|
|
||
| /** @var \phpbb\db\driver\driver_interface */ | ||
| protected $db; | ||
|
|
||
| /** @var \phpbb\pages\routing\page_loader_core */ | ||
| protected $loader; | ||
|
|
||
| public function getDataSet() | ||
| { | ||
| return $this->createXMLDataSet(__DIR__ . '/../operators/fixtures/page.xml'); | ||
| } | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| $this->db = $this->new_dbal(); | ||
| $this->loader = new \phpbb\pages\routing\page_loader_core($this->db, 'phpbb_pages'); | ||
| } | ||
|
|
||
| public function test_load_routes_returns_collection() | ||
| { | ||
| $collection = $this->loader->load_routes(); | ||
| self::assertInstanceOf('Symfony\Component\Routing\RouteCollection', $collection); | ||
| } | ||
|
|
||
| public static function route_data() | ||
| { | ||
| return array( | ||
| array(1, '/page_1'), | ||
| array(2, '/page_2'), | ||
| array(3, '/page_3'), | ||
| array(4, '/page_4'), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider route_data | ||
| */ | ||
| public function test_routes_have_correct_paths($id, $expected) | ||
| { | ||
| $collection = $this->loader->load_routes(); | ||
| $route = $collection->get('phpbb_pages_dynamic_route_' . $id); | ||
| self::assertInstanceOf('Symfony\Component\Routing\Route', $route); | ||
| self::assertSame($expected, $route->getPath()); | ||
| } | ||
|
|
||
| public function test_supports_type() | ||
| { | ||
| self::assertTrue($this->loader->supports_type('phpbb_pages_route')); | ||
| self::assertFalse($this->loader->supports_type('other_type')); | ||
| self::assertFalse($this->loader->supports_type(null)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.