In essence, each of our page scripts follows this organizational flow:
Generic Page Script
1 <?php
2 // one or more identical setup scripts
3 require 'setup.php';
4
5 // a series of dependencies to build a controller
6 $request = new \Mlaphp\Request($GLOBALS);
7 $response = new \Mlaphp\Response('/path/to/app/views');
8 $controller = new \Controller\PageName($request, $response);
9
10 // invoke the controller and send the response
11 $response = $controller->__invoke();
12 $response->send();
13 ?>
Because we have been diligent about always using the same variable name for our controller object ($controller
), always using the same method name for invoking it (__invoke()
), and always using the same variable name for the response ($response
), we can see that the only part of each page script that is different is the central section. That central block builds the controller object. Everything before and after is identical.