-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.0] Introduce router service #20339
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
Changes from 24 commits
2c7728e
e94cc78
2f64e1d
092c026
5ebf3b3
665b6cf
afd9c73
156a388
b44e8ad
329a20c
0cdfc17
99550a7
dbf7300
73d9098
625f730
df49591
6fd4f9f
76d5c06
ac82176
a9d5e6e
6d50d75
868895c
eed26f9
36769de
afae590
531b693
9722661
9f0298c
2499795
085953e
80bd410
dd75148
1cfca61
111a333
404991f
df353dc
4085469
d8f196c
c1eaca8
5b25d40
c956108
f6ab98c
550de78
8ea0ada
5621d7c
bc69b61
9dcd4c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?php | ||
| /** | ||
| * Joomla! Content Management System | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Component\Content\Administrator\Service\Provider; | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| use Joomla\DI\Container; | ||
| use Joomla\DI\ServiceProviderInterface; | ||
| use Joomla\CMS\Component\Router\RouterFactoryInterface; | ||
| use Joomla\CMS\Categories\Categories; | ||
| use Joomla\Database\DatabaseInterface; | ||
|
|
||
| /** | ||
| * Service provider for the service dispatcher factory. | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class RouterFactory implements ServiceProviderInterface | ||
| { | ||
| /** | ||
| * Registers the service provider with a DI container. | ||
| * | ||
| * @param Container $container The DI container. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function register(Container $container) | ||
| { | ||
| $container->set( | ||
| RouterFactoryInterface::class, | ||
| function (Container $container) | ||
| { | ||
| return new \Joomla\Component\Content\Site\Router\RouterFactory( | ||
| $container->get(Categories::class)[''], | ||
| $container->get(DatabaseInterface::class) | ||
| ); | ||
| } | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
| /** | ||
| * Joomla! Content Management System | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| namespace Joomla\Component\Content\Site\Router; | ||
|
|
||
| defined('_JEXEC') or die; | ||
|
|
||
| use Joomla\CMS\Application\CMSApplicationInterface; | ||
| use Joomla\CMS\Application\SiteApplication; | ||
| use Joomla\CMS\Component\Router\RouterFactoryInterface; | ||
| use Joomla\CMS\Component\Router\RouterInterface; | ||
| use Joomla\CMS\Menu\AbstractMenu; | ||
| use Joomla\Component\Content\Site\Service\Category; | ||
| use Joomla\Database\DatabaseInterface; | ||
|
|
||
| /** | ||
| * Content router factory. | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class RouterFactory implements RouterFactoryInterface | ||
| { | ||
| /** | ||
| * The category | ||
| * | ||
| * @var Category | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| private $category; | ||
|
|
||
| /** | ||
| * The db | ||
| * | ||
| * @var DatabaseInterface | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| private $db; | ||
|
|
||
| /** | ||
| * Content Component router factory constructor | ||
| * | ||
| * @param Category $category The category object | ||
| * @param DatabaseInterface $db The database object | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function __construct(Category $category, DatabaseInterface $db) | ||
| { | ||
| $this->category = $category; | ||
| $this->db = $db; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a router. | ||
| * | ||
| * @param CMSApplicationInterface $application The application | ||
| * @param AbstractMenu $menu The menu object to work with | ||
| * | ||
| * @return RouterInterface | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function createRouter(CMSApplicationInterface $application, AbstractMenu $menu): RouterInterface | ||
|
||
| { | ||
| if (!$application instanceof SiteApplication) | ||
| { | ||
| throw new \RuntimeException('No router available for this application.'); | ||
| } | ||
|
|
||
| return new ContentRouter($application, $menu, $this->category, $this->db); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
| /** | ||
| * Joomla! Content Management System | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\CMS\Component\Router; | ||
|
|
||
| defined('_JEXEC') or die; | ||
|
|
||
| use Joomla\CMS\Application\CMSApplicationInterface; | ||
| use Joomla\CMS\Menu\AbstractMenu; | ||
|
|
||
| /** | ||
| * Router factory interface | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| interface RouterFactoryInterface | ||
| { | ||
| /** | ||
| * Creates a router. | ||
| * | ||
| * @param CMSApplicationInterface $application The application | ||
| * @param AbstractMenu $menu The menu object to work with | ||
| * | ||
| * @return RouterInterface | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function createRouter(CMSApplicationInterface $application, AbstractMenu $menu): RouterInterface; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
| /** | ||
| * Joomla! Content Management System | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\CMS\Component\Router; | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| use Joomla\CMS\Application\CMSApplicationInterface; | ||
| use Joomla\CMS\Menu\AbstractMenu; | ||
|
|
||
| /** | ||
| * The component router service. | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| interface RouterServiceInterface | ||
| { | ||
| /** | ||
| * Returns the router. | ||
| * | ||
| * @param CMSApplicationInterface $application The application object | ||
| * @param AbstractMenu $menu The menu object to work with | ||
| * | ||
| * @return RouterInterface | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function createRouter(CMSApplicationInterface $application, AbstractMenu $menu): RouterInterface; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly disagree with this here. 90% of the components out there don't have categories and also don't need DB access. Even if you could hand in dummy objects, this is wrong. Also, you are not handing in one category object, but an object to get any category from.
I would rather have something like a setDb() and setCategories() to fill this, than handing this over in the constructor. Or add this as an additional interface or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, now I see what you are doing here and my previous comment about category and db as parameters was wrong. But please rename $category to something else. It is not a single category that you get. On a side note: We should improve that part and name JCategories to something better...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did something into that direction with a new
CategoryInterfacehere https://github.com/joomla/joomla-cms/pull/20693/files#diff-d1bc8815185a7ce4f6b7cff706b71f48R18. Any comments are welcome.