SitePoint Sponsor |
|
User Tag List
Results 26 to 50 of 100
-
Nov 11, 2003, 10:13 #26
- Join Date
- Nov 2000
- Location
- Switzerland
- Posts
- 2,479
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Selkirk
For a page controller which hasn't actually been deployed yet, this might happen;
1. User requests http://www.example.com/example_page.php
2. Apache finds page doesn't exist, calls 404 hander deployer.php
3. deployer.php copies /home/username/deploy/example_page.php to /home/username/www/example_page.php (adding necessary mods for front controller)
4. Page is served
5. User requests http://www.example.com/example_page.php again.
6. example_page.php (or some included code) checks the modification time on /home/username/deploy/example_page.php and compares with itself - updates if needed.
8. Latest version is executed
9. Page is served
Something like that. For users unable to modify their server's 404 handler, the initial deployment would need to be manually invoked but after that, no problem.
Whether this is a good idea though, not sure. Some things that might be problematic;
Confusing to develop with - you place your script in a different directory to the one it will actually be executed from - might make includes etc. mind boggling.
Easy to break(?). A script which "updates itself" may not be a pretty thing.
-
Nov 11, 2003, 10:22 #27
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Selkirk
PHP Code:class FilterChain
{
var $filters = array();
function FilterChain()
{
}
function register($filterClass)
{
$this->filters[] = $filterClass;
}
function execute()
{
reset($this->filters);
$this->next();
}
function next()
{
if ($filterClass = current($this->filters))
{
next($this->filters);
include_once('filters/' . $filterClass . '.class.php');
$filter =& new $fcfilterClass);
$filter->run($this);
}
}
}
PHP Code:require_once('FilterChain.class.php');
$fc =& new FilterChain();
$fc->register('OutputBufferingFilter');
$fc->register('TimingFilter');
$fc->register('RequestDispatchingFilter');
$fc->execute();
exit;
1. I'm making assumptions about the location and naming of the filters.
2. There's no way to pass parameters to the Filter constructors.
Any suggestions? As always, I want to keep things as absolutely simple as possible.
-
Nov 11, 2003, 13:15 #28
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by HarryF
Originally Posted by HarryF
Originally Posted by HarryF
Originally Posted by HarryF
-
Nov 11, 2003, 13:31 #29
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Selkirk
-
Nov 11, 2003, 16:45 #30
- Join Date
- Nov 2000
- Location
- Switzerland
- Posts
- 2,479
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Harry, I like the rules you came up with. In fact, they are all design requirements that I imposed on the solution I came up with.
I like what you trying to do, but I don't like the added complexity it creates. Personally, I'd rather have one naughty exit() call, than require that every page is wrapped inside a function.
Unit testing is something I'd certainly like to explore more
-
Nov 11, 2003, 16:54 #31
- Join Date
- Nov 2002
- Posts
- 841
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by codezilla
Originally Posted by codezilla
-
Nov 11, 2003, 17:11 #32
- Join Date
- Nov 2002
- Posts
- 841
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by codezilla
Front Controller:
Code:Web Server -----> Front Controller (Common Logic) ----> Action or Page Controller
Code:Page Controller Base Class (Common Logic) ^ | (inherits) | Web Server -------> Page Controller -----> Action
Originally Posted by codezilla
-
Nov 11, 2003, 17:19 #33
- Join Date
- Nov 2002
- Posts
- 841
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by codezilla
-
Nov 11, 2003, 17:34 #34
- Join Date
- Nov 2002
- Posts
- 841
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by codezilla
-- Some of the discussion on implementing intercepting filters in WACT is occurring here. Code generation is one possible option.
I'm not sure what exactly you mean by "naive application logic" but maybe it's related to my aforementioned lack of knowledge.
-
Nov 11, 2003, 19:38 #35
- Join Date
- Feb 2003
- Location
- Virginia
- Posts
- 143
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hey,
I read this post then went to Harry's site and read his article on Front Controllers, then went to Java web site and read theirs and STILL I'm trying to figure out what PROBLEM you all are tring to solve?
I've been designing them for years and didn;t know they were called that, I just used the LOGIC to guide me through development pits until things worked flawlessly. When I'm developing I don't use ANY code. I just use flow chart patterns until the logic gets me to where I want to be.
Could you all represent this problem as a flowchart or UML diagram for those of us who are doing some head scratching but would like to participate in the conversation - even if it's just listening real good?
cheers
-
Nov 11, 2003, 21:35 #36
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Selkirk
-
Nov 11, 2003, 21:52 #37
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Selkirk
-
Nov 11, 2003, 22:09 #38
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Selkirk
-
Nov 11, 2003, 22:10 #39
- Join Date
- Feb 2003
- Location
- Virginia
- Posts
- 143
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I agree that using the auto_prepend_file mechanism would be a more pure interpretation of Fowler's definition (I'm assuming you meant front controller, not page controller), but I consider them to be bascially the same thing -- as long as one has enough self-discipline to put include_once('frontcontroller.inc.php') at the top of every page.
cheers
Next day: I didn't realize they ment the APACHE auto_prepend_file. In which case I agree with the quote. ?? I must of been sleepyLast edited by Resolution; Nov 12, 2003 at 22:26.
-
Nov 11, 2003, 22:11 #40
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Selkirk
-
Nov 11, 2003, 22:17 #41
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Resolution
Core J2EE Patterns: Intercepting Filter [sun.com]
Enterprise Solution Patterns: Intercepting Filter [microsoft.com]
They both have several charts that explain things better than I can.
-
Nov 12, 2003, 02:58 #42
- Join Date
- Nov 2000
- Location
- Switzerland
- Posts
- 2,479
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Could you all represent this problem as a flowchart or UML diagram for those of us who are doing some head scratching but would like to participate in the conversation - even if it's just listening real good?
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.
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.
When an HTTP request comes into a Java Servlet, the servlet needs to select which code gets executed next.
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). That makes life easier, on the one hand - simply add a new script somewhere under the web root and you can immediately begin accepting requests, the script being termed a "Page Controller" (or perhaps an Application Controller in some circumstances - but that's a diversion right now). The downside is how do you "attach" the central logic that must be executed for every page (e.g. logging / authentication / timing), without having to make significant modifications (ideally no modifications) to the script?
There are many approaches which have been used in PHP to date (some re-implementing the front controller in PHP) but, IMO, we don't have the "perfect" solution yet; one that will suit everyone, irrespective to coding style. As a result, most PHP frameworks have a fairly short lifespan and you tend to get frustrated users (like this - "Yet Another Framework").
Been thinking about those requirements again. There may be a boiled down version which goes something like;
"Does not require implementing 404 pages in PHP"
That's a little confusing given I was talking about that Apache 404 trick earlier (a special case which is an exception) but what I really mean is I think this is "bad";
PHP Code:<?php
// index.php
switch ( @$GET['module'] ) {
case 'news':
include 'news.php';
break;
case 'forum':
include 'forum.php';
break;
default:
header('http/1.1 404 Not Found');
die('Page not found');
break;
}
?>
-
Nov 12, 2003, 03:19 #43
- Join Date
- Aug 2003
- Location
- Watford, UK
- Posts
- 62
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
Originally Posted by codezilla
Re. the redeclaration thing - I can't see how include_once gets round the issue, if you define functions or classes in the page controller, e.g.
page.php
PHP Code:<?php
include_once 'xxx-controller.php';
function afunction() {
echo 'blah';
}
afunction();
?>
xxx-controller.php
PHP Code:<?php
//... some stuff
include 'page.php';
exit(0);
?>
xxx-controller.php
PHP Code:<?php
// ... some stuff
include_once 'page.php';
exit(0);
?>
I'm seeing your example page controller more as a template than a controller (I know you said that it combines controller and view).
I'm liking the idea of some kind of Layer Supertype Page Controller providing a Template Method run/execute/process... + intercepting filter setup. Page Controllers under the web root inherit from this, templates are kept wherever and brought in by the controller when required. This obviously loses the simplicity and the easy application of the filters to other peoples code libraries tho- but I can't see how this can be reliable anyway with the redeclaration issue?
Cheers,
Jon
-
Nov 12, 2003, 04:17 #44
- Join Date
- Feb 2003
- Location
- Virginia
- Posts
- 143
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you for that explaination. I believe I have a grasp on the language being used - here goes.
Originally Posted by HarryF
-
Nov 12, 2003, 10:28 #45
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by JonR
I'm seeing your example page controller more as a template than a controller (I know you said that it combines controller and view).
My vision is that a PHP block appears at the top of the page containing all the page controller logic and below it is a TemplateView mixing HTML and presentation logic (PHP).
-
Nov 12, 2003, 10:30 #46
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Resolution
-
Nov 12, 2003, 10:53 #47
- Join Date
- Nov 2002
- Location
- upstairs
- Posts
- 110
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Selkirk
Originally Posted by HarryF
Originally Posted by JonR
You guys have convinced me! My frontcontroller.inc.php is not a Front Controller, but a Base (Page) Controller (or at least a draft of a proper one).
I think I was thrown off because Intercepting Filters are usually mentioned in the context of Front Controllers, but there's certainly no reason why they can't be used with Page Controllers.
So, where does that leave my code? I'll rename frontcontroller.inc.php to basecontroller.inc.php, but are there other changes that are needed? Rename FilterChain to FilterManager? Anything else?
-
Nov 12, 2003, 12:25 #48
- Join Date
- May 2003
- Location
- virginia
- Posts
- 988
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If you had a Request class (handles all POST and GET), would you consider that a filter also? In a framework like this, would it be OK to consider all classes being used (part of the core framework) as a InterceptingFilter class?
Also, would it be a problem if all InterceptingFilters had access to the filter manager? like:
$filterManager =& $this->fm;
That way you could access an InterceptingFilter previously loaded.
Thanks,
Matt
-
Nov 12, 2003, 13:19 #49
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
A bit late in replying though I also had the feeling that you were refering to a Page Controller myself from this bit...
...find the page-centric version much easier to build and maintain.
-
Nov 12, 2003, 13:58 #50
- Join Date
- Aug 2003
- Location
- Watford, UK
- Posts
- 62
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
Originally Posted by codezilla
. I'm curious as to why you stress that point?
Originally Posted by codezilla
Originally Posted by codezilla
Cheers,
Jon
Bookmarks