diff --git a/src/main/php/web/Application.class.php b/src/main/php/web/Application.class.php index ac746cd7..fb404239 100755 --- a/src/main/php/web/Application.class.php +++ b/src/main/php/web/Application.class.php @@ -38,6 +38,16 @@ public final function routing() { return $this->routing; } + /** + * Initializes this application, being run once when the server starts. + * Empty in this default implementation, overwrite in subclasses. + * + * @return void + */ + public function initialize() { + // Empty + } + /** * Returns this application's routes, which are either a `Routing` * instance or a map of paths to routing targets. diff --git a/src/main/php/xp/web/srv/Develop.class.php b/src/main/php/xp/web/srv/Develop.class.php index fdc2dc0b..26a1d7d4 100755 --- a/src/main/php/xp/web/srv/Develop.class.php +++ b/src/main/php/xp/web/srv/Develop.class.php @@ -5,7 +5,8 @@ use lang\{ClassLoader, CommandLine, FileSystemClassLoader, Runtime, RuntimeOptions}; use peer\Socket; use util\cmd\Console; -use web\Logging; +use web\{Application, Environment, Logging}; +use xp\web\Source; class Develop extends Server { @@ -21,6 +22,9 @@ class Develop extends Server { * @param string[] $logging */ public function serve($source, $profile, $webroot, $docroot, $config, $args, $logging) { + $environment= new Environment($profile, $webroot, $docroot, $config, $args, $logging); + $application= (new Source($source, $environment))->application($args); + $application->initialize(); // PHP doesn't start with a nonexistant document root if (!$docroot->exists()) { @@ -60,9 +64,8 @@ public function serve($source, $profile, $webroot, $docroot, $config, $args, $lo putenv('WEB_LOG='.$logging); Console::writeLine("\e[33m@", nameof($this), "(HTTP @ `php ", implode(' ', $arguments), "`)\e[0m"); - Console::writeLine("\e[1mServing {$profile}:", $source, $config, "\e[0m > ", Logging::of($logging)->target()); + Console::writeLine("\e[1mServing {$profile}:", $application, $config, "\e[0m > ", $environment->logging()->target()); Console::writeLine("\e[36m", str_repeat('═', 72), "\e[0m"); - Console::writeLine(); if ('WINDOWS' === $os->name()) { $nul= 'NUL'; diff --git a/src/main/php/xp/web/srv/Standalone.class.php b/src/main/php/xp/web/srv/Standalone.class.php index a060127d..8d5a2349 100755 --- a/src/main/php/xp/web/srv/Standalone.class.php +++ b/src/main/php/xp/web/srv/Standalone.class.php @@ -56,6 +56,7 @@ public function __construct($address, $impl) { public function serve($source, $profile, $webroot, $docroot, $config, $args, $logging) { $environment= new Environment($profile, $webroot, $docroot, $config, $args, $logging); $application= (new Source($source, $environment))->application($args); + $application->initialize(); $application->routing(); $socket= new ServerSocket($this->host, $this->port); diff --git a/src/test/php/web/unittest/ResponseTest.class.php b/src/test/php/web/unittest/ResponseTest.class.php index 31dc5c56..20873dee 100755 --- a/src/test/php/web/unittest/ResponseTest.class.php +++ b/src/test/php/web/unittest/ResponseTest.class.php @@ -119,7 +119,7 @@ public function overwrite_cookie() { $res= new Response(new TestOutput()); $res->cookie(new Cookie('theme', 'light')); $res->cookie(new Cookie('theme', 'dark')); - $this->assertEquals(['dark'], array_map(function($c) { return $c->value(); }, $res->cookies())); + Assert::equals(['dark'], array_map(function($c) { return $c->value(); }, $res->cookies())); } #[Test] @@ -127,7 +127,7 @@ public function append_cookie() { $res= new Response(new TestOutput()); $res->cookie(new Cookie('theme', 'light')); $res->cookie(new Cookie('theme', 'dark'), true); - $this->assertEquals(['light', 'dark'], array_map(function($c) { return $c->value(); }, $res->cookies())); + Assert::equals(['light', 'dark'], array_map(function($c) { return $c->value(); }, $res->cookies())); } #[Test]