Skip to content

Commit 200cc14

Browse files
committed
feat: add Symfony 8 support
Widen Symfony version constraints in composer.json to allow ^8.0 across http-kernel, dependency-injection, expression-language, config, console, process, framework-bundle, finder, yaml and var-exporter. Symfony 8 removes XmlFileLoader support for DI service definitions. Convert all Resources/config/*.xml DI service files (and the test app's services.xml) to PHP ContainerConfigurator format, and switch TaskExtension and TestKernel from XmlFileLoader to PhpFileLoader. Doctrine ORM mapping XML files are untouched, as those use a separate XML driver unaffected by this removal. Bundle::build() gained a void return type in Symfony 8; add it to TaskBundle::build(). Doctrine ORM 3.4+ requires either PHP 8.4 native lazy objects or the legacy VarExporter-based lazy ghost proxies, the latter of which was removed from Symfony 8's ProxyHelper. Enable native lazy objects in the test app's doctrine config when running on PHP 8.4+, since Symfony 8 requires PHP 8.2+ and native lazy objects are the only supported option once VarExporter's generateLazyGhost() is gone on PHP 8.4. Fix a PHP 8.4 deprecation in DebugTasksCommand where round() could receive null when a task execution has no duration yet.
1 parent 2d18e62 commit 200cc14

30 files changed

Lines changed: 425 additions & 246 deletions

‎composer.json‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@
1212
"require": {
1313
"php": "^8.0",
1414
"php-task/php-task": "^3.0.1",
15-
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0",
16-
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
17-
"symfony/expression-language": "^5.4 || ^6.0 || ^7.0",
18-
"symfony/config": "^5.4 || ^6.0 || ^7.0",
19-
"symfony/console": "^5.4 || ^6.0 || ^7.0",
20-
"symfony/process": "^5.4 || ^6.0 || ^7.0",
15+
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0 || ^8.0",
16+
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0 || ^8.0",
17+
"symfony/expression-language": "^5.4 || ^6.0 || ^7.0 || ^8.0",
18+
"symfony/config": "^5.4 || ^6.0 || ^7.0 || ^8.0",
19+
"symfony/console": "^5.4 || ^6.0 || ^7.0 || ^8.0",
20+
"symfony/process": "^5.4 || ^6.0 || ^7.0 || ^8.0",
2121
"doctrine/orm": "^2.5.3 || ^3.0"
2222
},
2323
"require-dev": {
24-
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
25-
"symfony/finder": "^5.4 || ^6.0 || ^7.0",
26-
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
24+
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0 || ^8.0",
25+
"symfony/finder": "^5.4 || ^6.0 || ^7.0 || ^8.0",
26+
"symfony/yaml": "^5.4 || ^6.0 || ^7.0 || ^8.0",
2727
"doctrine/doctrine-bundle": "^1.5 || ^2.0",
2828
"doctrine/data-fixtures": "^1.3.3",
2929
"phpunit/phpunit": "^9.6.5 || ^10",
3030
"phpspec/prophecy": "^1.14",
3131
"phpspec/prophecy-phpunit": "^2.0",
32-
"symfony/var-exporter": "^5.4 || ^6.4 || ^7.0"
32+
"symfony/var-exporter": "^5.4 || ^6.4 || ^7.0 || ^8.0"
3333
},
3434
"autoload": {
3535
"psr-4": {

‎src/Command/DebugTasksCommand.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7878
$execution->getHandlerClass(),
7979
$execution->getScheduleTime()->format(\DateTimeImmutable::RFC3339),
8080
!$execution->getEndTime() ? '' : $execution->getEndTime()->format(\DateTimeImmutable::RFC3339),
81-
(round($execution->getDuration(), 6) * 1000000) . 'ms',
81+
(round($execution->getDuration() ?? 0.0, 6) * 1000000) . 'ms',
8282
]
8383
);
8484
}

‎src/DependencyInjection/TaskExtension.php‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ public function load(array $configs, ContainerBuilder $container)
7171
$container->setParameter('task.lock.storages.' . $key, $config['locking']['storages'][$key]);
7272
}
7373

74-
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
75-
$loader->load(sprintf('storage/%s.xml', $config['storage']));
76-
$loader->load('task_event_listener.xml');
77-
$loader->load('scheduler.xml');
78-
$loader->load('command.xml');
79-
$loader->load('locking/services.xml');
74+
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
75+
$loader->load(sprintf('storage/%s.php', $config['storage']));
76+
$loader->load('task_event_listener.php');
77+
$loader->load('scheduler.php');
78+
$loader->load('command.php');
79+
$loader->load('locking/services.php');
8080

8181
if ($config['run']['mode'] === 'listener') {
82-
$loader->load('listener.xml');
82+
$loader->load('listener.php');
8383
}
8484

8585
$this->loadDoctrineAdapter($config['adapters']['doctrine'], $container);
@@ -118,10 +118,10 @@ private function loadDoctrineAdapter(array $config, ContainerBuilder $container)
118118
private function loadLockingComponent(array $config, ContainerBuilder $container, LoaderInterface $loader)
119119
{
120120
if (!$config['enabled'] || 'null' === $config['storage']) {
121-
return $loader->load('locking/null.xml');
121+
return $loader->load('locking/null.php');
122122
}
123123

124-
$loader->load('locking/services.xml');
124+
$loader->load('locking/services.php');
125125
$container->setParameter('task.lock.ttl', $config['ttl']);
126126
}
127127

@@ -134,7 +134,7 @@ private function loadLockingComponent(array $config, ContainerBuilder $container
134134
*/
135135
private function loadExecutorComponent(array $config, ContainerBuilder $container, LoaderInterface $loader)
136136
{
137-
$loader->load('executor/' . $config['type'] . '.xml');
137+
$loader->load('executor/' . $config['type'] . '.php');
138138
$container->setAlias('task.executor', 'task.executor.' . $config['type']);
139139

140140
if (!array_key_exists($config['type'], $config)) {
@@ -178,8 +178,8 @@ private function getLockingStorageAliases(ContainerBuilder $container)
178178
*/
179179
public function getConfiguration(array $config, ContainerBuilder $container)
180180
{
181-
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
182-
$loader->load('locking/storages.xml');
181+
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
182+
$loader->load('locking/storages.php');
183183

184184
return new Configuration($this->getLockingStorageAliases($container));
185185
}

‎src/Resources/config/command.php‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-task library.
5+
*
6+
* (c) php-task
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Task\TaskBundle\Command\DebugTasksCommand;
15+
use Task\TaskBundle\Command\ExecuteCommand;
16+
use Task\TaskBundle\Command\RunCommand;
17+
use Task\TaskBundle\Command\RunHandlerCommand;
18+
use Task\TaskBundle\Command\ScheduleTaskCommand;
19+
20+
return static function (ContainerConfigurator $container): void {
21+
$services = $container->services();
22+
23+
$services->set('task.command.run', RunCommand::class)
24+
->public()
25+
->args([
26+
null,
27+
service('task.runner'),
28+
service('task.scheduler'),
29+
// add entity_manager if doctrine storage is enabled
30+
])
31+
->tag('console.command', ['command' => 'task:run']);
32+
33+
$services->set('task.command.run_handler', RunHandlerCommand::class)
34+
->public()
35+
->args([
36+
null,
37+
service('task.handler.factory'),
38+
])
39+
->tag('console.command', ['command' => 'task:run:handler']);
40+
41+
$services->set('task.command.executor', ExecuteCommand::class)
42+
->public()
43+
->args([
44+
null,
45+
service('task.handler.factory'),
46+
service('task.storage.task_execution'),
47+
service('event_dispatcher'),
48+
])
49+
->tag('console.command', ['command' => 'task:execute']);
50+
51+
$services->set('task.command.schedule_task', ScheduleTaskCommand::class)
52+
->public()
53+
->args([
54+
null,
55+
service('task.scheduler'),
56+
// add entity_manager if doctrine storage is enabled
57+
])
58+
->tag('console.command', ['command' => 'task:schedule']);
59+
60+
$services->set('task.command.debug_tasks', DebugTasksCommand::class)
61+
->public()
62+
->args([
63+
null,
64+
service('task.storage.task_execution'),
65+
])
66+
->tag('console.command', ['command' => 'debug:tasks']);
67+
};

‎src/Resources/config/command.xml‎

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-task library.
5+
*
6+
* (c) php-task
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Task\Executor\InsideProcessExecutor;
15+
16+
return static function (ContainerConfigurator $container): void {
17+
$container->services()
18+
->set('task.executor.inside', InsideProcessExecutor::class)
19+
->public()
20+
->args([service('task.handler.factory')]);
21+
};

‎src/Resources/config/executor/inside.xml‎

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-task library.
5+
*
6+
* (c) php-task
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Task\TaskBundle\Executor\ExecutionProcessFactory;
15+
use Task\TaskBundle\Executor\SeparateProcessExecutor;
16+
17+
return static function (ContainerConfigurator $container): void {
18+
$services = $container->services();
19+
20+
$services->set('task.executor.separate', SeparateProcessExecutor::class)
21+
->public()
22+
->args([
23+
service('task.handler.factory'),
24+
service('task.storage.task_execution'),
25+
service('task.executor.separate.process_factory'),
26+
]);
27+
28+
$services->set('task.executor.separate.process_factory', ExecutionProcessFactory::class)
29+
->public()
30+
->args([
31+
'%task.executor.console_path%',
32+
'%task.executor.process_timeout%',
33+
'%kernel.environment%',
34+
]);
35+
};

‎src/Resources/config/executor/separate.xml‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎src/Resources/config/listener.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-task library.
5+
*
6+
* (c) php-task
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Task\TaskBundle\EventListener\RunListener;
15+
16+
return static function (ContainerConfigurator $container): void {
17+
$container->services()
18+
->set('task.event_listener.run', RunListener::class)
19+
->public()
20+
->args([service('task.runner')])
21+
->tag('kernel.event_listener', ['event' => 'kernel.terminate', 'method' => 'run']);
22+
};

0 commit comments

Comments
 (0)