entropy/entropy

Entropy framework

Maintainers

Package info

github.com/TomasVotruba/entropy

pkg:composer/entropy/entropy

Statistics

Installs: 2 516

Dependents: 8

Suggesters: 0

Stars: 3

Open Issues: 1

0.1.0 2026-05-03 20:45 UTC

This package is auto-updated.

Last update: 2026-05-03 20:46:23 UTC


README

A tiny framework with a dependency injection container and a console runner. No configuration, no YAML, no magic strings - just classes.


Install

composer require entropy/entropy

1. Dependency Injection

The container autowires services through reflection. Point it at a directory and every class in it becomes an available service.

use Entropy\Container\Container;

$container = new Container();
$container->autodiscover(__DIR__ . '/src');

$someService = $container->make(SomeService::class);

Need a custom factory? Register it manually:

$container->service(PDO::class, function (Container $container): PDO {
    return new PDO('sqlite::memory:');
});

Need every implementation of an interface? Ask for the contract:

$listeners = $container->findByContract(EventListenerInterface::class);

The container detects circular dependencies and tells you exactly where the cycle is, e.g. A -> B -> C -> A.


2. Console

Implement CommandInterface and the command is wired up automatically:

use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputPrinter;

final readonly class HelloCommand implements CommandInterface
{
    public function __construct(
        private OutputPrinter $outputPrinter
    ) {
    }

    public function getName(): string
    {
        return 'hello';
    }

    public function getDescription(): string
    {
        return 'Say hello';
    }

    /**
     * @param string[] $paths Paths to greet.
     * @param bool $loud Shout instead of speak.
     */
    public function run(array $paths, bool $loud = false): int
    {
        $this->outputPrinter->green('Hello!');

        return ExitCode::SUCCESS;
    }
}

The run() method signature is the command definition. Argument types, default values, and docblocks become CLI arguments, options, and help text. No attributes to add, no input objects to wire.


Boot the application from your binary:

use Entropy\Console\ConsoleApplication;
use Entropy\Container\Container;

$container = new Container();
$container->autodiscover(__DIR__ . '/src');

$consoleApplication = $container->make(ConsoleApplication::class);
exit($consoleApplication->run($argv));

That's it. Run it:

bin/console hello src/ --loud

Typo a command name and the fuzzy matcher will pick the closest one. Pass --help for global help, or command --help for command-level help built from your docblocks.


Happy coding!