
Originally Posted by
HarryF
How about some guesses at requirements for how intercepting filtes / controllers should work in PHP?
1. Should not restrict the use of URLs
2. Should be possible to use Apache ... tricks
3. Should be possible to execute a page controller without the frontcontroller.
4. Does does not depend on any Apache specific features or php.ini settings.
A requirements list is a good idea. I was orginally going to suggest making two seperate lists. One for Intercepting Filters and one for Controllers.
Then, I saw where you were going with this in your next post...

Originally Posted by
HarryF
Think it can be done automatically (fully automatic on Apache by using the 404 trick).
This is basically a front controller, right? I think any implementation of front controller would be able to support an implementation of intercepting filters.

Originally Posted by
HarryF
The basic problem is how do we centralize some logic (e.g. logging, authentication) without requiring all PHP scripts be included by some central PHP script.
Or requiring each script to include a centralized PHP script?

Originally Posted by
HarryF
My fundamental opinion is Apache itself is the Front Controller when working with PHP, as opposed to a Java Servlet, where you'd implement a Front Controller with Java itself.
I don't see Apache as a front controller. I see PHP/Apache as a container. Just like Java Servlets are run in a container.

Originally Posted by
HarryF
When an HTTP request comes into a Java Servlet, the servlet needs to select which code gets executed next.
It does this via a web.xml file which contains a line which maps the url to a "logical page:"
Code:
<servlet-mapping>
<servlet-name>FrontController</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

Originally Posted by
HarryF
When an HTTP request comes into Apache + PHP, Apache effectively selects the PHP script to execute for you (if one exists for the requested URL).
PHP uses a physical file mapping technique, rather than a logical class mapping technique. In many ways this is easier when that is what you want. (put the file in a directory. No config file to edit.) However, in a FrontController situtation, you want to map many requests to a single php script. There is no sanctioned way to do this with a physical mapping. Thus, we have to resort to tricks because the "PHP Container" is not flexible.
In Java, Intercepting Filters are built into the container as well. Servlets are not aware of when they are being filtered. Filters are registered in the same web.xml file that the container uses to decipher urls. Define a filter:
Code:
<filter>
<filter-name>Compression Filter</filter-name>
<filter-class>CompressionFilter</filter-class>
<init-param>
<param-name>compressionThreshold</param-name>
<param-value>10</param-value>
</init-param>
</filter>
Call a filter for a specific servlet:
Code:
<filter-mapping>
<filter-name>Compression Filter</filter-name>
<servlet-name>FrontController</servlet-name>
</filter-mapping>
The servlet in the previous example is naive. It has no idea that it is being filtered.
To do the equivalent naive filtering in PHP/apache, I believe that you must use the auto_prepend_file and auto_append_file directives in the php.ini file. doing this via php.ini file is NO different than the doing the same thing in the web.xml file in java, except that you have to add apache configuration in order to achieve more fine grained targeting:
Code:
<Files ~ "*.do">
php_value auto_prepend_file /path/filter.php
</Files>
This type of config file editing is par for the course in java web applications.
So why is it that we have no .htaccess/.ini dependencies on our requirements list?
Take a look at the include based filters in my previous post. Everyone who has responded with an answer has suggested that I should use classes in that implementation.
However, if the requirement is to wrap "naive" code, I do not see the value of wrapping the filters in classes. Please enlighten me. 

Originally Posted by
Resolution
Question is, why are you tring to tackle this puzzle without a central connecting php script?
Indeed. I believe that this is one of codezillas requirements. I can understand why one would want to support wrapping "naive" scripts.
However, in WACT, I don't think we will really have any "naive" scripts. Thus, I think for WACT an interceptor implementation could rely on a Front Controller or Page Controller doing a little bit of filter management on the behalf of the application logic.
So for implementing a Front Controller in PHP, we have a few tricks to overcome physical mapping of urls:
get parameter
path after url
mod rewrite
404 tricks
My thought is that a Front Controller implementation for WACT should really be independent of which url mapping "trick" was used. In otherwords, the trick would not be defined inside the front controller, but inside the PHP/apache container before the front controller was called.
In my previous filter post, I had a filter which mapped a "path after url" into a get parameter. What do you think of that, Harry. As opposed to the request/uridata technique?
In a way, this makes the Front controller a container within a container.
Bookmarks