Create your own framework

this abstract application knows about Request, Response, MiddlewareBulder(relay), so you have to write your application logic in methods(container, middleware, route and response methods) of your extends application class. these methods are executed by run() method.

response

In response method, you have to pass your controller callable handler to $this->addQueue('action', $handler, $args).
it is different how to get $handler, because it depends on your selected router library.

License

We can use anonymous classes in PHP7. So I use anonymous classes instead of anonymous functions.
Slim3 now supports PSR-7 interfaces for its Request and Response objects. And Slim3 uses extends objects, and use it in your anonymous functions.

But we use Request and Response object directly, so I try to use anonymous classes to write controller action logic and it is to be readability.

You have to write your controller logic in action method, this action method call when this route is matched.
You don't need to use Request and Response objects directly but access with Controller class.

The more you write your routes and similar controller logics with anonymous functions, The more redundancy your application is. and If you define classes with each routes, there are many classes in your application.... then you maybe decide to use full stack frameworks instead of micro frameworks.

So I think it is a one solution to use anonymous classes instead of function.

Controller class has these methods and class properties.

methods:

action($args): you have to write your controller logic in this method.

render($output): helper method to render the $output with 200 status

render404($output): helper method to render the $output with 404 status

properties:

$this->request

$this->response

$this->app

$this->container

If use Template engine (PHP or Twig etc...), a renderWithT method in Templatable trait is available:

Silex is the best web application framework for developers, who want to lean Symfony Components and PHP 5.3 (closure, name space..etc). Silex allow you to create new controllers with "mount" method which adds a controllers collection with "ControllerProvider".

Install

Then I tried to create new controllers for BASIC Authorization which is simple and reuseable. It is very easy to set up this controller provider, you have only to get code from gist in "src/Silex/Provider" directory.

Set up

This provider require UrlGeneratorServiceProvider and SessionServiceProvider, which are default providers Silex has. Then you have to register these providers before in index.php like below:

BasicAuth requires a name "home" of URL which is used after redirecting, of course you can change the name.

Then, add one line which calls the mount method in index.php. It is too simple:

$app->mount('/auth', new Silex\Provider\BasicAuthControllerProvider());

After adding, if you access to "http://example.com/", this application redirects you to "/auth/login" and require your name and password. If you want to logout, you have to access to '/auth/logout'. At Default, name is "demo" and password is "123456", so after you submit them, you can access to "home" page. If you want to remove Basic Authorization, you have only to comment out this mount line.

Customize

If you want to customize the setting about name, password and url to be redirect, just define like below:

Zend Framework Page A Day Calendar 2012

We can find articles of Zend Framework in Japanese fewer than the number of other frameworks, I think. Because CakePHP and CodeIgniter are more popular than ZF. in 2011, Japanese Zend Framework Page A Day Calendar is about to start.