Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
/phpunit.xml
/vendor/
/var/
/config/reference.php
/.phpunit.result.cache
/.php-cs-fixer.cache
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
}
],
"require": {
"php": ">=8.0",
"doctrine/doctrine-bundle": "^2.6",
"php": ">=8.1",
"doctrine/doctrine-bundle": "^2.6|^3.0",
"doctrine/orm": "^2.6|^3.0",
"symfony/framework-bundle": "^5.4|^6.0|^7.0"
"symfony/framework-bundle": "^6.4|^7.0|^8.0"
},
"require-dev": {
"matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.0",
"symfony/browser-kit": "^5.4|^6.0|^7.0",
"symfony/form": "^5.4|^6.0|^7.0",
"symfony/phpunit-bridge": "^6.0|^7.0",
"symfony/translation": "^5.4|^6.0|^7.0",
"symfony/validator": "^5.4|^6.0|^7.0",
"zenstruck/foundry": "^1.38.3",
"matthiasnoback/symfony-dependency-injection-test": "^4.3|^5.0",
"symfony/browser-kit": "^6.4|^7.0|^8.0",
"symfony/form": "^6.4|^7.0|^8.0",
"symfony/phpunit-bridge": "^7.4",
"symfony/translation": "^6.4|^7.0|^8.0",
"symfony/validator": "^6.4|^7.0|^8.0",
"zenstruck/foundry": "^2.8.1",
"phpunit/phpunit": "9.6.13",
"zenstruck/browser": "^1.6"
},
Expand Down
12 changes: 12 additions & 0 deletions config/form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Zenstruck\RedirectBundle\Form\Type\RedirectType;

return static function (ContainerConfigurator $container) {
$container->services()
->set('zenstruck_redirect.redirect.form.type', RedirectType::class)
->args(['%zenstruck_redirect.redirect_class%'])
->tag('form.type', ['alias' => 'zenstruck_redirect']);
};
13 changes: 0 additions & 13 deletions config/form.xml

This file was deleted.

25 changes: 25 additions & 0 deletions config/not_found.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Zenstruck\RedirectBundle\EventListener\CreateNotFoundListener;
use Zenstruck\RedirectBundle\Service\NotFoundManager;

return static function (ContainerConfigurator $container) {
$container->parameters()
->set('zenstruck_redirect.not_found_manager.class', NotFoundManager::class)
->set('zenstruck_redirect.not_found_listener.class', CreateNotFoundListener::class)
;

$container->services()
->set('zenstruck_redirect.not_found_manager', '%zenstruck_redirect.not_found_manager.class%')
->public()
->args([
'%zenstruck_redirect.not_found_class%',
service('zenstruck_redirect.entity_manager'),
])
->set('zenstruck_redirect.not_found_listener', '%zenstruck_redirect.not_found_listener.class%')
->args([service('zenstruck_redirect.not_found_manager')])
->tag('kernel.event_listener', ['event' => 'kernel.exception', 'method' => 'onKernelException'])
;
};
23 changes: 0 additions & 23 deletions config/not_found.xml

This file was deleted.

24 changes: 24 additions & 0 deletions config/redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Zenstruck\RedirectBundle\EventListener\RedirectOnNotFoundListener;
use Zenstruck\RedirectBundle\Service\RedirectManager;

return static function (ContainerConfigurator $container) {
$container->parameters()
->set('zenstruck_redirect.redirect_manager.class', RedirectManager::class)
->set('zenstruck_redirect.redirect_listener.class', RedirectOnNotFoundListener::class)
;

$container->services()
->set('zenstruck_redirect.redirect_manager', '%zenstruck_redirect.redirect_manager.class%')
->args([
'%zenstruck_redirect.redirect_class%',
service('zenstruck_redirect.entity_manager'),
])
->set('zenstruck_redirect.redirect_listener', '%zenstruck_redirect.redirect_listener.class%')
->args([service('zenstruck_redirect.redirect_manager')])
->tag('kernel.event_listener', ['event' => 'kernel.exception', 'method' => 'onKernelException', 'priority' => 10])
;
};
23 changes: 0 additions & 23 deletions config/redirect.xml

This file was deleted.

16 changes: 16 additions & 0 deletions config/remove_not_found_subscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Zenstruck\RedirectBundle\EventListener\Doctrine\RemoveNotFoundSubscriber;

return static function (ContainerConfigurator $container) {
$container->parameters()
->set('zenstruck_redirect.remove_not_found_subscriber.class', RemoveNotFoundSubscriber::class);

$container->services()
->set('zenstruck_redirect.remove_not_found_subscriber', '%zenstruck_redirect.remove_not_found_subscriber.class%')
->args([service('service_container')])
->tag('doctrine.event_listener', ['event' => 'postPersist'])
->tag('doctrine.event_listener', ['event' => 'postUpdate']);
};
14 changes: 0 additions & 14 deletions config/remove_not_found_subscriber.xml

This file was deleted.

10 changes: 5 additions & 5 deletions src/DependencyInjection/ZenstruckRedirectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
throw new InvalidConfigurationException('A "redirect_class" or "not_found_class" must be set for "zenstruck_redirect".');
}

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$modelManagerName = $mergedConfig['model_manager_name'] ?: 'default';

$container->setAlias('zenstruck_redirect.entity_manager', \sprintf('doctrine.orm.%s_entity_manager', $modelManagerName));

if (null !== $mergedConfig['redirect_class']) {
$container->setParameter('zenstruck_redirect.redirect_class', $mergedConfig['redirect_class']);

$loader->load('redirect.xml');
$loader->load('form.xml');
$loader->load('redirect.php');
$loader->load('form.php');
}

if (null !== $mergedConfig['not_found_class']) {
$container->setParameter('zenstruck_redirect.not_found_class', $mergedConfig['not_found_class']);

$loader->load('not_found.xml');
$loader->load('not_found.php');
}

if ($mergedConfig['remove_not_founds'] && null !== $mergedConfig['not_found_class'] && null !== $mergedConfig['redirect_class']) {
$loader->load('remove_not_found_subscriber.xml');
$loader->load('remove_not_found_subscriber.php');
}
}
}
10 changes: 5 additions & 5 deletions tests/Fixture/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
'test' => true,
]);

$c->loadFromExtension('zenstruck_foundry', [
'auto_refresh_proxies' => true,
]);
if (\PHP_VERSION_ID >= 80400) {
$c->loadFromExtension('zenstruck_foundry', [
'enable_auto_refresh_with_lazy_objects' => true,
]);
}

$c->loadFromExtension('zenstruck_redirect', [
'redirect_class' => DummyRedirect::class,
Expand All @@ -72,8 +74,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
$c->loadFromExtension('doctrine', [
'dbal' => ['url' => '%env(resolve:DATABASE_URL)%'],
'orm' => [
'auto_generate_proxy_classes' => true,
'auto_mapping' => true,
'mappings' => [
'Entity' => [
'is_bundle' => false,
Expand Down
17 changes: 14 additions & 3 deletions tests/Functional/RedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
use Zenstruck\Browser\Test\HasBrowser;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
use Zenstruck\RedirectBundle\Model\Redirect;
use Zenstruck\RedirectBundle\Tests\Fixture\Entity\DummyRedirect;

use function Zenstruck\Foundry\Persistence\persist_proxy;
use function Zenstruck\Foundry\Persistence\persist;
use function Zenstruck\Foundry\Persistence\proxy_factory;

/**
* @author Kevin Bond <kevinbond@gmail.com>
Expand All @@ -31,7 +33,7 @@ final class RedirectTest extends KernelTestCase
*/
public function permanent_redirect(): void
{
$redirect = persist_proxy(DummyRedirect::class, ['source' => '/301-redirect', 'destination' => '/']);
$redirect = $this->persist(DummyRedirect::class, ['source' => '/301-redirect', 'destination' => '/']);
$browser = $this->browser()->interceptRedirects();

$this->assertSame(0, $redirect->getCount());
Expand All @@ -56,7 +58,7 @@ public function permanent_redirect(): void
*/
public function temporary_redirect(): void
{
$redirect = persist_proxy(DummyRedirect::class, [
$redirect = $this->persist(DummyRedirect::class, [
'source' => '/302-redirect',
'destination' => '/',
'permanent' => false,
Expand All @@ -70,4 +72,13 @@ public function temporary_redirect(): void
;
$this->assertSame(1, $redirect->getCount());
}

private function persist(string $class, array $parameters): Redirect
{
if (\PHP_VERSION_ID >= 80400) {
return persist($class, $parameters);
}

return proxy_factory($class)->create($parameters);
}
}
7 changes: 4 additions & 3 deletions tests/Functional/RemoveNotFoundSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use Zenstruck\RedirectBundle\Tests\Fixture\Entity\DummyRedirect;

use function Zenstruck\Foundry\Persistence\persist;
use function Zenstruck\Foundry\Persistence\persist_proxy;
use function Zenstruck\Foundry\Persistence\repository;
use function Zenstruck\Foundry\Persistence\save;

/**
* @author Kevin Bond <kevinbond@gmail.com>
Expand Down Expand Up @@ -56,12 +56,13 @@ public function delete_not_found_on_update_redirect(): void

persist(DummyNotFound::class, ['path' => '/foo', 'fullUrl' => '/foo']);

$redirect = persist_proxy(DummyRedirect::class, ['source' => '/baz', 'destination' => '/bar']);
$redirect = persist(DummyRedirect::class, ['source' => '/baz', 'destination' => '/bar']);

$notFoundRepo->assert()->count(1);

$redirect->setSource('/foo');
$redirect->_save();

save($redirect);

$notFoundRepo->assert()->empty();
}
Expand Down
Loading