Skip to content

Commit c48d0c2

Browse files
committed
Merge pull request #126 from phpcr/autocomplete
Improved autocomplete
2 parents 4d52a5c + ee5f9c6 commit c48d0c2

File tree

7 files changed

+73
-45
lines changed

7 files changed

+73
-45
lines changed

CHANGELOG.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@ dev-master
1010
- [node:remove] Cannot `node:remove` by UUID
1111
- [node:edit] Serialization of single value references doesn't work
1212

13-
### Features
13+
### Enhancements
1414

15-
- [query:update] Added APPLY method to queries.
16-
- [query:update] APPLY `mixin_add` and `mixin_remove` functions
17-
- [node:remove] Immediately fail when trying to delete a node which has a
18-
(hard) referrer
19-
- [cli] Specify workspace with first argument
20-
- [global] Refactored to use DI container and various general improvements
21-
- [node:property:set] Allow setting reference property type by path
15+
- [autocomplete] Autocomplete now includes command names
2216
- [references] Show UUIDs when listing reference properties
2317
- [import/export] Renamed session import and export to `session:import` &
24-
`session:export`
18+
19+
### Features
20+
21+
- [cli] Specify workspace with first argument
2522
- [config] Added user config for general settings
2623
- [config] Enable / disable showing execution times and set decimal expansion
27-
- [transport] Added transport layer for experimental Jackalope FS implementation
28-
- [node] Added wilcard support to applicable node commands, including "node:list", "node:remove" and "node:property:show"
24+
- [global] Refactored to use DI container and various general improvements
25+
- [node:property:set] Allow setting reference property type by path`session:export`
2926
- [node:references] Shows the referencing node paths instead of the referrered-to node path(s)
27+
- [node:remove] Immediately fail when trying to delete a node which has a (hard) referrer
28+
- [node] Added wilcard support to applicable node commands, including "node:list", "node:remove" and "node:property:show"
29+
- [query:update] Added APPLY method to queries, permits addition and removal of mixins
30+
- [transport] Added transport layer for experimental Jackalope FS implementation
3031

3132
alpha-6
3233
-------

src/PHPCR/Shell/Console/Application/EmbeddedApplication.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,11 @@ public function __construct($mode)
4949
*/
5050
public function init()
5151
{
52-
if (true === $this->initialized) {
53-
return;
54-
}
55-
5652
$this->registerPhpcrCommands();
5753

5854
if ($this->container->getMode() === self::MODE_SHELL) {
5955
$this->registerShellCommands();
6056
}
61-
62-
$this->initialized = true;
6357
}
6458

6559
/**

src/PHPCR/Shell/Console/Application/SessionApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct()
3030
parent::__construct(self::APP_NAME, self::APP_VERSION);
3131

3232
$container = new Container();
33-
$this->shellApplication = new ShellApplication($container);
33+
$this->shellApplication = $container->get('console.application.shell');
3434

3535
$command = new ShellCommand($this->shellApplication);
3636
$command->setApplication($this);

src/PHPCR/Shell/Console/Application/Shell.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ protected function getHeader()
103103
*/
104104
private function autocompleter($text)
105105
{
106-
$info = readline_info();
107-
$text = substr($info['line_buffer'], 0, $info['end']);
108-
$list = $this->application->getContainer()->get('phpcr.session')->autocomplete($text);
109-
106+
// the following does not work at all on my system
107+
// it only returns the previous line:
108+
//
109+
// $info = readline_info();
110+
// $text = substr($info['line_buffer'], 0, $info['end']);
111+
$list = $this->application->getContainer()->get('console.input.autocomplete')->autocomplete('');
110112
return $list;
111113
}
112114

src/PHPCR/Shell/Console/Application/ShellApplication.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@
2828
*/
2929
class ShellApplication extends Application
3030
{
31-
/**
32-
* True when application has been initialized once
33-
*
34-
* @var boolean
35-
*/
36-
protected $initialized;
37-
3831
/**
3932
* @var boolean
4033
*/
@@ -61,6 +54,7 @@ public function __construct($container)
6154
$this->dispatcher = $container->get('event.dispatcher') ? : new EventDispatcher();
6255
$this->setDispatcher($this->dispatcher);
6356
$this->container = $container;
57+
$this->init();
6458
}
6559

6660
/**
@@ -75,29 +69,16 @@ public function setShowUnsupported($boolean)
7569
}
7670

7771
/**
78-
* Initialize the application.
79-
*
80-
* Note that we do this "lazily" because we instantiate the ShellApplication early,
81-
* before the SessionInput has been set. The SessionInput must be set before we
82-
* can initialize the application.
83-
*
84-
* @todo: The above scenario is no longer true, we use a Profile. So maybe it can
85-
* be refactored.
72+
* Initialize the application
8673
*/
8774
public function init()
8875
{
89-
if (true === $this->initialized) {
90-
return;
91-
}
92-
9376
$this->registerPhpcrCommands();
9477
$this->registerPhpcrStandaloneCommands();
9578
$this->registerShellCommands();
9679

9780
$event = new ApplicationInitEvent($this);
9881
$this->dispatcher->dispatch(PhpcrShellEvents::APPLICATION_INIT, $event);
99-
100-
$this->initialized = true;
10182
}
10283

10384
/**
@@ -236,8 +217,6 @@ private function configureFormatter(OutputFormatter $formatter)
236217
*/
237218
public function doRun(InputInterface $input, OutputInterface $output)
238219
{
239-
$this->init();
240-
241220
// configure the formatter for the output
242221
$this->configureFormatter($output->getFormatter());
243222

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Input;
4+
5+
use PHPCR\Shell\Console\Application\ShellApplication;
6+
use PHPCR\Shell\Phpcr\PhpcrSession;
7+
8+
/**
9+
* Class for autocompleting commands
10+
*
11+
* @author Daniel Leech <daniel@dantleech.com>
12+
*/
13+
class AutoComplete
14+
{
15+
private $application;
16+
private $session;
17+
18+
public function __construct(ShellApplication $application, PhpcrSession $session)
19+
{
20+
$this->application = $application;
21+
$this->session = $session;
22+
}
23+
24+
public function autocomplete($text)
25+
{
26+
$list = array_keys($this->application->all());
27+
28+
$node = $this->session->getCurrentNode();
29+
30+
foreach ($node->getNodes() as $node) {
31+
$list[] = $node->getName();
32+
}
33+
34+
foreach ($node->getProperties() as $property) {
35+
$list[] = $property->getName();
36+
}
37+
38+
return $list;
39+
}
40+
}

src/PHPCR/Shell/DependencyInjection/Container.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ public function __construct($mode = self::MODE_STANDALONE)
2727
parent::__construct();
2828
$this->mode = $mode;
2929

30+
$this->set('container', $this);
31+
3032
$this->registerHelpers();
3133
$this->registerConfig();
3234
$this->registerPhpcr();
3335
$this->registerEvent();
36+
$this->registerConsole();
3437
}
3538

3639
public function registerHelpers()
@@ -143,6 +146,15 @@ public function registerEvent()
143146
}
144147
}
145148

149+
public function registerConsole()
150+
{
151+
$this->register('console.application.shell', 'PHPCR\Shell\Console\Application\ShellApplication')
152+
->addArgument(new Reference('container'));
153+
$this->register('console.input.autocomplete', 'PHPCR\Shell\Console\Input\AutoComplete')
154+
->addArgument(new Reference('console.application.shell'))
155+
->addArgument(new Reference('phpcr.session'));
156+
}
157+
146158
public function getMode()
147159
{
148160
return $this->mode;

0 commit comments

Comments
 (0)