Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

chubbyphp-legacy/chubbyphp-lazy-command

Repository files navigation

chubbyphp-lazy-command

Build Status Coverage Status Latest Stable Version Total Downloads Monthly Downloads Daily Downloads

Description

Allow to lazyload commands.

Requirements

  • php: ^7.2
  • psr/container: ^1.0
  • symfony/console: ^3.4.43|^4.4.11|^5.0

Installation

Through Composer as chubbyphp/chubbyphp-lazy-command.

composer require chubbyphp/chubbyphp-lazy-command "^1.4"

Usage

For callables

<?php

use Chubbyphp\Lazy\LazyCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

$container['service'] = function () {
    return function (InputInterface $input, OutputInterface $output) {
        // run some lazy logic
    };
};

$command = new LazyCommand(
   $container,
   'service',
   'name',
   [
       new InputArgument('argument'),
   ],
   'description',
   'help'
);

$command->run();

For existing commands extending Command

<?php

use Chubbyphp\Lazy\CommandAdapter;
use Chubbyphp\Lazy\LazyCommand;
use Symfony\Component\Console\Input\InputArgument;

$container['service'] = function () {
    return new CommandAdapter(new ExistingCommand());
};

$command = new LazyCommand(
   $container,
   'service',
   'name',
   [
       new InputArgument('argument'),
   ],
   'description',
   'help'
);

$command->run();

Copyright

Dominik Zogg 2020