Skip to content

Commit 9515c6f

Browse files
committed
Merge pull request #83 from phpcr/no_aggregate_truncate_multivalue
Do not treat multivalue property values as a whole when truncating
2 parents 9c0c4e0 + 9fd577a commit 9515c6f

File tree

6 files changed

+38
-6
lines changed

6 files changed

+38
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ dev-master
1010
- [general] The shell supports being embedded as a dependency
1111
- [node:edit] New command `node:edit` enables editing of entire node
1212

13+
### Bug Fixes
14+
15+
- [shell] Multivalue (and so multiline) property values are truncated as a single string (#70)
16+
1317
alpha-4
1418
-------
1519

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

+8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44

55
use PhpSpec\ObjectBehavior;
66
use Prophecy\Argument;
7+
use PHPCR\Shell\Console\Helper\TextHelper;
78

89
class ResultFormatterHelperSpec extends ObjectBehavior
910
{
11+
function let(
12+
TextHelper $textHelper
13+
)
14+
{
15+
$this->beConstructedWith($textHelper);
16+
}
17+
1018
function it_is_initializable()
1119
{
1220
$this->shouldHaveType('PHPCR\Shell\Console\Helper\ResultFormatterHelper');

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,16 @@ public function init()
126126
protected function registerHelpers()
127127
{
128128
$phpcrHelper = new PhpcrHelper($this->transportRegistry, $this->profile);
129+
$textHelper = new TextHelper();
129130

130131
$helpers = array(
132+
$textHelper,
131133
new ConfigHelper(),
132134
new EditorHelper(),
133135
new NodeHelper(),
134136
new PathHelper(),
135137
new RepositoryHelper($phpcrHelper),
136-
new ResultFormatterHelper(),
137-
new TextHelper(),
138+
new ResultFormatterHelper($textHelper),
138139
new TableHelper(),
139140
$phpcrHelper
140141
);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private function renderProperties($currentNode, $table, $spacers)
173173
unset($propertyNames[$name]);
174174
}
175175

176-
$valueCell = $this->textHelper->truncate($this->formatter->formatValue($property), 55);
176+
$valueCell = $this->formatter->formatValue($property);
177177

178178
} catch (\Exception $e) {
179179
$valueCell = '<error>' . $e->getMessage() . '</error>';

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPCR\PropertyType;
1010
use PHPCR\NodeInterface;
1111
use PHPCR\PropertyInterface;
12+
use PHPCR\Shell\Console\Helper\TextHelper;
1213

1314
/**
1415
* Provide methods for formatting PHPCR objects
@@ -17,6 +18,13 @@
1718
*/
1819
class ResultFormatterHelper extends Helper
1920
{
21+
protected $textHelper;
22+
23+
public function __construct(TextHelper $textHelper)
24+
{
25+
$this->textHelper = $textHelper;
26+
}
27+
2028
/**
2129
* {@inheritDoc}
2230
*/
@@ -87,7 +95,7 @@ public function normalizeValue($value)
8795
} else {
8896
$value = $value;
8997
}
90-
$value = '[' . $i . '] ' . $value;
98+
$value = '[' . $i . '] ' . $this->textHelper->truncate($value);
9199
$values[] = $value;
92100
}
93101

@@ -98,7 +106,7 @@ public function normalizeValue($value)
98106
return $value->format('c');
99107
}
100108

101-
return $value;
109+
return $this->textHelper->truncate($value);
102110
}
103111

104112
public function formatValue(PropertyInterface $value, $showBinary = false)
@@ -133,6 +141,7 @@ public function formatValue(PropertyInterface $value, $showBinary = false)
133141
return $value->getValue()->getIdentifier();
134142
case PropertyType::URI :
135143
case PropertyType::STRING :
144+
return $this->textHelper->truncate($value->getValue());
136145
case PropertyType::NAME :
137146
case PropertyType::LONG :
138147
case PropertyType::DOUBLE :

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
*/
1212
class TextHelper extends Helper
1313
{
14+
/**
15+
* @todo: Make this configurable
16+
* @var integer
17+
*/
18+
protected $truncateLength = 75;
19+
1420
/**
1521
* {@inheritDoc}
1622
*/
@@ -29,8 +35,12 @@ public function getName()
2935
*
3036
* @return string
3137
*/
32-
public function truncate($string, $length, $alignment = null, $delimString = null)
38+
public function truncate($string, $length = null, $alignment = null, $delimString = null)
3339
{
40+
if (null === $length) {
41+
$length = $this->truncateLength;
42+
}
43+
3444
$alignment = $alignment === null ? 'left' : $alignment;
3545
$delimString = $delimString === null ? '...' : $delimString;
3646
$delimLen = strlen($delimString);

0 commit comments

Comments
 (0)