PHP code example of digitalnoise / command-launcher-bundle

1. Go to this page and download the library: Download digitalnoise/command-launcher-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/ */

    

digitalnoise / command-launcher-bundle example snippets


// ...
class ActivateUserController
{
    // ...
    public function __invoke(Request $request): Response
    {
        $userId = UserId::fromRequest($request);
        $message = new ActivateUserMessage(UserId $id)
        
        $this->messageBus->dispatch($message);
        
        // ...
    }
}



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Digitalnoise\CommandLauncherBundle\CommandLauncherBundle(),
        );

        // ...
    }

    // ...
}

/**
 * @return list<class-string>
 */
public function all(): array;

public function launch(object $command): void;

abstract public function supports(string $class): bool;

abstract public function options(string $class): array;

...

abstract public function value(string $key): mixed;

abstract public function manualValue(string $input): mixed;

public function supports(string $class): bool
{
    return $class === UserId::class;
}

public function options(string $class): array
{
    $users = $this->userRepository->all();

    return array_map(fn(User $user) => new ParameterOption($user->getEmail(), $user->getFullName()), $users);
}

public function value(string $key): mixed
{
    // object of type UserId
    return $this->userRepository->findByEmail($key)->id();
}

public function manualValue(string $input): mixed
{
    return UserId::fromString($input);
}