added event cache check and tweaked middleware event

event-tweaks
n0nag0n 2 weeks ago
parent 12725eb337
commit a2c74ddadd

@ -486,7 +486,7 @@ class Engine
// Which loosely translates to $class->$method($params) // Which loosely translates to $class->$method($params)
$start = microtime(true); $start = microtime(true);
$middlewareResult = $middlewareObject($params); $middlewareResult = $middlewareObject($params);
$this->triggerEvent('flight.middleware.executed', $route, $middleware, microtime(true) - $start); $this->triggerEvent('flight.middleware.executed', $route, $middleware, $eventName, microtime(true) - $start);
if ($useV3OutputBuffering === true) { if ($useV3OutputBuffering === true) {
$this->response()->write(ob_get_clean()); $this->response()->write(ob_get_clean());
@ -1002,10 +1002,10 @@ class Engine
$this->response()->header('ETag', '"' . str_replace('"', '\"', $id) . '"'); $this->response()->header('ETag', '"' . str_replace('"', '\"', $id) . '"');
if ( $hit = isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $id;
isset($_SERVER['HTTP_IF_NONE_MATCH']) && $this->triggerEvent('flight.cache.checked', 'etag', $hit, 0.0);
$_SERVER['HTTP_IF_NONE_MATCH'] === $id
) { if ($hit === true) {
$this->response()->clear(); $this->response()->clear();
$this->halt(304, '', empty(getenv('PHPUNIT_TEST'))); $this->halt(304, '', empty(getenv('PHPUNIT_TEST')));
} }
@ -1020,10 +1020,10 @@ class Engine
{ {
$this->response()->header('Last-Modified', gmdate('D, d M Y H:i:s \G\M\T', $time)); $this->response()->header('Last-Modified', gmdate('D, d M Y H:i:s \G\M\T', $time));
if ( $hit = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $time;
isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $this->triggerEvent('flight.cache.checked', 'lastModified', $hit, 0.0);
strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $time
) { if ($hit === true) {
$this->response()->clear(); $this->response()->clear();
$this->halt(304, '', empty(getenv('PHPUNIT_TEST'))); $this->halt(304, '', empty(getenv('PHPUNIT_TEST')));
} }

@ -44,9 +44,12 @@ class EventDispatcher
* *
* @param string $event Event name * @param string $event Event name
* @param mixed ...$args Arguments to pass to the callbacks * @param mixed ...$args Arguments to pass to the callbacks
*
* @return mixed
*/ */
public function trigger(string $event, ...$args): void public function trigger(string $event, ...$args)
{ {
$result = null;
if (isset($this->listeners[$event]) === true) { if (isset($this->listeners[$event]) === true) {
foreach ($this->listeners[$event] as $callback) { foreach ($this->listeners[$event] as $callback) {
$result = call_user_func_array($callback, $args); $result = call_user_func_array($callback, $args);
@ -57,6 +60,7 @@ class EventDispatcher
} }
} }
} }
return $result;
} }
/** /**

Loading…
Cancel
Save