QUIQQER Composer Events

QUIQQER Composer Events



Repository

New Features

What feature(s) did you add?

Composer is in the PHP world what NPM is in the nodejs world. QUIQQER has therefore been building on Composer since its beginnings and has it deeply integrated. So that the integration works over the web and over the console we have built a bridge which can communicate between CLI and web.

The problem was, a direct output was made on the console and therefore it could not be intercepted. In some cases you might want to log the output or continue working with it. To solve this problem we implemented Symfony Process Handling and integrated an Event Handling.

Now it is possible to react to the output event and continue working with the output.

<?php

require 'vendor/autoload.php';

$Composer = new QUI\Composer\Composer(dirname(__FILE__));
$Composer->addEvent('onOutput', function ($self, $output, $type) {
    echo $output;
});

$Composer->getOutdatedPackages();

How did you implement it/them?

Commits: 843eb93 93649c0 f42ac7a 920a50e 6bed09

So that the Composer class can fire events at all, a completely new event class was introduced.

https://github.com/QUIQQER/composer/commit/843eb930aaf01aa51d34c166cadc2a605d7cccd9#diff-cf146ce40cbf85c9b5cf8766c4e19d76

Afterwards this event class was integrated in all three composer classes, main Composer class, CLI class and the Web class.

An addEvent method was introduced so that the event can also be registered on the Composer instance. The same procedure was used in the main Composer class and in the Web composer class.

Now that all three installation classes have the event handling integrated, it is possible to react to the onOutput event (in the theory). For the whole thing to work the output event has to be executed as well.

The CLI it is a little bit tricky and not so simple, because the output is a direct output. This meant that some changes had to be made here. Symfony offers a good process class which executes a CLI command and the output can be intercepted on the fly. I.e. all system commands had to be started with such a process.

In order for the whole thing to work, we have centrally introduced a method which implements such a procedure.

After all commands were adjusted, the integration of the event handling was perfect.

Logging is now no longer a problem and also further handling with the output can be managed. With this feature QUIQQER has taken another step towards version 1.3.

Thanks for reading,
Hen, for PCSG Developers

GitHub Account

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now