Last active
August 29, 2015 14:11
-
-
Save bdunogier/7aebb1088a01596bee6c to your computer and use it in GitHub Desktop.
This file contains 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
$ php app/console bdtest:match-uri /Getting-Started/Selected-Features/Create | |
# Router | |
route: ez_urlalias | |
controller: ez_content:viewContent | |
arguments: | |
- contentId: 69 | |
- locationId: 71 | |
- viewType: full | |
- layout: 1 | |
# URL ALias | |
Type: location URL Alias | |
ContentId: 69, LocationId: 71 | |
# ContentView | |
template: eZDemoBundle:full:article.html.twig | |
controller: eZDemoBundle:Demo:showArticle |
This file contains 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
<?php | |
namespace BD\Bundle\TestBundle\Command; | |
use eZ\Publish\API\Repository\Values\Content\URLAlias; | |
use eZ\Publish\Core\MVC\Symfony\View\ContentViewInterface; | |
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpKernel\Controller\ControllerReference; | |
class MatchUriCommand extends ContainerAwareCommand | |
{ | |
protected function configure() | |
{ | |
$this->setName( 'bdtest:match-uri' ); | |
$this->addArgument( 'uri', InputArgument::REQUIRED, 'A valid URL alias, e.g. /Folder/An-article' ); | |
} | |
protected function execute( InputInterface $input, OutputInterface $output ) | |
{ | |
$uri = $input->getArgument( 'uri' ); | |
$container = $this->getContainer(); | |
$urlAliasService = $container->get( 'ezpublish.api.service.url_alias' ); | |
$urlAlias = $urlAliasService->lookup( $uri ); | |
$output->writeln( "# Router" ); | |
$router = $container->get( 'ezpublish.urlalias_router' ); | |
$route = $router->matchRequest( Request::create( $uri, 'GET' ) ); | |
$output->writeln( "route: " . $route['_route'] ); | |
$output->writeln( "controller: " . $route['_controller'] ); | |
$output->writeln( "arguments: " ); | |
unset( $route['_controller'], $route['_route'] ); | |
foreach ( $route as $argumentName => $argumentValue ) | |
{ | |
$output->writeln( "- $argumentName: $argumentValue" ); | |
} | |
$output->writeln( "" ); | |
$output->writeln( "# URL ALias" ); | |
if ( $urlAlias->type === URLAlias::LOCATION ) | |
{ | |
$output->writeln( "Type: location URL Alias" ); | |
$output->writeln( "ContentId: $urlAlias->destinationContentId, LocationId: $urlAlias->destination" ); | |
} | |
$output->writeln( "" ); | |
$output->writeln( "# ContentView" ); | |
$viewManager = $container->get( 'ezpublish.view_manager' ); | |
$contentInfo = $container->get( 'ezpublish.api.service.content' )->loadContentInfo( | |
$urlAlias->destinationContentId | |
); | |
foreach ( $viewManager->getAllContentViewProviders() as $viewProvider ) | |
{ | |
$view = $viewProvider->getView( $contentInfo, 'full' ); | |
if ( $view instanceof ContentViewInterface ) | |
{ | |
$output->writeln( "template: " . $view->getTemplateIdentifier() ); | |
break; | |
} | |
} | |
$controllerReference = $container->get( 'ezpublish.controller_manager' )->getControllerReference( | |
$contentInfo, | |
'full' | |
); | |
if ( $controllerReference instanceof ControllerReference ) | |
{ | |
$output->writeln( "controller: " . $controllerReference->controller ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment