Skip to content

Commit c5223ef

Browse files
committed
Merge pull request #88 from phpcr/allow_real_closure
Enable an actual closure to be passed to CliHelper apply-closures
2 parents 7003ffb + cf6a576 commit c5223ef

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/PHPCR/Util/Console/Helper/PhpcrCliHelper.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,20 @@ public function processNode(OutputInterface $output, $node, $options)
116116
$node->removeMixin($removeMixin);
117117
}
118118

119-
foreach ($options['applyClosures'] as $closureString) {
120-
$closure = create_function('$session, $node', $closureString);
121-
$output->writeln(sprintf(
122-
'<comment> > Applying closure: %s</comment>',
123-
strlen($closureString) > 75 ? substr($closureString, 0, 72).'...' : $closureString
124-
));
119+
foreach ($options['applyClosures'] as $closure) {
120+
if ($closure instanceof \Closure) {
121+
$output->writeln(
122+
'<comment> > Applying closure</comment>'
123+
);
124+
} else {
125+
$closureString = $closure;
126+
$closure = create_function('$session, $node', $closure);
127+
$output->writeln(sprintf(
128+
'<comment> > Applying closure: %s</comment>',
129+
strlen($closureString) > 75 ? substr($closureString, 0, 72).'...' : $closureString
130+
));
131+
}
132+
125133
$closure($this->session, $node);
126134
}
127135

tests/PHPCR/Tests/Util/Console/Command/NodesUpdateCommandTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,16 @@ public function testApplyClosure()
143143
'--query' => "SELECT foo FROM bar",
144144
'--no-interaction' => true,
145145
'--apply-closure' => array(
146-
'$session->getNodeByIdentifier("/foo"); $node->setProperty("foo", "bar");'
146+
'$session->getNodeByIdentifier("/foo"); $node->setProperty("foo", "bar");',
147+
function ($session, $node) {
148+
$node->setProperty('foo', 'bar');
149+
}
147150
),
148151
);
149152

150153
$this->setupQueryManager(array('query' => 'SELECT foo FROM bar'));
151154

152-
$this->node1->expects($this->once())
155+
$this->node1->expects($this->exactly(2))
153156
->method('setProperty')
154157
->with('foo', 'bar');
155158

0 commit comments

Comments
 (0)