Skip to content
Browse files

Use Cilex Pimple Service Provider.

  • Loading branch information...
1 parent 47831df commit d7567e65796b94c4fb1fadc62c960eca9c80acf6 @simensen simensen committed Nov 21, 2012
View
17 composer.json
@@ -10,12 +10,19 @@
"authors":[
{ "name": "Mike van Riel", "email": "mike.vanriel@naenius.com" }
],
+ "repositories": [
+ {
+ "type": "git",
+ "url": "https://github.com/simensen/cilex-console-service-provider.git"
+ }
+ ],
"require":{
- "php": ">=5.3.3",
- "pimple/pimple": "1.0.*",
- "symfony/console": "2.1.*",
- "symfony/process": "2.1.*",
- "symfony/finder": "2.1.*"
+ "php": ">=5.3.3",
+ "pimple/pimple": "1.0.*",
+ "symfony/console": "2.1.*",
+ "symfony/process": "2.1.*",
+ "symfony/finder": "2.1.*",
+ "cilex/console-service-provider": "1.*@dev"
},
"require-dev":{
"symfony/validator": "2.1.*"
View
119 composer.lock
@@ -1,7 +1,58 @@
{
- "hash": "944309f818ae516a3e9dadc903ed7bf7",
+ "hash": "e56c1e12a86395d16852822216dd72f4",
"packages": [
{
+ "name": "cilex/console-service-provider",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/simensen/cilex-console-service-provider.git",
+ "reference": "0d3585c1915f12dbe60ad5a698ab466f2b6a5233"
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "pimple/pimple": "1.*@dev",
+ "symfony/console": "~2.1"
+ },
+ "require-dev": {
+ "cilex/cilex": "1.*@dev",
+ "silex/silex": "1.*@dev"
+ },
+ "time": "1353948732",
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "installation-source": "source",
+ "autoload": {
+ "psr-0": {
+ "Cilex\\Pimple\\Provider\\Console": "src"
+ }
+ },
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Mike van Riel",
+ "email": "mike.vanriel@naenius.com"
+ },
+ {
+ "name": "Beau Simensen",
+ "email": "beau@dflydev.com"
+ }
+ ],
+ "description": "Console Service Provider",
+ "keywords": [
+ "pimple",
+ "cilex",
+ "silex",
+ "console"
+ ]
+ },
+ {
"name": "pimple/pimple",
"version": "1.0.0",
"source": {
@@ -189,12 +240,70 @@
"homepage": "http://symfony.com"
}
],
- "packages-dev": null,
+ "packages-dev": [
+ {
+ "name": "symfony/validator",
+ "version": "v2.1.3",
+ "target-dir": "Symfony/Component/Validator",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/Validator",
+ "reference": "v2.1.3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/symfony/Validator/zipball/v2.1.3",
+ "reference": "v2.1.3",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "symfony/http-foundation": "2.1.*",
+ "symfony/locale": "2.1.*",
+ "symfony/yaml": "2.1.*"
+ },
+ "suggest": {
+ "doctrine/common": ">=2.1,<2.4-dev",
+ "symfony/http-foundation": "2.1.*",
+ "symfony/yaml": "2.1.*"
+ },
+ "time": "2012-10-22 07:37:12",
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.1-dev"
+ }
+ },
+ "installation-source": "dist",
+ "autoload": {
+ "psr-0": {
+ "Symfony\\Component\\Validator": ""
+ }
+ },
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Validator Component",
+ "homepage": "http://symfony.com"
+ }
+ ],
"aliases": [
],
"minimum-stability": "stable",
- "stability-flags": [
-
- ]
+ "stability-flags": {
+ "cilex/console-service-provider": 20
+ }
}
View
14 src/Cilex/Application.php
@@ -12,6 +12,7 @@
namespace Cilex;
use \Symfony\Component\Console;
+use \Cilex\Pimple\Provider\Console\Adapter\Cilex\ConsoleServiceProvider;
/**
* The Cilex framework class.
@@ -35,11 +36,13 @@ class Application extends \Pimple
*/
public function __construct($name, $version = null)
{
- $this['console'] = $this->share(
- function () use ($name, $version) {
- return new Console\Application($name, $version);
- }
+ $consoleConfig = array(
+ 'console.name' => $name,
);
+ if (null !== $version) {
+ $consoleConfig['console.version'] = $version;
+ }
+ $this->register(new ConsoleServiceProvider, $consoleConfig);
}
/**
@@ -70,9 +73,8 @@ public function run($interactive = false)
*
* @return void
*/
- public function command(Command\Command $command)
+ public function command(Console\Command\Command $command)
{
- $command->setContainer($this);
$this['console']->add($command);
}
View
21 src/Cilex/Command/Command.php
@@ -23,30 +23,13 @@
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;
+ return $this->getApplication()->getContainer();
}
/**
@@ -67,6 +50,6 @@ public function getContainer()
*/
public function getService($name)
{
- return isset($this->container[$name]) ? $this->container[$name] : null;
+ return $this->getApplication()->getService($name);
}
}
View
41 src/Cilex/Command/DemoInfoCommand.php
@@ -0,0 +1,41 @@
+<?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\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Command\Command as BaseCommand;
+
+/**
+ * Example command for testing purposes.
+ */
+class DemoInfoCommand extends BaseCommand
+{
+ protected function configure()
+ {
+ $this
+ ->setName('demo:info')
+ ->setDescription('Get Application Information');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ // This is a contrived example to show accessing services
+ // from the container without needing the command itself
+ // to extend from anything but Symfony Console's base Command.
+
+ $app = $this->getApplication()->getService('console');
+
+ $output->writeln('Name: ' . $app->getName());
+ $output->writeln('Version: ' . $app->getVersion());
+ }
+}
View
11 tests/Cilex/Tests/Command/CommandTest.php
@@ -34,16 +34,13 @@ public function setUp()
}
/**
- * Tests the getContainer and setContainer methods to see whether the
- * provided Cilex Application is persisted.
+ * Tests the getContainer method.
*/
public function testContainer()
{
$app = new \Cilex\Application('Test');
+ $app->command($this->fixture);
- $this->assertNull($this->fixture->getContainer());
-
- $this->fixture->setContainer($app);
$this->assertSame($app, $this->fixture->getContainer());
}
@@ -54,11 +51,11 @@ public function testContainer()
public function testGetService()
{
$app = new \Cilex\Application('Test');
- $this->fixture->setContainer($app);
+ $app->command($this->fixture);
$this->assertInstanceOf(
'\Symfony\Component\Console\Application',
- $app['console']
+ $this->fixture->getService('console')
);
}
}

0 comments on commit d7567e6

Please sign in to comment.
Something went wrong with that request. Please try again.