Skip to content

Commit 64573c5

Browse files
committed
Bug fixes on pipe execution
* The beforeExecute middleware is executed before anything. * Middlewares of base pipes are propagated to subpipes.
1 parent 1acea20 commit 64573c5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/WaterPipe/WaterPipe.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,15 @@ public function run()
310310
if ($pipe === null) {
311311
$this->_executeRequest();
312312
} else {
313-
// Propagate errors registry only
313+
// Propagate errors registry
314314
foreach ($this->_errorsRegistry as $code => $action)
315315
if (!isset($pipe[1]->_errorsRegistry[$code]))
316-
$pipe[1]->_errorsRegistry[$code] = $action;
316+
$pipe[1]->error($code, $action);
317+
318+
// Propagate middlewares registry
319+
foreach ($this->_middlewareRegistry as $middleware)
320+
if (!in_array($middleware, $pipe[1]->_middlewareRegistry))
321+
$pipe[1]->use($middleware);
317322

318323
$pipe[1]->_runBase($pipe[0]);
319324
}
@@ -345,6 +350,9 @@ private function _findSubPipe()
345350

346351
private function _executeRequest()
347352
{
353+
// Execute middleware
354+
self::triggerBeforeExecuteEvent(Request::getInstance());
355+
348356
$registry = null;
349357

350358
switch (Request::getInstance()->getMethod()) {
@@ -391,9 +399,6 @@ private function _executeRequest()
391399
throw new \Exception("Malformed route action");
392400
}
393401

394-
// Execute middleware
395-
self::triggerBeforeExecuteEvent(Request::getInstance());
396-
397402
// NOTE: No code will be executed after this call...
398403
$this->_executeAction($runner);
399404
}

0 commit comments

Comments
 (0)