@@ -27,21 +27,34 @@ public function __construct(Environment $environment) {
2727 */
2828 public abstract function routes ($ environment );
2929
30- /** @return web.Routing */
31- protected final function routing () {
32- $ routes = $ this -> routes ( new WebEnv (
30+ /** @return web.Application */
31+ protected final function application () {
32+ $ env = new WebEnv (
3333 $ this ->environment ->variable ('PROFILE ' ) ?? 'prod ' ,
3434 $ this ->environment ->root ,
3535 $ this ->environment ->path ('static ' ),
3636 [$ this ->environment ->properties ],
3737 [],
3838 $ this ->tracing
39- ));
39+ );
40+ $ routes = $ this ->routes ($ env );
4041
4142 // Check for `xp-forge/web ^4.0` applications, which provide an initializer
42- if ($ routes instanceof Application && method_exists ($ routes , 'initialize ' )) {
43- $ routes ->initialize ();
43+ if ($ routes instanceof Application) {
44+ method_exists ($ routes , 'initialize ' ) && $ routes ->initialize ();
45+ return $ routes ;
4446 }
45- return Routing::cast ($ routes );
47+
48+ // Wrap routes inside an application to ensure application-level functionality
49+ return new class ($ env , $ routes ) extends Application {
50+ private $ routes ;
51+
52+ public function __construct ($ env , $ routes ) {
53+ parent ::__construct ($ env );
54+ $ this ->routes = $ routes ;
55+ }
56+
57+ public function routes () { return $ this ->routes ; }
58+ };
4659 }
4760}
0 commit comments