php 框架编写脚本,Cilex:一个轻量级的框架创建PHP CLI脚本

Cilex, a simple Command Line Interface framework

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

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

git clone this repository.

Download composer: curl -s https://getcomposer.org/installer | php

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值