PHPackages                             locomotivemtl/charcoal-contrib-command - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. locomotivemtl/charcoal-contrib-command

ActiveLibrary[CLI &amp; Console](/categories/cli)

locomotivemtl/charcoal-contrib-command
======================================

Charcoal contrib to handle dynamic cron scripts as commands.

0.1.6(1mo ago)1198MITPHPPHP &gt;7.1CI failing

Since Mar 10Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/locomotivemtl/charcoal-contrib-command)[ Packagist](https://packagist.org/packages/locomotivemtl/charcoal-contrib-command)[ Docs](https://locomotivemtl.github.io/charcoal-contrib-command/)[ RSS](/packages/locomotivemtl-charcoal-contrib-command/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (10)Versions (9)Used By (0)

Charcoal Contrib Command
========================

[](#charcoal-contrib-command)

[![License](https://camo.githubusercontent.com/4a71b58c32065b43fb5734a959f0ab99ad2d3ab4375b72d5638407756341278a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6f636f6d6f746976656d746c2f63686172636f616c2d636f6e747269622d636f6d6d616e642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/locomotivemtl/charcoal-contrib-command)[![Latest Stable Version](https://camo.githubusercontent.com/c95dfd43ac13b90dbe09d9a8808b142bbea65bb402d317029b19c3d892dc9bc7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6f636f6d6f746976656d746c2f63686172636f616c2d636f6e747269622d636f6d6d616e642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/locomotivemtl/charcoal-contrib-command)[![Code Quality](https://camo.githubusercontent.com/89d8723cfdece3ae94f0c2d3075c95cfaae8b713ea23c4c14699a38029ed2e30/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6c6f636f6d6f746976656d746c2f63686172636f616c2d636f6e747269622d636f6d6d616e642e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/locomotivemtl/charcoal-contrib-command/)[![Coverage Status](https://camo.githubusercontent.com/918308eb2159557a075d8ec804e22aa0e7c27a0e28481b74affd7a5ec807d4dc/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6c6f636f6d6f746976656d746c2f63686172636f616c2d636f6e747269622d636f6d6d616e642e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/locomotivemtl/charcoal-contrib-command)[![Build Status](https://camo.githubusercontent.com/e6cbd47d7717937ccbfecf61a2c387535ac2da22b9cf24fdda1be07409565693/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c6f636f6d6f746976656d746c2f63686172636f616c2d636f6e747269622d636f6d6d616e642e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/locomotivemtl/charcoal-contrib-command)

A charcoal contrib used to provide dynamic cron scripts, easily schedulable.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
    - [Dependencies](#dependencies)
- [Service Provider](#service-provider)
    - [Services](#services)
- [Configuration](#configuration)
    - [Defaults](#defaults)
- [Usage](#usage)
    - [Creating a command class](#creating-a-command-class)
        - [Interface](#interface)
        - [Example](#example)
    - [Back-end form](#back-end-form)
    - [Available services](#available-services)
        - [Method](#method)
        - [Parameters](#parameters)
- [Development](#development)
    - [API Documentation](#api-documentation)
    - [Development Dependencies](#development-dependencies)
    - [Coding Style](#coding-style)
- [Credits](#credits)
- [License](#license)

Installation
------------

[](#installation)

The preferred (and only supported) method is with Composer:

```
$ composer require locomotivemtl/charcoal-contrib-command
```

### Including the modules

[](#including-the-modules)

Just add the following module in your json configuration file:

`"charcoal/command/command": {},`

### Setting a cron

[](#setting-a-cron)

Script `command/process-queue` is added with the command's module.

```
* * * * * /path/to/bin/php /path/to/vendor/bin/charcoal command/process-queue > /dev/null 2>&1

```

### Dependencies

[](#dependencies)

#### Required

[](#required)

- [**PHP 7.1+**](https://php.net): *PHP 7.3+* is recommended.
- [**Monolog/monolog**](https://github.com/Seldaek/monolog): Official project logger.

#### PSR

[](#psr)

\--TBD--

Service Provider
----------------

[](#service-provider)

The following services are provided with the use of [charcoal-contrib-command](https://packagist.org/packages/locomotivemtl/charcoal-contrib-command)

### Services

[](#services)

- **command/queue-stack**: instance of Command\\Service\\CommandQueuer

Configuration
-------------

[](#configuration)

Every bit of configuration for the command contrib should be under the namespace `command`. Configurations allows the possibility to define options for the logger, such as the handlers, processors or formatters. All default configurations are visible in the `Charcoal\Command\Logger\Config\CommandLoggerConfig` class.

### Defaults

[](#defaults)

```
    "command": {
        "logger": {
            "level": "debug",
            "active": true,
            "handlers": {
                "charcoal/command/logger/handler/charcoal": {
                    "model": "charcoal/command/log",
                    "formatter": {
                        "charcoal/command/logger/formatter/command": {}
                    }
                }
            }
        }
    }
```

The handlers should be resolvable by the logger handler generic factory. In the given example, we see `Charcoal\Command\Logger\Handler\CharcoalHandler` class. The options defined with the handler will be passed in the handler's constructor method.

The formatters should be resolvable by the logger formatter generic factory. In the given example, we see `Charcoal\Command\Logger\Formatter\Command`. The options defined with the formatter will be passed in the formatter's constructor method.

The class should be resolvable by the model factory. In the given example, we see `Charcoal\Command\Log`.

Usage
-----

[](#usage)

### Creating a command class

[](#creating-a-command-class)

A command class should extend the `AbstractCommand` class. You can use the `setDependencies` public method to access any dependencies you might need. The public method `execute` is called when everything is ready.

#### Interface

[](#interface)

- public **AbstractCommand::\_\_invoke ( array $arguments )**: Sets arguments, execute command and log results
- public **AbstractCommand::setDependencies ( Container $container )**: Allows to set any required dependencies
- protected **AbstractCommand::log ()**: Called upon execution. Logs according to the given options.
- protected **AbstractCommand::setSuccess ( boolean $success )**: Defines if the scripts was executed successfully or not.
- abstract protected **AbstractCommand::execute ()**: The actual command goes in there.

#### Example

[](#example)

```
namespace Charcoal\Cache\Command;

[...]

/**
 * Cache clearer command
 */
class ClearCommand extends AbstractCommand
{
    use CachePoolAwareTrait;

    /**
     * @param array $arguments
     */
    public function setDependencies(Container $container)
    {
        parent::setDependencies($container);
        $this->setCachePool($container['cache']);
    }

    /**
     * @return mixed|void
     */
    public function execute()
    {
        $success = $this->cachePool()->clear();
        $this->setSuccess($success);
    }
}
```

### Back-end form

[](#back-end-form)

Use the CommandQueue model to queue a new command.

KeyTypeExampleDescription`command`stringcharcoal/cache/command/clearShould be resolvable by the command factory. Hits `Charcoal\Cache\Command\ClearCommand``arguments`array{ "someProperty": "someValue" }Any arguments that could be necessary for the executed command. Passed as argument to the command's constructor method.`issuedDate`DateTimenowWhen was the command issued. This is done on preSave and shouldn't be altered.`processingDate`DateTimenowWhen should the script be run?`processedDate`DateTimenowWhen has the script been ran? Could differ from the processingDate depending on the cron frenquency and the time of execution of the command.`processed`booleanfalseFlag as to whether or not the command has been processed.### Available Service

[](#available-service)

#### Method

[](#method)

```
public QueueStack::enqueue ( array $data ) : QueueStack

```

#### Parameters

[](#parameters)

Array **data**

- `command`: Required. Resolvable Command class string.
- `processingDate`: Optional. Date when the command should be run. Accept any valid DateTime format or a DateTime object. Defaults to `now`
- `arguments`: Options. Array of arguments to be passed to the command constructor method.

##### Example

[](#example-1)

```
    $stack = $container['command/queue-stack'];
    $stack->enqueue([
        'command' => 'charcoal/cache/command/clear',
        'processingDate' => 'NOW +1 day'
    ]);
```

The default processing date is "now".

Development
-----------

[](#development)

To install the development environment:

```
$ composer install
```

To run the scripts (phplint, phpcs, and phpunit):

```
$ composer test
```

### API Documentation

[](#api-documentation)

- The auto-generated `phpDocumentor` API documentation is available at:

- The auto-generated `apigen` API documentation is available at:
    [https://codedoc.pub/locomotivemtl/charcoal-contrib-command/master/](https://codedoc.pub/locomotivemtl/charcoal-contrib-command/master/index.html)

### Development Dependencies

[](#development-dependencies)

- \[php-coveralls/php-coveralls\]\[phpcov\]
- \[phpunit/phpunit\]\[phpunit\]
- \[squizlabs/php\_codesniffer\]\[phpcs\]

### Coding Style

[](#coding-style)

The charcoal-contrib-command module follows the Charcoal coding-style:

- [*PSR-1*](https://www.php-fig.org/psr/psr-1/)
- [*PSR-2*](https://www.php-fig.org/psr/psr-2/)
- [*PSR-4*](https://www.php-fig.org/psr/psr-4/), autoloading is therefore provided by *Composer*.
- [*phpDocumentor*](http://phpdoc.org/) comments.
- [phpcs.xml.dist](phpcs.xml.dist) and [.editorconfig](.editorconfig) for coding standards.

> Coding style validation / enforcement can be performed with `composer phpcs`. An auto-fixer is also available with `composer phpcbf`.

Credits
-------

[](#credits)

- [Locomotive](https://locomotive.ca/)

License
-------

[](#license)

Charcoal is licensed under the MIT license. See [LICENSE](LICENSE) for details.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance89

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~314 days

Recently: every ~545 days

Total

8

Last Release

57d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4229f19eecd12c2b651b6502dcc5adfba48c5770db3d2dbea55fc92c7a246b2b?d=identicon)[BeneRoch](/maintainers/BeneRoch)

---

Top Contributors

[![BeneRoch](https://avatars.githubusercontent.com/u/3017380?v=4)](https://github.com/BeneRoch "BeneRoch (10 commits)")

---

Tags

charcoal

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/locomotivemtl-charcoal-contrib-command/health.svg)

```
[![Health](https://phpackages.com/badges/locomotivemtl-charcoal-contrib-command/health.svg)](https://phpackages.com/packages/locomotivemtl-charcoal-contrib-command)
```

###  Alternatives

[pantheon-systems/terminus

A command line interface for Pantheon

3391.5M13](/packages/pantheon-systems-terminus)[mahocommerce/maho

Free and open source ecommerce platform, created in 2024 on the M1 platform, PHP 8.3+

1322.1k12](/packages/mahocommerce-maho)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
