Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
624 changes: 484 additions & 140 deletions composer.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/Coddict/DevExtraBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ services:
arguments: ["@service_container"]
coddictdevextra.packagistsearch:
class: Coddict\DevExtraBundle\Services\PackagistSearchService
arguments: ["@service_container"]
coddictdevextra.console:
class: Coddict\DevExtraBundle\Services\ConsoleService
arguments: ["@service_container"]
93 changes: 93 additions & 0 deletions src/Coddict/DevExtraBundle/Services/ConsoleService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Coddict\DevExtraBundle\Services;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Coddict\DevExtraBundle\Utils\VirtualConsoleApplication;
use Coddict\DevExtraBundle\Utils\StringOutput;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\ArrayInput;

class ConsoleService extends AbstractService
{
public function getCommands()
{
$kernel = $this->get('kernel');
$consoleApp = new VirtualConsoleApplication($kernel);
$consoleApp->registerCommands();
$commands = $consoleApp->all();
$output = array();
// TODO: i think we must use $consoleApp->sortCommands($commands)
// to get all commands sorted by namespace
foreach($commands as $key => $command)
$output[$key] = $this->serializeCommand($command);
return $output;
}

public function findCommand($name)
{
$kernel = $this->get('kernel');
$consoleApp = new VirtualConsoleApplication($kernel);
$consoleApp->registerCommands();
$command = $consoleApp->find($name);
return $command;
}



public function runCommand($name, $param)
{
$command = $this->findCommand($name);
$input = null;
$output = new StringOutput();

if(is_array($param)){
$param['command'] = $name;
$input = new ArrayInput($param);
}
else{
$param = $name.' '.$param;
$input = new StringInput($param);
}

$statusCode = $command->run($input, $output);

return $output;
}

protected function serializeCommand($command)
{
return array(
"name" => $command->getName(),
//"alias" => $command->getAliases(),
"options" => $this->serializeOptions($command->getDefinition()->getOptions()),
"arguments" => $this->serializeArguments($command->getDefinition()->getArguments()),
);
}

protected function serializeArguments($arguments)
{
$output = array();
foreach($arguments as $key => $argument)
$output[] = array(
"name" => $argument->getName(),
"isRequired" => $argument->isRequired(),
"description" => $argument->getDescription(),
);
return $output;
}

protected function serializeOptions($options)
{
$output = array();
foreach($options as $key => $option)
$output[] = array(
"name" => $option->getName(),
"shortcut" => $option->getShortcut(),
"description" => $option->getDescription(),
);
return $output;
}
}

?>
3 changes: 3 additions & 0 deletions src/Coddict/DevExtraBundle/Services/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class EntityManager extends AbstractService{
* Updates the database schema based on existing entities
*/
public function schemaUpdate(){

// TODO : use ConsoleService

$kernel = $this->get('kernel');
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$application->setAutoExit(false);
Expand Down
32 changes: 32 additions & 0 deletions src/Coddict/DevExtraBundle/Tests/Services/ConsoleServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Coddict\DevExtraBundle\Tests\Services;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class ConsoleServiceTest extends WebTestCase
{

public function testGetCommands()
{
$container = static::createClient()->getContainer();
$commands = $container->get('coddictdevextra.console')->getCommands();
//var_dump($commands);
$this->assertNotEmpty($commands);
}

public function testFindCommand()
{
$container = static::createClient()->getContainer();
$command = $container->get('coddictdevextra.console')->findCommand("cache:clear");
$this->assertNotNUll($command);
}
public function testRunCommand()
{
$container = static::createClient()->getContainer();
$output = $container->get('coddictdevextra.console')->runCommand("list",'--raw');
//printf($output->getOutput());
$this->assertNotNull($output);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class EntityManagerServiceTest extends WebTestCase
{
public function testSchemaUpdate()
{
$container = static::createClient()->getContainer();
/*$container = static::createClient()->getContainer();
$service = $container->get('coddictdevextra.entitymanager');
$this->assertTrue($service->schemaUpdate());
$this->assertTrue($service->schemaUpdate());*/
}
}
20 changes: 20 additions & 0 deletions src/Coddict/DevExtraBundle/Utils/VirtualConsoleApplication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Coddict\DevExtraBundle\Utils;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\HttpKernel\KernelInterface;

class VirtualConsoleApplication Extends Application
{
public function __construct(KernelInterface $kernel)
{
parent::__construct($kernel);
}

public function registerCommands(){
parent::registerCommands();
}
}

?>