Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Controller/RoutingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function __construct(RoutingExtractor $extractor, SerializerInterface $se
/**
* Return the exposed routes as JSON
* This method does not have a route and is called directly from the twig template
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function routingData(): JsonResponse
{
Expand Down
15 changes: 12 additions & 3 deletions DependencyInjection/XactJSRoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@

class XactJSRoutingExtension extends Extension implements PrependExtensionInterface
{
public function load(array $configs, ContainerBuilder $container)
/**
* Load the DI configuration
*
* @param mixed[] $configs
*
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');
}

public function prepend(ContainerBuilder $container)
/**
* Prepend the twig configuration with @XactJSRouting for accessing the template
*/
public function prepend(ContainerBuilder $container): void
{
$fileSystem = new Filesystem();
$projectDir = $container->getParameter('kernel.project_dir');
Expand All @@ -28,4 +38,3 @@ public function prepend(ContainerBuilder $container)
$container->prependExtensionConfig('twig', $twigConfig);
}
}

48 changes: 24 additions & 24 deletions Extractor/ExtractedRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@
class ExtractedRoute
{
/**
* @var array
* @var string[]
*/
private $tokens;
/**
* @var array
* @var string[]
*/
private $defaults;
/**
* @var array
* @var string[]
*/
private $requirements;
/**
* @var array
* @var string[]
*/
private $hosttokens;
/**
* @var array
* @var string[]
*/
private $methods;
/**
* @var array
* @var string[]
*/
private $schemes;

/**
* Constructor
*
* @param array $tokens
* @param array $defaults
* @param array $requirements
* @param array $hosttokens
* @param array $methods
* @param array $schemes
* @param string[] $tokens
* @param string[] $defaults
* @param string[] $requirements
* @param string[] $hosttokens
* @param string[] $methods
* @param string[] $schemes
*/
public function __construct(array $tokens, array $defaults, array $requirements, array $hosttokens = [], array $methods = [], array $schemes = [])
{
Expand All @@ -60,59 +60,59 @@ public function __construct(array $tokens, array $defaults, array $requirements,
/**
* Return the route tokens
*
* @return array
* @return string[]
*/
public function getTokens()
public function getTokens(): array
{
return $this->tokens;
}

/**
* Return the route defaults
*
* @return array
* @return string[]
*/
public function getDefaults()
public function getDefaults(): array
{
return $this->defaults;
}

/**
* Return the route requirements
*
* @return array
* @return string[]
*/
public function getRequirements()
public function getRequirements(): array
{
return $this->requirements;
}

/**
* Return the route host tokens
*
* @return array
* @return string[]
*/
public function getHosttokens()
public function getHosttokens(): array
{
return $this->hosttokens;
}

/**
* Return the route methods
*
* @return array
* @return string[]
*/
public function getMethods()
public function getMethods(): array
{
return $this->methods;
}

/**
* Return the route schemes
*
* @return array
* @return string[]
*/
public function getSchemes()
public function getSchemes(): array
{
return $this->schemes;
}
Expand Down
33 changes: 12 additions & 21 deletions Extractor/RoutingExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ class RoutingExtractor
/**
* Default constructor.
*
* @param RouterInterface $router
* @param string $cacheDir
* @param string $appEnv
* @param array $routesToExpose
* @param object[] $routesToExpose
*/
public function __construct(RouterInterface $router, $cacheDir, $appEnv, array $routesToExpose = [])
public function __construct(RouterInterface $router, string $cacheDir, string $appEnv, array $routesToExpose = [])
{
$this->router = $router;
$this->routesToExpose = $routesToExpose;
Expand All @@ -59,7 +56,7 @@ public function getRoutes()
$compiledRoute = $route->compile();
$defaults = array_intersect_key(
$route->getDefaults(),
array_fill_keys($compiledRoute->getVariables(), NULL)
array_fill_keys($compiledRoute->getVariables(), null)
);
$requirements = $route->getRequirements();
$hostTokens = method_exists($compiledRoute, 'getHostTokens') ? $compiledRoute->getHostTokens() : [];
Expand All @@ -86,12 +83,14 @@ public function getExposedRoutes()
$pattern = $this->buildPattern();

foreach ($collection->all() as $name => $route) {
if (FALSE === $route->getOption('expose')) {
if (false === $route->getOption('expose')) {
continue;
}

if (($route->getOption('expose') && (TRUE === $route->getOption('expose') || 'true' === $route->getOption('expose')))
|| ('' !== $pattern && preg_match('#' . $pattern . '#', $name))) {
if (
($route->getOption('expose') && (true === $route->getOption('expose') || 'true' === $route->getOption('expose')))
|| ('' !== $pattern && preg_match('#' . $pattern . '#', $name))
) {
$routes[$name] = $route;
}
}
Expand Down Expand Up @@ -126,10 +125,8 @@ public function getHost()

/**
* Check whether server is serving this request from a non-standard port.
*
* @return bool
*/
protected function usesNonStandardPort()
protected function usesNonStandardPort(): bool
{
return $this->usesNonStandardHttpPort() || $this->usesNonStandardHttpsPort();
}
Expand Down Expand Up @@ -167,10 +164,8 @@ public function getResources()

/**
* Convert the routesToExpose array in a regular expression pattern.
*
* @return string
*/
protected function buildPattern()
protected function buildPattern(): string
{
$patterns = [];
foreach ($this->routesToExpose as $toExpose) {
Expand All @@ -182,20 +177,16 @@ protected function buildPattern()

/**
* Checks whether server is serving HTTP over a non-standard port.
*
* @return bool
*/
private function usesNonStandardHttpPort()
private function usesNonStandardHttpPort(): bool
{
return 'http' === $this->getScheme() && '80' != $this->router->getContext()->getHttpPort();
}

/**
* Checks whether server is serving HTTPS over a non-standard port.
*
* @return bool
*/
private function usesNonStandardHttpsPort()
private function usesNonStandardHttpsPort(): bool
{
return 'https' === $this->getScheme() && '443' != $this->router->getContext()->getHttpsPort();
}
Expand Down