robertwesner/simple-mvc-php-spawner-bundle
最新稳定版本:v1.0.1
Composer 安装命令:
composer require robertwesner/simple-mvc-php-spawner-bundle
包简介
Run background tasks that do not produce synchronous output or require monitoring.
README 文档
README
Simple MVC Spawner Bundle
Run background tasks that do not produce synchronous output or require monitoring.
Fire and forget.
Created for my YouTube playlist viewer with pagination.
Installation
composer require robertwesner/simple-mvc-php-spawner-bundle
Make sure to load the bundle in your $PROJECT_ROOT$/configurations/bundles.php.
use RobertWesner\SimpleMvcPhp\Configuration; use RobertWesner\SimpleMvcPhpSpawnerBundle\SpawnerBundle; use RobertWesner\SimpleMvcPhpSpawnerBundle\SpawnerBundleConfiguration; Configuration::BUNDLES ::load( SpawnerBundle::class, // optional, can be omitted new SpawnerBundleConfiguration( preExecuteScriptPath: __BASE_DIR__ . '/pre-command.php', ), );
Usage
Create configuration
final readonly class MySpawnConfiguration implements SpawnConfigurationInterface { public function __construct( private string $foo, private string $bar, ) {} public function __serialize(): array { return [ 'foo' => $this->foo, 'bar' => $this->bar, ]; } public function __unserialize(array $data): void { $this->foo = $data['foo']; $this->bar = $data['bar']; } public function getFoo(): string { return $this->foo; } public function getBar(): string { return $this->bar; } }
Create background task
class MySpawn implements SpawnInterface { public function run(SpawnConfigurationInterface|MySpawnConfiguration $configuration): void { // asynchronous task with $configuration->getFoo(), etc... } }
Execute
// spawner accessed through dependency injection $this->spawner->spawn( EchoSpawn::class, new EchoSpawnConfiguration( 'Some value', 'Another value', ), );
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-07