2017 © Pedro PelĂĄez
 

library aent-console

A utility PHP package to create aents using Symfony console.

image

theaentmachine/aent-console

A utility PHP package to create aents using Symfony console.

  • Wednesday, August 1, 2018
  • by mouf
  • Repository
  • 2 Watchers
  • 0 Stars
  • 977 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

aent-console

A utility PHP package to create Aents using the Symfony console., (*1)

Travis CI Scrutinizer Codecov , (*2)


Why do I need this?

This package contains a set of classes that extend Symfony console classes to help you get started building an Aent., (*3)

Docker Aents must contain a "aent" program that accepts in argument events triggered by other aents., (*4)

$ aent event-name payload

When writing a command line application in PHP, it is fairly common to use Symfony console., (*5)

However, Aents have some peculiarities that do not fit with the Symfony console:, (*6)

  • If an event is not found, the aent must not return an error code. In Symfony console, if the first argument is not a known command, an error is raised
  • Aents are configured using the PHEROMONE_LOG_LEVEL environment variable. Symfony console log level is configured using the "-vvv" option.

Usage

A typical Aent will look like this:, (*7)

#!/usr/bin/env php
<?php
require __DIR__ . '/../vendor/autoload.php';

use TheAentMachine\AentApplication;
use MyAent\AddEventCommand;
use MyAent\DeleteDockerServiceEventCommand;
use MyAent\NewDockerServiceInfoEventCommand;
use MyAent\RemoveEventCommand;

// Notice how the application is a "AentApplication" and not a classical Symfony Console "Application"
$application = new AentApplication();

// Each event is a Symfony command
$application->add(new AddEventCommand());
$application->add(new RemoveEventCommand());
$application->add(new NewDockerServiceInfoEventCommand());
$application->add(new DeleteDockerServiceEventCommand());

$application->run();

Each command you write should extend "\TheAentMachine\EventCommand"., (*8)

class MyCommand extends EventCommand
{
    protected function getEventName(): string
    {
        return 'my-event-name';
    }

    protected function executeEvent(?string $payload): void
    {
        // Do some stuff with this event
    }
}

If your payload is a JSON message, you can even extend the "\TheAentMachine\JsonEventCommand"., (*9)

class MyCommand extends JsonEventCommand
{
    protected function getEventName(): string
    {
        return 'my-event-name';
    }

    protected function executeJsonEvent(array $payload): void
    {
        // Do some stuff with this event
    }
}

The Versions