Information Required ? Pending

User tests: Successful: Unsuccessful:

avatar sakiss
sakiss
27 Oct 2020

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 Router

Actual 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

avatar sakiss sakiss - open - 27 Oct 2020
avatar sakiss sakiss - change - 27 Oct 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 27 Oct 2020
Category Libraries
avatar sakiss sakiss - change - 27 Oct 2020
The description was changed
avatar sakiss sakiss - edited - 27 Oct 2020
avatar sakiss sakiss - change - 27 Oct 2020
The description was changed
avatar sakiss sakiss - edited - 27 Oct 2020
avatar sakiss sakiss - change - 27 Oct 2020
Title
protected $_router
[4.0] protected $_router instead of private
avatar sakiss sakiss - edited - 27 Oct 2020
avatar HLeithner
HLeithner - comment - 27 Oct 2020

Can you give me an example what you want to achieve?

avatar sakiss
sakiss - comment - 27 Oct 2020

@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.

avatar HLeithner
HLeithner - comment - 27 Oct 2020

Maybe I'm wrong but wouldn't it be easier to add a preprocessor?

avatar sakiss
sakiss - comment - 27 Oct 2020

@HLeithner Thanks for the suggestion.
Any idea on how this can be implemented?

avatar HLeithner
HLeithner - comment - 27 Oct 2020

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 */
}

}
avatar sakiss
sakiss - comment - 29 Oct 2020

@HLeithner Thank you!
The actual problem is in the Uri class, hence it requires more than adding rules.

In any case i think that providing the ability to set our own Router could add extra flexibility.

avatar HLeithner
HLeithner - comment - 29 Oct 2020

Can you send me the code you want to use in your router if this variable is not private?

avatar sakiss
sakiss - comment - 29 Oct 2020

I am overwriting the Router::createUri by calling my own Uri class within that fn.

avatar dgrammatiko
dgrammatiko - comment - 29 Oct 2020

@sakiss if you're essentially overriding the Uri class probably you should consider doing it like the example here: #19842

avatar sakiss
sakiss - comment - 30 Oct 2020

@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).

avatar sakiss sakiss - change - 6 Nov 2020
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2020-11-06 15:08:36
Closed_By sakiss
Labels Added: Information Required ?
avatar sakiss sakiss - close - 6 Nov 2020

Add a Comment

Login with GitHub to post a comment