Skip to content
This repository has been archived by the owner on Dec 9, 2017. It is now read-only.

Commit

Permalink
bug #3 Rewrite RequestUriProvider service (and Fix support for Symfon…
Browse files Browse the repository at this point in the history
…y 2.3) (sstok)

This PR was merged into the master branch.

Discussion
----------

|Q            |A  |
|---          |---|
|Bug Fix?     |yes|
|New Feature? |no |
|BC Breaks?   |yes|
|Deprecations?|no |
|Fixed Tickets|   |

The internal API is changed, but this not be used directly.

Commits
-------

175445c Rewrite RequestUriProvider service (and Fix support for Symfony 2.3)
  • Loading branch information
sstok committed Dec 6, 2015
2 parents 2208312 + 175445c commit 702c033
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 129 deletions.
10 changes: 3 additions & 7 deletions src/DependencyInjection/Compiler/RequestUriProviderPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Rollerworks\Bundle\DatagridBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -33,15 +34,10 @@ public function process(ContainerBuilder $container)

// Symfony >=2.4
if ($container->hasDefinition('request_stack') || $container->hasAlias('request_stack')) {
$definition->addArgument(new Reference('rollerworks_datagrid.request_uri_provider.request_stack'));

$container->removeDefinition('rollerworks_datagrid.request_uri_provider.request_service');
$container->removeDefinition('rollerworks_datagrid.event_subscriber.request');
$container->setAlias('rollerworks_datagrid.request_uri_provider', new Alias('rollerworks_datagrid.request_uri_provider.request_stack', false));
} else {
// Symfony 2.3
$definition->addArgument(new Reference('rollerworks_datagrid.request_uri_provider.request_service'));

$container->removeDefinition('rollerworks_datagrid.request_uri_provider.request_stack');
$container->setAlias('rollerworks_datagrid.request_uri_provider', new Alias('rollerworks_datagrid.request_uri_provider.request_service', false));
}
}
}
54 changes: 0 additions & 54 deletions src/Extension/Symfony/EventSubscriber/RequestSubscriber.php

This file was deleted.

44 changes: 0 additions & 44 deletions src/Extension/Symfony/RequestUriProviderByListener.php

This file was deleted.

32 changes: 32 additions & 0 deletions src/Extension/Symfony/RequestUriProviderByRequestService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the RollerworksDatagrid package.
*
* (c) Sebastiaan Stok <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Rollerworks\Bundle\DatagridBundle\Extension\Symfony;

use Symfony\Component\DependencyInjection\ContainerInterface;

class RequestUriProviderByRequestService implements RequestUriProviderInterface
{
private $container;

public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

/**
* @return string
*/
public function getRequestUri()
{
return $this->container->get('request')->getRequestUri();
}
}
8 changes: 4 additions & 4 deletions src/Resources/config/services/type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<service id="rollerworks_datagrid.column_extension.action" class="Rollerworks\Bundle\DatagridBundle\Extension\Symfony\ColumnTypeExtension\ActionTypeExtension">
<tag name="rollerworks_datagrid.column_extension" alias="action" />
<argument type="service" id="router" />
<argument type="service" id="rollerworks_datagrid.request_uri_provider" />

<!-- RequestUriProvider is set by RequestUriProviderPass -->
</service>

Expand All @@ -61,10 +63,8 @@
</service>

<!-- Symfony 2.3 -->
<service id="rollerworks_datagrid.request_uri_provider.request_service" class="Rollerworks\Bundle\DatagridBundle\Extension\Symfony\RequestUriProviderByListener" public="false" />
<service id="rollerworks_datagrid.event_subscriber.request" class="Rollerworks\Bundle\DatagridBundle\Extension\Symfony\EventSubscriber\RequestSubscriber">
<tag name="kernel.event_subscriber" />
<argument type="service" id="rollerworks_datagrid.request_uri_provider.request_service" />
<service id="rollerworks_datagrid.request_uri_provider.request_service" class="Rollerworks\Bundle\DatagridBundle\Extension\Symfony\RequestUriProviderByRequestService" public="false">
<argument type="service" id="service_container" />
</service>
</services>
</container>
20 changes: 6 additions & 14 deletions tests/DependencyInjection/Compiler/RequestUriProviderPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,20 @@ public function testSymfony23RequestListener()
{
$this->compile();

$this->assertContainerBuilderHasServiceDefinitionWithArgument(
'rollerworks_datagrid.column_extension.action',
1,
new Reference('rollerworks_datagrid.request_uri_provider.request_service')
$this->assertContainerBuilderHasAlias(
'rollerworks_datagrid.request_uri_provider',
'rollerworks_datagrid.request_uri_provider.request_service'
);

$this->assertFalse($this->container->hasDefinition('rollerworks_datagrid.request_uri_provider.request_stack'));
$this->assertContainerBuilderHasServiceDefinitionWithTag('rollerworks_datagrid.event_subscriber.request', 'kernel.event_subscriber');
}

public function testSymfony24AndHigherRequestStack()
{
$this->registerService('request_stack', 'stdClass');
$this->compile();

$this->assertFalse($this->container->hasDefinition('rollerworks_datagrid.request_uri_provider.request_service'));
$this->assertFalse($this->container->hasDefinition('rollerworks_datagrid.event_subscriber.request'));

$this->assertContainerBuilderHasServiceDefinitionWithArgument(
'rollerworks_datagrid.column_extension.action',
1,
new Reference('rollerworks_datagrid.request_uri_provider.request_stack')
$this->assertContainerBuilderHasAlias(
'rollerworks_datagrid.request_uri_provider',
'rollerworks_datagrid.request_uri_provider.request_stack'
);
}

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

namespace Rollerworks\Bundle\DatagridBundle\Tests\Extension\Symfony\ColumnTypeExtension;

use Prophecy\Argument;
use Rollerworks\Bundle\DatagridBundle\Extension\Symfony\ColumnTypeExtension\ActionTypeExtension;
use Rollerworks\Bundle\DatagridBundle\Extension\Symfony\RequestUriProviderInterface;
use Rollerworks\Component\Datagrid\PreloadedExtension;
Expand All @@ -22,37 +23,37 @@ class ActionTypeExtensionTest extends ColumnTypeTestCase
protected function getExtensions()
{
$urlGenerator = $this->prophesize(UrlGeneratorInterface::class);
$urlGenerator->generate('entity_edit', ['id' => 42], false)->will(
$urlGenerator->generate('entity_edit', ['id' => 42], Argument::any())->will(
function ($args) {
return '/entity/'.$args[1]['id'].'/edit';
}
);

$urlGenerator->generate('entity_edit', ['id' => 42], false)->will(
$urlGenerator->generate('entity_edit', ['id' => 42], Argument::any())->will(
function ($args) {
return '/entity/'.$args[1]['id'].'/edit';
}
);

$urlGenerator->generate('entity_edit', ['id' => 42, 'foo' => 'bar'], false)->will(
$urlGenerator->generate('entity_edit', ['id' => 42, 'foo' => 'bar'], Argument::any())->will(
function ($args) {
return '/entity/'.$args[1]['id'].'/edit?foo=bar';
}
);

$urlGenerator->generate('entity_delete', ['id' => 42], false)->will(
$urlGenerator->generate('entity_delete', ['id' => 42], Argument::any())->will(
function ($args) {
return '/entity/'.$args[1]['id'].'/delete';
}
);

$urlGenerator->generate('entity_list', [], false)->will(
$urlGenerator->generate('entity_list', [], Argument::any())->will(
function () {
return '/entity/list';
}
);

$urlGenerator->generate('entity_list', ['filter' => 'something', 'user' => 'sheldon'], false)->will(
$urlGenerator->generate('entity_list', ['filter' => 'something', 'user' => 'sheldon'], Argument::any())->will(
function () {
return '/list/?user=sheldon&filter=something';
}
Expand Down

0 comments on commit 702c033

Please sign in to comment.