Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

POC for defunct route options #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions ConfigurableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Component\RoutingAuto;

/**
* This interface should be implemented by classes which
* need to configure options.
*
* @author Daniel Leech <[email protected]>
*/
interface ConfigurableInterface
{
/**
* Configure the options for this token provider
*
* @param OptionsResolverInterface $optionsResolver
*/
public function configureOptions(OptionsResolverInterface $optionsResolver);
}
Empty file.
15 changes: 13 additions & 2 deletions DefunctRouteHandler/DelegatingDefunctRouteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Symfony\Cmf\Component\RoutingAuto\ServiceRegistry;
use Symfony\Cmf\Component\RoutingAuto\DefunctRouteHandlerInterface;
use Symfony\Cmf\Component\RoutingAuto\UriContextCollection;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Cmf\Component\RoutingAuto\ConfigurableInterface;

/**
* Defunct route handler which delegates the handling of
Expand Down Expand Up @@ -48,7 +50,7 @@ public function __construct(
/**
* {@inheritDoc}
*/
public function handleDefunctRoutes(UriContextCollection $uriContextCollection)
public function handleDefunctRoutes(UriContextCollection $uriContextCollection, array $options = array())
{
$subject = $uriContextCollection->getSubjectObject();
$realClassName = $this->adapter->getRealClassName(get_class($uriContextCollection->getSubjectObject()));
Expand All @@ -57,6 +59,15 @@ public function handleDefunctRoutes(UriContextCollection $uriContextCollection)
$defunctRouteHandlerConfig = $metadata->getDefunctRouteHandler();

$defunctHandler = $this->serviceRegistry->getDefunctRouteHandler($defunctRouteHandlerConfig['name']);
$defunctHandler->handleDefunctRoutes($uriContextCollection);

$options = array();

if ($defunctHandler instanceof ConfigurableInterface) {
$optionsResolver = new OptionsResolver();
$defunctHandler->configureOptions($optionsResolver);
$options = $optionsResolver->resolve($defunctRouteHandlerConfig['options']);
}

$defunctHandler->handleDefunctRoutes($uriContextCollection, $options);
}
}
16 changes: 13 additions & 3 deletions DefunctRouteHandler/LeaveRedirectDefunctRouteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Component\RoutingAuto\DefunctRouteHandler;

use Symfony\Cmf\Component\RoutingAuto\DefunctRouteHandlerInterface;
use Symfony\Cmf\Component\RoutingAuto\UriContextCollection;
use Symfony\Cmf\Component\RoutingAuto\AdapterInterface;

class LeaveRedirectDefunctRouteHandler implements DefunctRouteHandlerInterface
class LeaveRedirectDefunctRouteHandler implements DefunctRouteHandlerInterface, ConfigurableInterface
{
/**
* @var AdapterInterface
*/
protected $adapter;

/**
* @param AdapterInterface $adapter
*/
public function __construct(AdapterInterface $adapter)
{
$this->adapter = $adapter;
Expand All @@ -31,7 +33,15 @@ public function __construct(AdapterInterface $adapter)
/**
* {@inheritDoc}
*/
public function handleDefunctRoutes(UriContextCollection $uriContextCollection)
public function configureOptions(OptionsResolverInterface $optionsResolver)
{
$optionsResolver->setDefault('http_code', 301);
}

/**
* {@inheritDoc}
*/
public function handleDefunctRoutes(UriContextCollection $uriContextCollection, array $options = array())
{
$referringAutoRouteCollection = $this->adapter->getReferringAutoRoutes($uriContextCollection->getSubjectObject());

Expand Down
2 changes: 1 addition & 1 deletion DefunctRouteHandler/RemoveDefunctRouteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(AdapterInterface $adapter)
/**
* {@inheritDoc}
*/
public function handleDefunctRoutes(UriContextCollection $uriContextCollection)
public function handleDefunctRoutes(UriContextCollection $uriContextCollection, array $options = array())
{
$referringAutoRouteCollection = $this->adapter->getReferringAutoRoutes($uriContextCollection->getSubjectObject());

Expand Down
7 changes: 5 additions & 2 deletions DefunctRouteHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Symfony\Cmf\Component\RoutingAuto;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* @author Daniel Leech <[email protected]>
*/
Expand All @@ -28,7 +30,8 @@ interface DefunctRouteHandlerInterface
* or perhaps replaced with a redirect route, or indeed
* left alone to continue depending on the configuration.
*
* TODO
* @param UriContextCollection $uriContextCollection
* @param array $options
*/
public function handleDefunctRoutes(UriContextCollection $uriContextCollection);
public function handleDefunctRoutes(UriContextCollection $uriContextCollection, array $options = array());
}
9 changes: 1 addition & 8 deletions TokenProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Symfony\Component\OptionsResolver\OptionsResolverInterface;

interface TokenProviderInterface
interface TokenProviderInterface extends ConfigurableInterface
{
/**
* Return a token value for the given configuration and
Expand All @@ -26,11 +26,4 @@ interface TokenProviderInterface
* @return string
*/
public function provideValue(UriContext $uriContext, $options);

/**
* Configure the options for this token provider
*
* @param OptionsResolverInterface $optionsResolver
*/
public function configureOptions(OptionsResolverInterface $optionsResolver);
}