PHP code example of robertwesner / simple-mvc-php-spawner-bundle

1. Go to this page and download the library: Download robertwesner/simple-mvc-php-spawner-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

robertwesner / simple-mvc-php-spawner-bundle example snippets


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',
        ),
    );

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;
    }
}


class MySpawn implements SpawnInterface
{
    public function run(SpawnConfigurationInterface|MySpawnConfiguration $configuration): void
    {
        // asynchronous task with $configuration->getFoo(), etc...
    }
}

// spawner accessed through dependency injection
$this->spawner->spawn(
    EchoSpawn::class,
    new EchoSpawnConfiguration(
        'Some value',
        'Another value',
    ),
);