Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RouteCollectionInterface #6699

Merged
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
38 changes: 38 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
UPGRADE 3.x
===========

UPGRADE FROM 3.xx to 3.xx
=========================

### `RouteCollection` now implements `RouteCollectionInterface`

In 4.0, `AbstractAdmin::configureRoutes` and `AdminExtensionInterface::configureRoutes` will receive a
`RouteCollectionInterface` instance instead of a `RouteCollection` instance, you can update your code before ugprading
to 4.0.

Before:
```php
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Route\RouteCollection;

final class MyAdmin extends AbstractAdmin
{
protected function configureRoutes(RouteCollection $collection): void
{
$collection->add('my_route');
}
}
```

After:
```php
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Route\RouteCollectionInterface;

final class MyAdmin extends AbstractAdmin
{
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection->add('my_route');
}
}
```
This only will work with PHP >= 7.4, where fully support to contravariance was added.

### Sonata\AdminBundle\Admin\BaseFieldDescription

Method `__construct()` has been updated to receive the field name as argument 6:
Expand Down
2 changes: 1 addition & 1 deletion src/Route/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Thomas Rabaix <[email protected]>
*/
class RouteCollection
class RouteCollection implements RouteCollectionInterface
{
/**
* @var array<string, Route|callable():Route>
Expand Down
130 changes: 130 additions & 0 deletions src/Route/RouteCollectionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\AdminBundle\Route;

use Symfony\Component\Routing\Route;

/**
* @author Jordi Sala <[email protected]>
*/
interface RouteCollectionInterface
{
/**
* @param string $name
* @param string $pattern Pattern (will be automatically combined with @see $this->baseRoutePattern and $name
* @param string $host
* @param string $condition
*
* @return RouteCollection
*/
public function add(
$name,
$pattern = null,
array $defaults = [],
array $requirements = [],
array $options = [],
$host = '',
array $schemes = [],
array $methods = [],
$condition = ''
);

/**
* @return string
*/
public function getCode(string $name);

/**
* @return $this
*/
public function addCollection(RouteCollection $collection);

/**
* @return Route[]
*/
public function getElements();

/**
* @param string $name
*
* @return bool
*/
public function has($name);

public function hasCached(string $name): bool;

/**
* @param string $name
*
* @throws \InvalidArgumentException
*
* @return Route
*/
public function get($name);

/**
* @return $this
*/
public function remove(string $name);

/**
* @throws \InvalidArgumentException
*
* @return $this
*/
public function restore(string $name);

/**
* Remove all routes except routes in $routeList.
*
* @param string[]|string $routeList
*
* @return $this
*/
public function clearExcept($routeList);

/**
* @return $this
*/
public function clear();

/**
* Converts a word into the format required for a controller action. By instance,
* the argument "list_something" returns "listSomething" if the associated controller is not an action itself,
* otherwise, it will return "listSomethingAction".
*
* @return string
*/
public function actionify(string $action);

/**
* @return string
*/
public function getBaseCodeRoute();

/**
* @return string
*/
public function getBaseControllerName();

/**
* @return string
*/
public function getBaseRouteName();

/**
* @return string
*/
public function getBaseRoutePattern();
}