Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Deprecate bundle:controller:action and service:method notation #26085

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
replace single colon syntax also for service router loader
  • Loading branch information
Tobion committed Feb 19, 2018
commit 067a0d8a4054627874ea173d49a986fc427ec742
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
$loader->load(function (ContainerBuilder $container) use ($loader) {
$container->loadFromExtension('framework', array(
'router' => array(
'resource' => 'kernel:loadRoutes',
'resource' => 'kernel::loadRoutes',
'type' => 'service',
),
));
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"symfony/polyfill-mbstring": "~1.0",
"symfony/filesystem": "~3.4|~4.0",
"symfony/finder": "~3.4|~4.0",
"symfony/routing": "^3.4.5|^4.0.5"
"symfony/routing": "^4.1"
},
"require-dev": {
"doctrine/cache": "~1.0",
Expand Down
14 changes: 11 additions & 3 deletions 14 src/Symfony/Component/Routing/Loader/ObjectRouteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ abstract protected function getServiceObject($id);
*/
public function load($resource, $type = null)
{
$parts = explode(':', $resource);
if (1 === substr_count($resource, ':')) {
$resource = str_replace(':', '::', $resource);
@trigger_error(sprintf(
'Referencing service route loaders with a single colon is deprecated since version 4.1 and will be removed in 5.0. Use %s instead.',
$resource
), E_USER_DEPRECATED);
}

$parts = explode('::', $resource);
if (2 != count($parts)) {
throw new \InvalidArgumentException(sprintf('Invalid resource "%s" passed to the "service" route loader: use the format "service_name:methodName"', $resource));
throw new \InvalidArgumentException(sprintf('Invalid resource "%s" passed to the "service" route loader: use the format "service::method"', $resource));
}

$serviceString = $parts[0];
Expand All @@ -58,7 +66,7 @@ public function load($resource, $type = null)
throw new \LogicException(sprintf('%s:getServiceObject() must return an object: %s returned', get_class($this), gettype($loaderObject)));
}

if (!method_exists($loaderObject, $method)) {
if (!is_callable(array($loaderObject, $method))) {
throw new \BadMethodCallException(sprintf('Method "%s" not found on "%s" when importing routing resource "%s"', $method, get_class($loaderObject), $resource));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

class ObjectRouteLoaderTest extends TestCase
{
public function testLoadCallsServiceAndReturnsCollection()
/**
* @group legacy
* @expectedDeprecation Referencing service route loaders with a single colon is deprecated since version 4.1 and will be removed in 5.0. Use my_route_provider_service::loadRoutes instead.
*/
public function testLoadCallsServiceAndReturnsCollectionWithLegacyNotation()
{
$loader = new ObjectRouteLoaderForTest();

Expand All @@ -40,6 +44,28 @@ public function testLoadCallsServiceAndReturnsCollection()
$this->assertNotEmpty($actualRoutes->getResources());
}

public function testLoadCallsServiceAndReturnsCollection()
{
$loader = new ObjectRouteLoaderForTest();

// create a basic collection that will be returned
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo'));

$loader->loaderMap = array(
'my_route_provider_service' => new RouteService($collection),
);

$actualRoutes = $loader->load(
'my_route_provider_service::loadRoutes',
'service'
);

$this->assertSame($collection, $actualRoutes);
// the service file should be listed as a resource
$this->assertNotEmpty($actualRoutes->getResources());
}

/**
* @expectedException \InvalidArgumentException
* @dataProvider getBadResourceStrings
Expand All @@ -54,7 +80,6 @@ public function getBadResourceStrings()
{
return array(
array('Foo'),
array('Bar::baz'),
array('Foo:Bar:baz'),
);
}
Expand All @@ -66,7 +91,7 @@ public function testExceptionOnNoObjectReturned()
{
$loader = new ObjectRouteLoaderForTest();
$loader->loaderMap = array('my_service' => 'NOT_AN_OBJECT');
$loader->load('my_service:method');
$loader->load('my_service::method');
}

/**
Expand All @@ -76,7 +101,7 @@ public function testExceptionOnBadMethod()
{
$loader = new ObjectRouteLoaderForTest();
$loader->loaderMap = array('my_service' => new \stdClass());
$loader->load('my_service:method');
$loader->load('my_service::method');
}

/**
Expand All @@ -93,7 +118,7 @@ public function testExceptionOnMethodNotReturningCollection()

$loader = new ObjectRouteLoaderForTest();
$loader->loaderMap = array('my_service' => $service);
$loader->load('my_service:loadRoutes');
$loader->load('my_service::loadRoutes');
}
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.