Skip to content
Merged
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
45 changes: 33 additions & 12 deletions src/PHPCR/Shell/Console/Application/ShellApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use PHPCR\Shell\Console\Command\WorkspaceNamespaceListCommand;
use PHPCR\Shell\Console\Command\WorkspaceNamespaceRegisterCommand;
use PHPCR\Shell\Console\Command\WorkspaceNamespaceUnregisterCommand;
use PHPCR\Shell\Console\Command\WorkspaceUseCommand;
use PHPCR\Shell\Console\Command\NodeTypeShowCommand;
use PHPCR\Shell\Console\Helper\EditorHelper;
use PHPCR\Shell\Console\Command\NodeTypeEditCommand;
Expand Down Expand Up @@ -91,10 +92,14 @@
class ShellApplication extends Application
{
protected $transports;
protected $credentials;
protected $initialized;
protected $sessionInput;

/**
* @var SessionInterface
*/
private $session;

/**
* Input from the shell command, containing the connection
* parameters etc.
Expand Down Expand Up @@ -156,6 +161,7 @@ public function init()
$this->add(new WorkspaceNamespaceListCommand());
$this->add(new WorkspaceNamespaceRegisterCommand());
$this->add(new WorkspaceNamespaceUnregisterCommand());
$this->add(new WorkspaceUseCommand());
$this->add(new NodeTypeShowCommand());
$this->add(new NodeTypeEditCommand());
$this->add(new NodeTypeUnregisterCommand());
Expand Down Expand Up @@ -219,31 +225,46 @@ public function init()
->setName('workspace-purge')
);

$session = $this->getSession($this->sessionInput);
$this->initSession();

$this->getHelperSet()->set(new EditorHelper($session));
$this->getHelperSet()->set(new EditorHelper($this->session));
$this->getHelperSet()->set(new PhpcrConsoleDumperHelper());
$this->getHelperSet()->set(new PhpcrHelper($session));
$this->getHelperSet()->set(new PhpcrHelper($this->session));
$this->getHelperSet()->set(new ResultFormatterHelper());
$this->getHelperSet()->set(new TextHelper());
$this->getHelperSet()->set(new NodeHelper($session));
$this->getHelperSet()->set(new NodeHelper($this->session));

$this->initialized = true;
}

private function getSession($input)
private function initSession()
{
$transport = $this->getTransport($input);
$transport = $this->getTransport($this->sessionInput);
$repository = $transport->getRepository();
$credentials = new SimpleCredentials(
$input->getOption('phpcr-username'),
$input->getOption('phpcr-password')
$this->sessionInput->getOption('phpcr-username'),
$this->sessionInput->getOption('phpcr-password')
);

$session = $repository->login($credentials, $input->getOption('phpcr-workspace'));
$session = new PhpcrSession($session);
$session = $repository->login($credentials, $this->sessionInput->getOption('phpcr-workspace'));

return $session;
if (!$this->session) {
$this->session = new PhpcrSession($session);
} else {
$this->session->setPhpcrSession($session);
}
}

/**
* Change the current workspace
*
* @param string $workspaceName
*/
public function changeWorkspace($workspaceName)
{
$this->session->logout();
$this->sessionInput->setOption('phpcr-workspace', $workspaceName);
$this->initSession($this->sessionInput);
}

private function getTransport(InputInterface $input)
Expand Down
12 changes: 9 additions & 3 deletions src/PHPCR/Shell/Console/Command/WorkspaceListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected function configure()
$this->setHelp(<<<HERE
Lists the workspaces accessible to the current user.

The current workspace is indicated by an asterix (*).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asterix -> asterisk


Lists the names of all workspaces in this
repository that are accessible to this user, given the Credentials that
were used to get the Session to which this Workspace is tied.
Expand All @@ -31,12 +33,16 @@ public function execute(InputInterface $input, OutputInterface $output)
{
$session = $this->getHelper('phpcr')->getSession();

$workspaces = $session->getWorkspace()->getAccessibleWorkspaceNames();
$workspace = $session->getWorkspace();
$availableWorkspaces = $workspace->getAccessibleWorkspaceNames();

$table = clone $this->getHelper('table');
$table->setHeaders(array('Name'));
foreach ($workspaces as $workspace) {
$table->addRow(array($workspace));
foreach ($availableWorkspaces as $availableWorkspace) {
if ($availableWorkspace == $workspace->getName()) {
$availableWorkspace .= ' *';
}
$table->addRow(array($availableWorkspace));
}

$table->render($output);
Expand Down
29 changes: 29 additions & 0 deletions src/PHPCR/Shell/Console/Command/WorkspaceUseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no metaheaders? we need the Gush command finished 👶

namespace PHPCR\Shell\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;

class WorkspaceUseCommand extends Command
{
protected function configure()
{
$this->setName('workspace:use');
$this->setDescription('Change the current workspace');
$this->addArgument('name', InputArgument::REQUIRED, 'Name of workspace to use');
$this->addArgument('srcWorkspace', InputArgument::OPTIONAL, 'If specified, clone from this workspace');
$this->setHelp(<<<HERE
Change the workspace.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think you want to leave a line break aways since that will look better

HERE
);
}

public function execute(InputInterface $input, OutputInterface $output)
{
$workspaceName = $input->getArgument('name');
$this->getApplication()->changeWorkspace($workspaceName);
}
}
21 changes: 16 additions & 5 deletions src/PHPCR/Shell/PhpcrSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ class PhpcrSession implements SessionInterface
protected $session;
protected $cwd = '/';

public function __construct(SessionInterface $session)
{
$this->session = $session;
}

/**
* Allow underlying session to be changed
* For example when changing workspaces
*
* @param SessionInterface $session
*/
public function setPhpcrSession(SessionInterface $session)
{
$this->session = $session;
}

public function getCurrentNode()
{
return $this->getNode($this->getCwd());
Expand Down Expand Up @@ -121,11 +137,6 @@ public function getAbsPaths($paths)
return $newPaths;
}

public function __construct(SessionInterface $session)
{
$this->session = $session;
}

public function getRepository()
{
return $this->session->getRepository();
Expand Down