Permalink
Browse files

Initial commit

  • Loading branch information...
1 parent f23bd8a commit c84de0aa6e3f1411d2f681f0ea01711d31dfbe0f @mvriel mvriel committed Mar 23, 2012
View
@@ -0,0 +1,4 @@
+vendor
+phpunit.xml
+cilex.phar
+.idea
View
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Mike van Riel
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
0 README
No changes.
View
@@ -0,0 +1,37 @@
+Cilex, a simple Command Line Interface framework
+================================================
+
+Cilex is a simple command line application framework to develop simple tools
+based on [Symfony2][1] components:
+
+```php
+<?php
+require_once __DIR__.'/cilex.phar';
+
+$app = new \Cilex\Application('Cilex');
+$app->command(new \Cilex\Command\DemoGreetCommand());
+$app->run();
+```
+
+Cilex works with PHP 5.3.2 or later and is heavily inspired on the [Silex][2]
+web micro-framework by Fabien Potencier.
+
+<!--
+## Installation
+
+Installing Cilex is as easy as it can get. Download the [`cilex.phar`][3] file
+and you're done!
+
+## More Information
+
+Read the [documentation][4] for more information.
+-->
+
+## License
+
+Cilex is licensed under the MIT license.
+
+[1]: http://symfony.com
+[2]: http://silex.sensiolabs.org
+[3]: http://cilex.github.com/get/cilex.phar
+[4]: http://cilex.github.com/documentation
View
@@ -0,0 +1,8 @@
+#!/usr/bin/env php
+<?php
+require_once __DIR__.'/vendor/.composer/autoload.php';
+
+use Cilex\Compiler;
+
+$compiler = new Compiler();
+$compiler->compile();
View
@@ -0,0 +1,37 @@
+{
+ "name": "cilex/cilex",
+ "description": "The PHP micro-framework for Command line tools based on the Symfony2 Components",
+ "keywords": ["microframework","cli"],
+ "homepage": "http://cilex.github.com",
+ "license": "MIT",
+ "authors":[
+ {
+ "name": "Mike van Riel",
+ "email": "mike.vanriel@naenius.com"
+ }
+ ],
+ "require":{
+ "php": ">=5.3.2",
+ "pimple/pimple": "dev-master",
+ "symfony/class-loader": "2.1.*",
+ "symfony/console": "2.1.*",
+
+ "symfony/process": "2.1.*",
+ "symfony/finder": "2.1.*"
+ },
+ "suggest":{
+ "monolog/monolog": ">=1.0.0",
+ "symfony/yaml": ">=1.0.0",
+ "symfony/validator": ">=1.0.0"
+ },
+ "autoload":{
+ "psr-0":{
+ "Cilex": "src/"
+ }
+ },
+ "extra":{
+ "branch-alias":{
+ "dev-master": "1.0-dev"
+ }
+ }
+}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,6 @@
+<?php
+require_once __DIR__ . '/cilex.phar';
+
+$app = new \Cilex\Application('Cilex');
+$app->command(new \Cilex\Command\GreetCommand());
+$app->run();
View
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="vendor/.composer/autoload.php"
+ >
+ <testsuites>
+ <testsuite name="Cilex Test Suite">
+ <directory>./tests/Cilex/</directory>
+ </testsuite>
+ </testsuites>
+</phpunit>
View
@@ -0,0 +1,99 @@
+<?php
+
+/*
+ * This file is part of the Cilex framework.
+ *
+ * (c) Mike van Riel <mike.vanriel@naenius.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Cilex;
+
+use \Symfony\Component\Console;
+use \Symfony\Component\ClassLoader\UniversalClassLoader;
+
+/**
+ * The Cilex framework class.
+ *
+ * @author Mike van Riel <mike.vanriel@naenius.com>
+ *
+ * @api
+ */
+class Application extends \Pimple
+{
+ /** @var int Version number for Cilex */
+ const VERSION = '1.0.0';
+
+ /**
+ * Registers the autoloader and necessary components.
+ *
+ * @param string $name Name for this application.
+ * @param string|null $version Version number for this application.
+ */
+ function __construct($name, $version = null)
+ {
+ $this['autoloader'] = $this->share(function () {
+ $loader = new UniversalClassLoader();
+ $loader->register();
+ return $loader;
+ });
+
+ $this['console'] = $this->share(function () use ($name, $version) {
+ return new Console\Application($name, $version);
+ });
+ }
+
+ /**
+ * Executes this application.
+ *
+ * @param bool $interactive runs in an interactive shell if true.
+ *
+ * @return void
+ */
+ public function run($interactive = false)
+ {
+ $app = $this['console'];
+ if ($interactive)
+ {
+ $app = new Console\Shell($app);
+ }
+
+ $app->run();
+ }
+
+ /**
+ * Adds a command object.
+ *
+ * If a command with the same name already exists, it will be overridden.
+ *
+ * @param \Cilex\Command\Command $command A Command object
+ *
+ * @api
+ *
+ * @return void
+ */
+ public function command(Command\Command $command)
+ {
+ $command->setContainer($this);
+ $this['console']->add($command);
+ }
+
+ /**
+ * Registers a service provider.
+ *
+ * @param ServiceProviderInterface $provider A ServiceProviderInterface instance
+ * @param mixed[] $values An array of values that customizes the provider
+ *
+ * @return void
+ */
+ public function register(ServiceProviderInterface $provider, array $values = array())
+ {
+ foreach ($values as $key => $value) {
+ $this[$key] = $value;
+ }
+
+ $provider->register($this);
+ }
+}
@@ -0,0 +1,70 @@
+<?php
+
+/*
+ * This file is part of the Cilex framework.
+ *
+ * (c) Mike van Riel <mike.vanriel@naenius.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Cilex\Command;
+
+use \Symfony\Component\Console;
+
+/**
+ * Base class for Cilex commands.
+ *
+ * @author Mike van Riel <mike.vanriel@naenius.com>
+ *
+ * @api
+ */
+abstract class Command extends Console\Command\Command
+{
+ /** @var \Cilex\Application */
+ protected $container = null;
+
+ /**
+ * Sets the application container containing all services.
+ *
+ * @param \Cilex\Application $container Application object to register.
+ *
+ * @return void
+ */
+ public function setContainer(\Cilex\Application $container)
+ {
+ $this->container = $container;
+ }
+
+ /**
+ * Returns the application container.
+ *
+ * @return \Cilex\Application
+ */
+ public function getContainer()
+ {
+ return $this->container;
+ }
+
+ /**
+ * Returns a service contained in the application container or null if none
+ * is found with that name.
+ *
+ * This is a convenience method used to retrieve an element from the
+ * Application container without having to assign the results of the
+ * getContainer() method in every call.
+ *
+ * @param string $name Name of the service
+ *
+ * @see self::getContainer()
+ *
+ * @api
+ *
+ * @return \stdClass|null
+ */
+ public function getService($name)
+ {
+ return isset($this->container[$name]) ? $this->container[$name] : null;
+ }
+}
Oops, something went wrong.

0 comments on commit c84de0a

Please sign in to comment.