Skip to content

Commit

Permalink
Add url option to the core:route command (#5172)
Browse files Browse the repository at this point in the history
* Add url option to the core:route command

* Add usage

* Enhance path processing to support URLs

* Fix spacing
  • Loading branch information
Chi-teck committed Jul 1, 2022
1 parent 9b06c2d commit 36924fa
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Drupal/Commands/core/DrupalCommands.php
Expand Up @@ -145,15 +145,22 @@ public function requirements($options = ['format' => 'table', 'severity' => -1,
* View details about the <info>update.status</info> route.
* @usage drush route --path=/user/1
* View details about the <info>entity.user.canonical</info> route.
* @usage drush route --url=https://example.com/node/1
* View details about the <info>entity.node.canonical</info> route.
* @option name A route name.
* @option path An internal path.
* @option path An internal path or URL.
* @version 10.5
*/
public function route($options = ['name' => self::REQ, 'path' => self::REQ, 'format' => 'yaml'])
{
$route = $items = null;
$provider = $this->getRouteProvider();
if ($path = $options['path']) {
if (filter_var($path, FILTER_VALIDATE_URL)) {
$path = parse_url($path, PHP_URL_PATH);
// Strip base path.
$path = '/' . substr_replace($path, '', 0, strlen(base_path()));
}
$name = Url::fromUserInput($path)->getRouteName();
$route = $provider->getRouteByName($name);
} elseif ($name = $options['name']) {
Expand Down

0 comments on commit 36924fa

Please sign in to comment.