Cilex a lightweight framework for creating PHP CLI scripts inspired by Silex

Related tags

Command Line Cilex
Overview

Cilex, a simple Command Line Interface framework

Cilex is a simple command line application framework to develop simple tools based on Symfony2 components:

<?php
if (!$loader = include __DIR__.'/vendor/autoload.php') {
    die('You must set up the project dependencies.');
}

$app = new \Cilex\Application('Cilex');
$app->command(new \Cilex\Command\GreetCommand());
$app->command('foo', function ($input, $output) {
    $output->writeln('Example output');
});
$app->run();

Cilex works with PHP 5.5.9 or later and is heavily inspired by the Silex web micro-framework by Fabien Potencier.

Installation

  1. git clone this repository.
  2. Download composer: curl -s https://getcomposer.org/installer | php
  3. Install Cilex' dependencies: php composer.phar install

Usage

  • Create your new commands in src/Cilex/Command/
  • Add your new commands to bin/run.php
  • Run the commands as:
./bin/run.php demo:greet world
./bin/run.php demo:greet world -y
./bin/run.php demo:greet world --yell
./bin/run.php demo:info

Creating a PHAR

  • Download and install box:
curl -LSs https://box-project.github.io/box2/installer.php | php
chmod +x box.phar
mv box.phar /usr/local/bin/box
  • Update the project phar config in box.json
  • Create the package:
box build
  • Run the commands:
./cilex.phar demo:greet world
./cilex.phar demo:greet world -y
./cilex.phar demo:greet world --yell
./cilex.phar demo:info
  • enjoy a lot.

License

Cilex is licensed under the MIT license.

FAQ

Q: How do I pass configuration into the application?

A: You can do this by adding the following line, where $configPath is the path to the configuration file you want to use:

$app->register(new \Cilex\Provider\ConfigServiceProvider(), array('config.path' => $configPath));

The formats currently supported are: YAML, XML and JSON

Comments
  • Pimple3

    Pimple3

    This makes Cilex more inline with Silex 2.0 and uses pimple 3. there is an issue with silex/api as have not yet been updated with the pimple 3.0 requirement.

    I removed a bunch of providers as they can now be used from silex/providers. Also i moved the ConsoleServiceProvider into Cilex directly, mostly because its a hard requirement. If we want a seperate package for it, we can use a subsplit on src/Cilex/Provider as the silex/providers package does.

    opened by henrikbjorn 23
  • ServiceProviderInterface and Silex

    ServiceProviderInterface and Silex

    so one of my visions was that Cilex and Silex could share extensions. right now @mvriel introduced a new ServiceProviderInterface interface inside the Cilex namespace. i talked briefly with him on IRC today where @mvriel said he wants to switch the Silex one, which obviously would imply a dependency on Silex, which imho is fine, but i don't know how specifically he wants it to play out given the Application type hint.

    but it does raise the question of if we are not making things needlessly complex by not doing this all inside Silex. then again doing it all inside Silex would go against the entire "micro" idea. so maybe we do need to ask the Silex guys to make things a bit easier for us ..

    /cc @igorw @jmikola

    opened by lsmith77 19
  • Add dependency support for pimple ~2.0

    Add dependency support for pimple ~2.0

    Cilex is currently bound to pimple ~1.0. When included in a complex composer.json dependency tree, cilex bounds pimple to the older version. This is causing problems with a variety of other packages, such as elasticsearch.

    opened by cverges 6
  • Move to Pimple 2.*

    Move to Pimple 2.*

    Want to use Pimple 2.* in my application but composer seeing conflict with Cilex and doesn't let me. This is also providing the use of PhpDocumentor since it uses Cilex as well. Have NOT looked to see what all changes were make on Pimple but always prefer using most up to date versions when possible. After a quick look it looks like the main change is that instances are shared by default like share() would do and you use factory() to get something like the old behavior if my reading of the code is right. Not sure how this effects Cilex.

    opened by Dragonrun1 5
  • compilation error

    compilation error

    When I try to compile:

    cilex/bin$ php ./compile

    PHP Fatal error: Uncaught exception 'RuntimeException' with message 'The git binary cannot be found.' in /media/disk2/darek/yii/cilex/src/Cilex/Compiler.php:43 Stack trace: #0 /media/disk2/darek/yii/cilex/bin/compile(13): Cilex\Compiler->compile() #1 {main}

    thrown in /media/disk2/darek/yii/cilex/src/Cilex/Compiler.php on line 43

    Fatal error: Uncaught exception 'RuntimeException' with message 'The git binary cannot be found.' in /media/disk2/darek/yii/cilex/src/Cilex/Compiler.php on line 43

    RuntimeException: The git binary cannot be found. in /media/disk2/darek/yii/cilex/src/Cilex/Compiler.php on line 43

    but git is of course available on system

    cilex/bin$ whereis git git: /usr/bin/git /usr/bin/X11/git /usr/share/man/man1/git.1.gz

    cilex/bin$ git usage: git [--version] [--exec-path[=]] [--html-path] [--man-path] [--info-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=] [--work-tree=] [--namespace=] [-c name=value] [--help] []

    opened by blendsoft 4
  • Fix lost library class-loader

    Fix lost library class-loader

    PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'The "/src/Cilex/../../vendor/symfony/class-loader/Symfony/Component/ClassLoader" directory does not exist.' in /vendor/symfony/finder/Symfony/Component/Finder/Finder.php:497

    opened by beshkenadze 4
  • Documentation improvements

    Documentation improvements

    • Added a demo run.php file in bin/
    • Added .idea to gitignore
    • Added a demo box.json
    • Improved the readme file to explain how to create and use new commands, as well as creating a phar file using box
    opened by hgraca 3
  • Add easy way to use simple closures as commands

    Add easy way to use simple closures as commands

    This fixed #27

    I know this is a BC but since it targets 2.0 i think it is okay.

    The reason for renaming command to add is that it adds the command to the application, which is the same terminology used by a normal Console Application. Also when using closures the name command feels more natural.

    here is an example, the syntax should be equal to the one used in Silex with its get, post etc functions.

    <?php
    
    $cilex = new Cilex\Application;
    $cilex->command('my-command-name', function ($input, $output) {
        // do something
    });
    
    $command = $cilex->command('my-command-name', function ($input, $output) {
        // do something
    });
    
    $command->addOption(); // etc.
    
    opened by henrikbjorn 3
  • cilex.phar has errors

    cilex.phar has errors

    Fresh install: 1008 git clone https://github.com/Cilex/Cilex.git 1009 cd Cilex 1010 composer update 1011 composer install 1012 php bin/compile 1013 php cilex.phar PHP Warning: require(phar:///private/tmp/Cilex/cilex.phar/vendor/composer/include_paths.php): failed to open stream: phar error: "vendor/composer/include_paths.php" is not a file in phar "/private/tmp/Cilex/cilex.phar" in phar:///private/tmp/Cilex/cilex.phar/vendor/composer/autoload_real.php on line 29

    Warning: require(phar:///private/tmp/Cilex/cilex.phar/vendor/composer/include_paths.php): failed to open stream: phar error: "vendor/composer/include_paths.php" is not a file in phar "/private/tmp/Cilex/cilex.phar" in phar:///private/tmp/Cilex/cilex.phar/vendor/composer/autoload_real.php on line 29 PHP Fatal error: require(): Failed opening required 'phar:///private/tmp/Cilex/cilex.phar/vendor/composer/include_paths.php' (include_path='.:') in phar:///private/tmp/Cilex/cilex.phar/vendor/composer/autoload_real.php on line 29

    Fatal error: require(): Failed opening required 'phar:///private/tmp/Cilex/cilex.phar/vendor/composer/include_paths.php' (include_path='.:') in phar:///private/tmp/Cilex/cilex.phar/vendor/composer/autoload_real.php on line 29

    opened by cxj 3
  • Cilex/Silex ServiceProvider Incompatibility

    Cilex/Silex ServiceProvider Incompatibility

    The register function of Cilex\Application supposedly allows you to register a Silex ServiceProvider (\vendor\cilex\cilex\src\Cilex\Application.php:97-99), but when actually trying to register the Silex ServiceProvider, you hit:

    Catchable fatal error: Argument 1 passed to Igorw\Silex\ConfigServiceProvider::register() must be an instance of Silex\Application, instance of Cilex\Application given
    

    If it is to be compatible with Silex service providers, the Interface definition typehint must be dropped or if it is not compatible, lines \vendor\cilex\cilex\src\Cilex\Application.php:97-103 should be removed.

    This seems related to https://github.com/Cilex/Cilex/issues/3.

    opened by jonmchan 3
  • Added console-service-provider to the phar compiler finder.

    Added console-service-provider to the phar compiler finder.

    Added the console-service-provider library to the finder that compiles the phar, fixes this exception I was always getting: PHP Fatal error: Class 'Cilex\Provider\Console\ConsoleServiceProvider' not found in phar://

    opened by kimausloos 3
  • Symfony 4 compatibility

    Symfony 4 compatibility

    Greetings from the #SymfonyConHackday2017. This PR fixes a small compatibility problem with Symfony 4 and updates the composer.json file to allow the installation of Symfony 4 components.

    opened by derrabus 0
Library for creating CLI commands or applications

Console Motivation: this library purpose is to provide a lighter and more robust API for console commands and/or applications to symfony/console. It c

Théo FIDRY 16 Dec 28, 2022
Skeleton for creating a new Command Line Interface application with a minimum of dependencies.

Skeleton for creating a new Command Line Interface application with a minimum of dependencies.

Richard van Laak 1 Jan 17, 2022
🖥 Build beautiful PHP CLI menus. Simple yet Powerful. Expressive DSL.

Contents Minimum Requirements Installation Upgrading Usage Quick Setup Examples API Appearance Menu Title Colour Width Padding Margin Borders Exit But

PHP School 1.9k Dec 28, 2022
An Elegant CLI Library for PHP

Commando An Elegant PHP CLI Library Commando is a PHP command line interface library that beautifies and simplifies writing PHP scripts intended for c

Nate Good 793 Dec 25, 2022
PHP Version Manager for the CLI on Windows

This package has a much more niche use case than nvm does. When developing on Windows and using the integrated terminal, it's quite difficult to get those terminals to actually listen to PATH changes.

Harry Bayliss 49 Dec 19, 2022
PHP CLI tool which allows publishing zipped MODX extra to modstore.pro marketplace

MODX Extra Publisher PHP CLI tool which allows publishing zipped MODX extra to modstore.pro marketplace. Installation global? local? To install packag

Ivan Klimchuk 3 Aug 6, 2021
PHP CLI project to get an appointment from https://vacunacovid.catsalut.gencat.ca

covid_vaccine_bcn PHP CLI project to get an appointment from https://citavacunacovid19.catsalut.gencat.cat/Vacunacio_Covid/Vacunacio/VacunacioCovidRes

Gabriel Noé González 3 Jul 27, 2021
PHP CLI to add latest release notes to a CHANGELOG

changelog-updater A PHP CLI to update a CHANGELOG following the "Keep a Changelog" format with the latest release notes. Want to automate the process

Stefan Zweifel 15 Sep 21, 2022
unofficial cli built using php which can be used to upload and download files from anonfiles.com

Anonfiles CLI Table of Contents Introduction Features Screenshots Installation Contributing License Introduction Anon Files CLI can upload and downloa

Albin Varghese 8 Nov 21, 2022
A handy set of Stringable mixins for CLI text.

Laravel Colorize A mixin for Laravel's Stringable to easily apply colors and styles to CLI text. Installation You can install the package via Composer

James Brooks 47 Oct 30, 2022
WP-CLI Trait Package Command

WP-CLI Trait Package Command Generate plugin or php model files e.g. post-type or taxonomy for WP-Trait Package in Develop WordPress Plugin. Installat

Mehrshad Darzi 2 Dec 17, 2021
A CLI program that helps you check your endpoints by requesting the given servers and send a report message in any supported channel like Telegram

API Monitor A CLI program that help you check your endpoints by requesting the given servers and send a report message in any supported channel ( Tele

Hussein Feras 51 Aug 21, 2022
Termage provides a fluent and incredibly powerful object-oriented interface for customizing CLI output text color, background, formatting, theming and more.

Termage provides a fluent and incredibly powerful object-oriented interface for customizing CLI output text color, background, formatting, theming and

TERMAGE 75 Dec 20, 2022
A CLI starter pack for developing a package with Laravel 5

Laravel PackMe Laravel PackMe is a project starter pack which combine all basic stuff (src, tests) in order to develop a package for Laravel 5.*. It t

Pierre Tondereau 63 Dec 29, 2021
PHPFusion CLI

PHPFusion CLI Installation Source Add path\to\PF-CLI\bin to your system PATH .phar file Download pf.phar Check the Phar file to verify that it's worki

PF Projects 0 Mar 20, 2022
Drupal.org Git CLI

doGit Drupal.org + Git CLI application. doGit assists in making the transition to merge requests, and general Git operations, easier for Drupal develo

dpi 16 Dec 15, 2022
A Magento 2 module that adds a CLI bin/magento cms:dump to dump all CMS pages and CMS blocks to a folder var/cms-output.

A Magento 2 module that adds a CLI bin/magento cms:dump to dump all CMS pages and CMS blocks to a folder var/cms-output.

Yireo 16 Dec 16, 2022
Host Onion services in dark web using Heroku CLI

Tor Onion Service On Heroku Host Tor v3 Hidden Service in dark web using heroku Try my another repository built with php https://github.com/sumithemma

Emmadi Sumith Kumar 34 Dec 13, 2022