PHP code example of integration-kit / bundle

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

    

integration-kit / bundle example snippets


// 1. Define a typed Command (execution contract)
final class SlackNotifyCommand implements IntegrationCommand
{
    public function __construct(
        public readonly string $email,
        public readonly string $name
    ) {}
    
    public function integrationName(): string
    {
        return 'slack';
    }
}

// 2. Define an explicit Handler (typed mapping, no reflection)
final class SlackNotifyHandler implements IntegrationHandlerInterface
{
    public function __construct(
        private HttpClientInterface $httpClient,
        private string $webhookUrl
    ) {}
    
    public function supports(): string
    {
        return SlackNotifyCommand::class;
    }
    
    public function handle(IntegrationCommand $command): void
    {
        assert($command instanceof SlackNotifyCommand);
        
        $response = $this->httpClient->request('POST', $this->webhookUrl, [
            'json' => ['text' => "User {$command->email} ({$command->name}) registered"]
        ]);
        
        if (200 !== $response->getStatusCode()) {
            throw new IntegrationException('slack', 'Notification failed');
        }
    }
}

// 3. Use it in business code (strong typing, auto-completion)
class UserService
{
    public function __construct(
        private IntegrationExecutor $executor
    ) {}
    
    public function notifyUserRegistered(User $user): void
    {
        // Typed command = compile-time safety, refactoring safe
        $this->executor->execute(new SlackNotifyCommand(
            $user->getEmail(),
            $user->getName()
        ));
    }
}