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
[4.0] protected $_router instead of private #31251
Conversation
Can you give me an example what you want to achieve? |
@HLeithner In my case i want to override the Router::createUri, in order to encode the special characters included in the url's query vars. But i think that can be used in a more broad way e.g. set validation and escape rules. |
Maybe I'm wrong but wouldn't it be easier to add a preprocessor? |
@HLeithner Thanks for the suggestion. |
Create a plugin and add a buildRule in the onAfterInitialise event. somehing like this: class plgSystemMyRouterExtgension extends JPlugin {
public function onAfterInitialise() {
$app = JFactory::getApplication();
if ($app->isSite()) {
$router = $app->getRouter();
// attach build rules for translation on SEF
$router->attachBuildRule(array($this, 'buildRule'), JRouter::PROCESS_BEFORE);
}
}
public function buildRule(&$router, &$uri) {
/* modify $uri here */
}
} |
@HLeithner Thank you! In any case i think that providing the ability to set our own Router could add extra flexibility. |
Can you send me the code you want to use in your router if this variable is not private? |
I am overwriting the |
@dgrammatiko Valid. The only reason i don't like that, is that is sets an object in the container which will be used globally. I prefer having something with limited scope. But i understand the point that the same class should be used on input and output (build/parse). |
Summary of Changes
Set the
$_router
variable as protected instead of private in the class:Joomla\CMS\Router\Route
By doing that we can extend the Route class and define our own Router in that.
This way we can provide additional functionalities in our Router.
Testing Instructions
It can only be tested by extending the
Joomla\CMS\Router\Route
and defining our own RouterActual result BEFORE applying this Pull Request
No Router can be defined in sub-classes.
Expected result AFTER applying this Pull Request
You can define your own Router in sub-classes.
Documentation Changes Required
DKN