Latest release: v0.4

Console Extra

Content

Usage

Register commands one by one:

extensions:
    console: Contributte\Console\DI\ConsoleExtension

    # register all console bridges
    console.extra: Contributte\Console\Extra\DI\ConsoleBridgesExtension

console.extra:
    # optionally disable these bridges
    cache: false
    caching: false
    di: false
    latte: false
    router: false
    security: false
    utils: false
    advancedCache: false
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

You can also register bridges one by one.

extensions:
    # register only bridges of your choice
    console.cache: Contributte\Console\Extra\DI\CacheConsoleExtension
    console.caching: Contributte\Console\Extra\DI\CachingConsoleExtension
    console.di: Contributte\Console\Extra\DI\DIConsoleExtension
    console.latte: Contributte\Console\Extra\DI\LatteConsoleExtension
    console.router: Contributte\Console\Extra\DI\RouterConsoleExtension
    console.security: Contributte\Console\Extra\DI\SecurityConsoleExtension
    console.utils: Contributte\Console\Extra\DI\UtilsConsoleExtension
    console.advancedCache: Contributte\Console\Extra\DI\AdvancedCacheConsoleExtension
1
2
3
4
5
6
7
8
9
10

To use these commands you need to setup a bin/console entrypoint.

Extension

At this moment, these bridges are available:

  • cache
  • caching
  • di
  • latte
  • router
  • security
  • utils
  • advanced cache

CacheConsole

cache.console:
    purge:
        - %tempDir%/cache
1
2
3

The purge parameter expects an array of dirs.

Available commands:

  • nette:cache:purge

CachingConsole

Available commands:

  • nette:caching:clear

    This command requires to specify the cleaning strategy.

    The cleaning strategy options are:

    • --all or -a shortcut
    • --tag <tag> or -t <tag> shortcut
    • --priority <priority> or -p <priority> shortcut

    NOTE: Only one tag can be used at the time.

DIConsole

console.di:
    purge:
        - %tempDir%/cache/Nette.Configurator
1
2
3

The purge parameter expects an array of dirs.

Available commands:

  • nette:di:purge

LatteConsole

console.latte:
    warmup:
         - %appDir%
    warmupExclude: []
    purge:
         - %tempDir%/cache/latte
1
2
3
4
5
6

The warmup, warmupExclude and purge parameters are expecting an array of dirs.

Available commands:

  • nette:latte:warmup
  • nette:latte:purge

RouterConsole

Available commands:

  • nette:router:dump

SecurityConsole

Available commands:

  • nette:security:password

UtilsConsole

Available commands:

  • nette:utils:random

    This command supports count parameter (--count <count> or -c <count> shortcut), to change the count of random strings. Default count is 10.

AdvancedCacheConsole

Generator

Generate application cache with a single command

  • contributte:cache:generate

    --list show list of available generators

    --generator GENERATOR use only specified generator

Register generators you want to use:
console.advancedCache:
    generators:
        latte: Contributte\Console\Extra\Cache\Generators\LatteTemplatesCacheGenerator(
            @Nette\Application\UI\ITemplateFactory,
            [%appDir%],
            [],
            ::realpath(%appDir%/..)
        )
1
2
3
4
5
6
7
8
Available generators:
  • Latte templates cache generator

    Contributte\Console\Extra\Cache\Generators\LatteTemplatesCacheGenerator(
        [%appDir%],
        @Nette\Bridges\ApplicationLatte\ILatteFactory::create()
    )
    
    1
    2
    3
    4
  • DI containers generator

    • This example is configured to generate 3 containers - 1 for production mode, 1 for debug mode and 1 for console (should be enough for every application)
    • You don't need to add the productionMode parameter for Nette BC, it is done automatically.
    Contributte\Console\Extra\Cache\Generators\DiContainersCacheGenerator(
        [
            debug: [debugMode: true, consoleMode: false],
            production: [debugMode: false, consoleMode: false],
            console: [debugMode: true, consoleMode: true]
        ],
        "?->getService('configurator')"(@container)
    )
    
    1
    2
    3
    4
    5
    6
    7
    8

    You will also need slightly modify bootstrap.php to get this generator work.

    $configurator->addServices(['configurator' => $configurator]); // we need Configurator available as a service
    $container = $configurator->createContainer();
    return $container;
    
    1
    2
    3
Implement your own generator:
use Contributte\Console\Extra\Cache\Generators\IGenerator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class YourGenerator implements IGenerator
{

    public function getDescription(): string
    {
        return 'description which is shown in console when you run `contributte:cache:generate --list`'
    }

    public function generate(InputInterface $input, OutputInterface $output): bool
    {
        // generate cache
        // inform about it in console
        // return true if generating was successful, false otherwise
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Cleaner

Clean application cache with a single command

  • contributte:cache:clean

    --list show list of available cleaners

    --cleaner CLEANER use only specified cleaner

Register cleaners you want to use:
console.advancedCache:
    cleaners:
        localFs: Contributte\Console\Extra\Cache\Cleaners\LocalFilesystemCleaner([%tempDir%])
1
2
3
Available cleaners:
  • APC cleaner

    Contributte\Console\Extra\Cache\Cleaners\ApcCleaner()
    
    1
  • APCu cleaner

    Contributte\Console\Extra\Cache\Cleaners\ApcuCleaner()
    
    1
  • Local filesystem cleaner

    Contributte\Console\Extra\Cache\Cleaners\LocalFilesystemCleaner([%tempDir%], [%tempDir%/ignored/])
    
    1
  • Memcache(d) cleaner

    Contributte\Console\Extra\Cache\Cleaners\MemcachedCleaner([@memcache1, @memcache2])
    
    1
  • Nette\Caching\IStorage cleaner

    Contributte\Console\Extra\Cache\Cleaners\NetteCachingStorageCleaner([@storage1, @storage2])
    
    1
  • Opcode cleaner

    Contributte\Console\Extra\Cache\Cleaners\OpcodeCleaner()
    
    1
Implement your own cleaner:
use Contributte\Console\Extra\Cache\Cleaners\ICleaner;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class YourCleaner implements ICleaner
{

    public function getDescription(): string
    {
        return 'description which is shown in console when you run `contributte:cache:clean --list`'
    }

    public function clean(InputInterface $input, OutputInterface $output): bool
    {
        // clean cache
        // inform about it in console
        // return true if cleaning was successful, false otherwise
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Compatibility

How to make this extension work with other Symfony/Console implementations.

Kdyby/Console

Kdyby packages use the kdyby.console.command tag to mark its Command classes in order to find them. So it won't recognize commands from other packages which don't tag them this way.

This is where the decorator extension comes into play:

decorator:
    Symfony\Component\Console\Command\Command:
        tags: [kdyby.console.command]
1
2
3

Now kdyby.console will be able to recognize all available commands added by this extension.