Skip to content

Commit

Permalink
Merge pull request #180 from dantleech/phpcr_shell_1
Browse files Browse the repository at this point in the history
Changed PHPCR Shell instantiation.
  • Loading branch information
dbu committed Jan 12, 2015
2 parents 39292c3 + 392d4de commit 2be1bef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Command/PhpcrShellCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use PHPCR\Shell\Console\Application\EmbeddedApplication;
use Symfony\Component\Console\Input\ArgvInput;
use PHPCR\Shell\Console\Input\StringInput;
use PHPCR\Shell\PhpcrSession;
use Symfony\Component\Console\Input\InputArgument;
use PHPCR\Shell\Console\Application\Shell;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use PHPCR\Shell\PhpcrShell;

/**
* Wrapper to use this command in the symfony console with multiple sessions.
Expand Down Expand Up @@ -93,20 +89,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
);

$args = $input->getArgument('cmd');
$mode = empty($args) ? EmbeddedApplication::MODE_SHELL : EmbeddedApplication::MODE_COMMAND;
$launchShell = empty($args);
$session = $this->getHelper('phpcr')->getSession();

$application = new EmbeddedApplication($mode);
$application->getHelperSet()->get('phpcr')->setSession(new PhpcrSession($session));

// If no arguments supplied, launch the shell with the embedded application
if ($mode === EmbeddedApplication::MODE_SHELL) {
$shell = new Shell($application);
$shell->run();
} else {
// else try and run the command using the given input
$application->run(new StringInput(implode(' ', $args), $output));
$session->save();
// If no arguments supplied, launch the shell uwith the embedded application
if ($launchShell) {
$shell = PhpcrShell::createEmbeddedShell($session);
$exitCode = $shell->run();

return $exitCode;
}

// else try and run the command using the given input
$application = PhpcrShell::createEmbeddedApplication($session);
$exitCode = $application->runWithStringInput(implode(' ', $args), $output);

// always save the session after running a single command
$session->save();

return $exitCode;
}
}
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"doctrine/doctrine-bundle": "when using jackalope-doctrine-dbal",
"burgov/key-value-form-bundle": "to edit assoc multivalue properties. require version 1.0.*"
},
"conflict": {
"phpcr/phpcr-shell": "<1.0.0-beta1"
},
"autoload": {
"psr-4": { "Doctrine\\Bundle\\PHPCRBundle\\": "" }
},
Expand Down

0 comments on commit 2be1bef

Please sign in to comment.