Skip to content

Commit 4631a0b

Browse files
committed
Updated to use table helper for result set formatting
1 parent a9bb2b1 commit 4631a0b

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

bin/phpcrsh renamed to bin/phpcr

File renamed without changes.

box.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"alias": "phpcrsh.phar",
2+
"alias": "phpcr.phar",
33
"chmod": "0755",
44
"directories": ["src"],
55
"files": [
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"git-version": "package_version",
16-
"main": "bin/phpcrsh",
17-
"output": "phpcrsh.phar",
16+
"main": "bin/phpcr",
17+
"output": "phpcr.phar",
1818
"stub": true
1919
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "dantleech/phpcrsh",
33
"description": "Shell for PHPCR",
44
"require": {
5-
"symfony/console": "2.1.*",
5+
"symfony/console": "2.3.*",
66
"jackalope/jackalope-doctrine-dbal": "dev-master",
77
"jackalope/jackalope-jackrabbit": "dev-master",
88
"jackalope/jackalope": "dev-master",

src/PHPCR/Shell/Console/Helper/ResultFormatterHelper.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPCR\Shell\Console\Helper;
44

55
use Symfony\Component\Console\Helper\Helper;
6+
use Symfony\Component\Console\Helper\TableHelper;
67
use PHPCR\Query\QueryResultInterface;
78
use Symfony\Component\Console\Output\OutputInterface;
89
use PHPCR\PropertyType;
@@ -20,27 +21,32 @@ public function format(QueryResultInterface $result, OutputInterface $output, $e
2021
$selectorNames = $result->getSelectorNames();
2122

2223
foreach ($result->getRows() as $i => $row) {
23-
$output->writeln(sprintf('%s ----', $i + 1));
24+
$output->writeln(sprintf($str = '| <info>Row:</info> #%d <info>Score:</info> %d',
25+
$i, $row->getScore()
26+
));
27+
2428
foreach ($selectorNames as $selectorName) {
2529
$node = $row->getNode($selectorName);
2630
$properties = $node->getProperties();
27-
$output->writeln(sprintf(
28-
' [%s] [path:<comment>%s</comment>] [uid:<info>%s</info>]',
31+
$output->writeln(sprintf('| <info>selector:</info> %s <info>path:</info> %s <info>uid:</info> %s',
2932
$selectorName, $node->getPath(), $node->getIdentifier()
3033
));
3134

35+
$table = new TableHelper;
36+
$table->setHeaders(array('Name', 'Type', 'Multiple', 'Value'));
3237
foreach ($properties as $key => $value) {
33-
$output->writeln(sprintf(' <info>%s</info> <fg=magenta>%s%s</fg=magenta>: %s',
38+
$table->addRow(array(
3439
$key,
3540
PropertyType::nameFromValue($value->getType()),
36-
$value->isMultiple() ? '[]' : '',
41+
$value->isMultiple() ? 'yes' : 'no',
3742
$this->formatValue($value)
3843
));
3944
}
45+
$table->render($output);
4046
}
47+
$output->writeln('');
4148
}
4249

43-
$output->writeln('');
4450
$output->writeln(sprintf('%s rows in set (%s sec)', count($result->getRows()), number_format($elapsed, 2)));
4551
}
4652

@@ -53,17 +59,19 @@ protected function formatValue($value)
5359
$array = $value;
5460
$values = array();
5561

56-
foreach ($array->getValue() as $value) {
62+
foreach ($array->getValue() as $i => $value) {
5763
if ($value instanceof NodeInterface) {
58-
$values[] = $value->getPath();
64+
$value = $value->getPath();
5965
} else if (is_object($value)) {
60-
$values[] = '<UNKNOWN OBJECT>';
66+
$value = '<UNKNOWN OBJECT>';
6167
} else {
62-
$values[] = $value;
68+
$value = $value;
6369
}
70+
$value = '[' . $i . '] ' . $value;
71+
$values[] = $value;
6472
}
6573

66-
return "\n - " . implode("\n - ", $values);
74+
return implode("\n", $values);
6775
}
6876

6977
switch (intval($value->getType())) {

0 commit comments

Comments
 (0)