Skip to content

Commit a4ef324

Browse files
committed
User config and profiling
- Enable setting expansion for timings - Enableable timing for query / traversal - Config is automatically based with dist config
1 parent 3b4823c commit a4ef324

File tree

14 files changed

+211
-39
lines changed

14 files changed

+211
-39
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ dev-master
55
----------
66

77
- [references] Show UUIDs when listing reference properties
8+
- [import/export] Renamed session import and export to `session:import` &
9+
`session:export`
10+
- [config] Added user config for general settings
11+
- [config] Enable / disable showing execution times and set decimal expansion
812
- [transport] Added transport layer for experimental Jackalope FS implementation
913
- [misc] Wildcard (single asterisk) support in paths
1014
- [node] Added wilcard support to applicable node commands, including "node:list", "node:remove" and "node:property:show"

features/all/phpcr_session_export_view.feature renamed to features/all/phpcr_session_export.feature

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
Feature: Export the repository to an XML file
22
In order to export the repository (or part of the repository) to an XML file
33
As a user that is logged into the shell
4-
I want to be able to "session:export:view" command to export the repository to an XML file.
4+
I want to be able to "session:export" command to export the repository to an XML file.
55

66
Background:
77
Given that I am logged in as "testuser"
88
And the file "foobar.xml" does not exist
99
And the "session_data.xml" fixtures are loaded
1010

1111
Scenario: Export the root
12-
Given I execute the "session:export:view / foobar.xml" command
12+
Given I execute the "session:export / foobar.xml" command
1313
Then the command should not fail
1414
And the file "foobar.xml" should exist
1515
And the xpath count "/sv:node" is "1" in file "foobar.xml"
1616
And the xpath count "/sv:node/sv:node" is "1" in file "foobar.xml"
1717

1818
Scenario: Export a subtree
19-
Given I execute the "session:export:view /tests_general_base foobar.xml" command
19+
Given I execute the "session:export /tests_general_base foobar.xml" command
2020
Then the file "foobar.xml" should exist
2121
And the command should not fail
2222

2323
Scenario: Export with an invalid path
24-
Given I execute the "session:export:view cms foobar.xml" command
24+
Given I execute the "session:export cms foobar.xml" command
2525
Then the command should fail
2626
And the output should contain:
2727
"""
@@ -30,26 +30,26 @@ Feature: Export the repository to an XML file
3030

3131
Scenario: Export to an existing file (should overwrite as --no-interaction is specified)
3232
Given the file "foobar.xml" exists
33-
And I execute the "session:export:view /tests_general_base foobar.xml --no-interaction" command
33+
And I execute the "session:export /tests_general_base foobar.xml --no-interaction" command
3434
Then the command should not fail
3535

3636
Scenario: Export non recursive
37-
Given I execute the "session:export:view /tests_general_base foobar.xml --no-recurse" command
37+
Given I execute the "session:export /tests_general_base foobar.xml --no-recurse" command
3838
Then the command should not fail
3939
And the file "foobar.xml" should exist
4040
And the xpath count "/sv:node" is "1" in file "foobar.xml"
4141
And the xpath count "/sv:node/sv:node" is "0" in file "foobar.xml"
4242

4343
Scenario: Export and skip binaries
44-
Given I execute the "session:export:view / foobar.xml --skip-binary" command
44+
Given I execute the "session:export / foobar.xml --skip-binary" command
4545
Then the command should not fail
4646

4747
Scenario: Export the document view
48-
Given I execute the "session:export:view / foobar.xml --document" command
48+
Given I execute the "session:export / foobar.xml --document" command
4949
Then the command should not fail
5050

5151
Scenario: Export the document view in pretty way
52-
Given I execute the "session:export:view / foobar.xml --pretty" command
52+
Given I execute the "session:export / foobar.xml --pretty" command
5353
Then the command should not fail
5454
And the file "foobar.xml" should exist
5555
And the xpath count "/sv:node" is "1" in file "foobar.xml"

spec/PHPCR/Shell/Config/ConfigManagerSpec.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ public function it_should_be_able_to_parse_a_config_file_and_return_the_config_a
3434
putenv('PHPCRSH_HOME=' . $dir);
3535
$filesystem->exists(Argument::any())->willReturn(true);
3636

37-
$this->getConfig('alias')->shouldReturn(array(
38-
'foobar' => 'barfoo',
39-
'barfoo' => 'foobar',
40-
));
41-
37+
$this->getConfig('alias')->offsetGet('foobar')->shouldReturn('barfoo');
38+
$this->getConfig('alias')->offsetGet('barfoo')->shouldReturn('foobar');
4239
}
4340
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Config;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
8+
class ConfigSpec extends ObjectBehavior
9+
{
10+
function it_is_initializable()
11+
{
12+
$this->shouldHaveType('PHPCR\Shell\Config\Config');
13+
}
14+
15+
function let()
16+
{
17+
$this->beConstructedWith(array(
18+
'foo' => 'bar',
19+
'bar' => array(
20+
'boo' => 'baz'
21+
),
22+
));
23+
}
24+
25+
function it_should_be_able_to_access_data_values()
26+
{
27+
$this['foo']->shouldReturn('bar');
28+
}
29+
30+
function it_should_be_able_to_access_nested_config()
31+
{
32+
$this['bar']['boo']->shouldReturn('baz');
33+
}
34+
}

spec/PHPCR/Shell/Console/Helper/ResultFormatterHelperSpec.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
use PhpSpec\ObjectBehavior;
66
use PHPCR\Shell\Console\Helper\TextHelper;
77
use PHPCR\Shell\Console\Helper\TableHelper;
8+
use PHPCR\Shell\Config\Config;
89

910
class ResultFormatterHelperSpec extends ObjectBehavior
1011
{
1112
public function let(
1213
TextHelper $textHelper,
13-
TableHelper $tableHelper
14+
TableHelper $tableHelper,
15+
Config $config
1416
)
1517
{
16-
$this->beConstructedWith($textHelper, $tableHelper);
18+
$this->beConstructedWith($textHelper, $tableHelper, $config);
1719
}
1820

1921
public function it_is_initializable()

src/PHPCR/Shell/Config/Config.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Config;
4+
5+
/**
6+
* Configuration profile object
7+
*/
8+
class Config implements \ArrayAccess, \Iterator
9+
{
10+
private $data;
11+
12+
public function __construct($data)
13+
{
14+
$this->data = $data;
15+
}
16+
17+
public function offsetSet($offset, $value)
18+
{
19+
throw new \InvalidArgumentException(sprintf(
20+
'Setting values not permitted on configuration objects (trying to set "%s" to "%s"',
21+
$offset, $value
22+
));
23+
}
24+
25+
public function offsetExists($offset)
26+
{
27+
return isset($this->data[$offset]);
28+
}
29+
30+
public function offsetUnset($offset)
31+
{
32+
unset($this->data[$offset]);
33+
}
34+
35+
public function offsetGet($offset)
36+
{
37+
if (isset($this->data[$offset])) {
38+
$value = $this->data[$offset];
39+
if (is_array($value)) {
40+
return new self($value);
41+
} else {
42+
return $value;
43+
}
44+
}
45+
}
46+
47+
public function current()
48+
{
49+
return current($this->data);
50+
}
51+
52+
public function key()
53+
{
54+
return key($this->data);
55+
}
56+
57+
public function next()
58+
{
59+
return next($this->data);
60+
}
61+
62+
public function rewind()
63+
{
64+
return reset($this->data);
65+
}
66+
67+
public function valid()
68+
{
69+
return current($this->data);
70+
}
71+
}

src/PHPCR/Shell/Config/ConfigManager.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Symfony\Component\Yaml\Yaml;
66
use Symfony\Component\Console\Output\OutputInterface;
77
use Symfony\Component\Filesystem\Filesystem;
8+
use PHPCR\Shell\Config\Config;
89

910
/**
1011
* Configuration manager
@@ -20,7 +21,8 @@ class ConfigManager
2021
* @var array
2122
*/
2223
protected $configKeys = array(
23-
'alias'
24+
'alias',
25+
'phpcrsh',
2426
);
2527

2628
/**
@@ -114,11 +116,24 @@ public function loadConfig()
114116
$fullDistPath = $distConfigDir . '/' . $configKey . '.yml';
115117
$config[$configKey] = array();
116118

119+
$userConfig = array();
117120
if ($this->filesystem->exists($fullPath)) {
118-
$config[$configKey] = Yaml::parse(file_get_contents($fullPath));
119-
} elseif ($this->filesystem->exists($fullDistPath)) {
120-
$config[$configKey] = Yaml::parse(file_get_contents($fullDistPath));
121+
$userConfig = Yaml::parse(file_get_contents($fullPath));
121122
}
123+
124+
if ($this->filesystem->exists($fullDistPath)) {
125+
$distConfig = Yaml::parse(file_get_contents($fullDistPath));
126+
} else {
127+
throw new \RuntimeException(sprintf(
128+
'Could not find dist config at path (%s)',
129+
$fullDistPath
130+
));
131+
}
132+
133+
$config[$configKey] = new Config(array_merge(
134+
$distConfig,
135+
$userConfig
136+
));
122137
}
123138

124139
$this->cachedConfig = $config;
@@ -142,6 +157,11 @@ public function getConfig($type)
142157
return $this->cachedConfig[$type];
143158
}
144159

160+
public function getPhpcrshConfig()
161+
{
162+
return $this->getConfig('phpcrsh');
163+
}
164+
145165
/**
146166
* Initialize a configuration files
147167
*/
@@ -167,6 +187,7 @@ public function initConfig(OutputInterface $output = null, $noInteraction = fals
167187

168188
$configFilenames = array(
169189
'alias.yml',
190+
'phpcrsh.yml',
170191
);
171192

172193
foreach ($configFilenames as $configFilename) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ protected function registerPhpcrCommands()
108108
// phpcr commands
109109
$this->add(new CommandPhpcr\AccessControlPrivilegeListCommand());
110110
$this->add(new CommandPhpcr\RepositoryDescriptorListCommand());
111-
$this->add(new CommandPhpcr\SessionExportViewCommand());
111+
$this->add(new CommandPhpcr\SessionExportCommand());
112112
$this->add(new CommandPhpcr\SessionImpersonateCommand());
113-
$this->add(new CommandPhpcr\SessionImportXMLCommand());
113+
$this->add(new CommandPhpcr\SessionImportCommand());
114114
$this->add(new CommandPhpcr\SessionInfoCommand());
115115
$this->add(new CommandPhpcr\SessionNamespaceListCommand());
116116
$this->add(new CommandPhpcr\SessionNamespaceSetCommand());

src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class NodeListCommand extends BasePhpcrCommand
1717
protected $formatter;
1818
protected $textHelper;
1919
protected $maxLevel;
20+
protected $time;
21+
protected $nbNodes;
2022

2123
protected function configure()
2224
{
@@ -54,6 +56,10 @@ public function execute(InputInterface $input, OutputInterface $output)
5456
$this->showChildren = $input->getOption('children');
5557
$this->showProperties = $input->getOption('properties');
5658
$this->showTemplate = $input->getOption('template');
59+
$this->time = 0;
60+
$this->nbNodes = 0;
61+
62+
$config = $this->get('config.config.phpcrsh');
5763

5864
$session = $this->get('phpcr.session');
5965
$path = $input->getArgument('path');
@@ -70,7 +76,10 @@ public function execute(InputInterface $input, OutputInterface $output)
7076
$filter = substr($filter, 1);
7177
}
7278

79+
80+
$start = microtime(true);
7381
$nodes = $session->findNodes($parentPath);
82+
$this->time = microtime(true) - $start;
7483
}
7584

7685
if (!$this->showChildren && !$this->showProperties) {
@@ -88,10 +97,18 @@ public function execute(InputInterface $input, OutputInterface $output)
8897
}
8998
}
9099

100+
if ($config['show_execution_time_list']) {
101+
$output->writeln(sprintf(
102+
'%s nodes in set (%s sec)',
103+
$this->nbNodes,
104+
number_format($this->time, $config['execution_time_expansion']))
105+
);
106+
}
91107
}
92108

93109
private function renderNode($currentNode, $table, $spacers = array(), $filter = null)
94110
{
111+
$this->nbNodes++;
95112
if ($this->showChildren) {
96113
$this->renderChildren($currentNode, $table, $spacers, $filter);
97114
}
@@ -103,7 +120,9 @@ private function renderNode($currentNode, $table, $spacers = array(), $filter =
103120

104121
private function renderChildren($currentNode, $table, $spacers, $filter = null)
105122
{
123+
$start = microtime(true);
106124
$children = $currentNode->getNodes($filter ? : null);
125+
$this->time += microtime(true) - $start;
107126

108127
$nodeType = $currentNode->getPrimaryNodeType();
109128
$childNodeDefinitions = $nodeType->getDeclaredChildNodeDefinitions();

src/PHPCR/Shell/Console/Command/Phpcr/SessionExportViewCommand.php renamed to src/PHPCR/Shell/Console/Command/Phpcr/SessionExportCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
use Symfony\Component\Console\Input\InputOption;
1010
use PHPCR\Util\PathHelper;
1111

12-
class SessionExportViewCommand extends BasePhpcrCommand
12+
class SessionExportCommand extends BasePhpcrCommand
1313
{
1414
protected function configure()
1515
{
16-
$this->setName('session:export:view');
17-
$this->setDescription('Export the system view');
16+
$this->setName('session:export');
17+
$this->setDescription('Export the to XML');
1818
$this->addArgument('absPath', InputArgument::REQUIRED, 'Path of node to export');
1919
$this->addArgument('file', InputArgument::REQUIRED, 'File to export to');
2020
$this->addOption('no-recurse', null, InputOption::VALUE_NONE, 'Do not recurse');

src/PHPCR/Shell/Console/Command/Phpcr/SessionImportXMLCommand.php renamed to src/PHPCR/Shell/Console/Command/Phpcr/SessionImportCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Symfony\Component\Console\Input\InputOption;
1010
use PHPCR\Util\PathHelper;
1111

12-
class SessionImportXMLCommand extends BasePhpcrCommand
12+
class SessionImportCommand extends BasePhpcrCommand
1313
{
1414
protected $uuidBehaviors = array(
1515
'create-new',
@@ -20,10 +20,10 @@ class SessionImportXMLCommand extends BasePhpcrCommand
2020

2121
protected function configure()
2222
{
23-
$this->setName('session:import-xml');
23+
$this->setName('session:import');
2424
$this->setDescription('Import content from an XML file');
2525
$this->addArgument('parentAbsPath', InputArgument::REQUIRED, 'Path of node to export');
26-
$this->addArgument('file', InputArgument::REQUIRED, 'File to export to');
26+
$this->addArgument('file', InputArgument::REQUIRED, 'File to import from');
2727
$this->addOption('uuid-behavior', null, InputOption::VALUE_REQUIRED, 'UUID behavior', 'create-new');
2828
$this->setHelp(<<<HERE
2929
Deserializes an XML document and adds the resulting item subgraph as a

0 commit comments

Comments
 (0)