SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Montreal, Canada
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    From Libraries to Frameworks, and MVC

    Coming to the end of the first overhaul of a Library I am working on, I have been considering implementing a framework in PHP for web based applications on top of this library.

    I did some search, and neither any search here or Amazon produced any good leads, so I am asking here in the hopes of getting some good advice. I am looking for two good books (or more, if that is the case), one that covers good Framework design, and another that details MVC. While the former is easy to understand, as is the latter, it's important to me that when I develop the Framework, I have a clear understanding of developing solid frameworks and developing frameworks with MVC in mind.

    So maybe not just books, but anything that you think would help me in this cause. Seeing that I have the library pretty much done, and on the road to being released, I also need to think, and plan, ahead for other things I want to do.

    Thank you. :)
    If at first you don't succeed, sky-diving is not for you.

  2. #2
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Number one on the list has to be "Patterns Of Enterprise Architecture" by Martin Fowler. It's not a step by step guide to building a framework but rather more in the flavour of the GoF design patterns, but with a focus on "middleware" type systems, such as those you might build with PHP (PHP even gets one small mention ).

    The web related patterns (such as the Template View and MVC) may well tell you what you already know but (in my case) had never "mentally formalized", which is great for really understanding what you're dealing with.

    Also Bruce Eckels short description of Building a Framework with the Template Method in thinking in Python may be useful.

    My guess is it's best to study what others have done in PHP as well, such as the MVC frameworks listed here. Not sure anyone has hit on the perfect solution yet (for example some are somewhat too literal ports of Java to PHP).

  3. #3
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jason, is the library you're talking about EclipseCE?

    I'd start my MVC research by looking at Sun, Apple and Smalltalk's implementations, if I were you BTW.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  4. #4
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Montreal, Canada
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anode: Yes it's Eclipse CE. No, it's not updated in the SF CVS, so don't bother. Heh....

    Things I have added include some Reader and Writer classes. I am still working out a few details, but I hope to have a clearly defined Reader/Writer interface across many different storage mechnasims (including Files, Sessions, Cookies, Databases, possible even FTP because I may actually need something like that).

    I also have implemented some Curl stuff, HttpPost and HttpGet, which is rather handy, and simple to use.

    I've improved the iterators, so that you can use either the oringal EclipseCE method, or the shortened while ( $val = $it->next() ) method, and accomplish the same thing.

    I'ved also tried to clean up the interface a bit. Things are common. ::isValid() is now the default way to test if any object is doing alright. If it returns false, their is an error. You can retrieve errors via the ::getErrorMessage() method. ::isSuccess() exists on all Result objects returned after an operation is performed. For example:

    PHP Code:
    $HttpPost =& new HttpPost($Url);
    $HttpPost->setVar($ArrayIterator);
    $Result =& $HttpPost->execute();
    if ( !
    $Result->isSuccess() ) {
            echo 
    $Result->getErrorMessages();

    Sessions and Cookie management are in place, but not as useful as I had hoped (well, they are useful, they just don't provide anything different from what already exists other than a common interface to Reading/Writing).

    Little things all around that just make using the library easier to use for general PHP things. For example, QueryIterator makes looping through query results easy, however, getting a single row of data back from a query result required a number of lines of code in Eclipse.

    Now instead of something like this:
    PHP Code:
    $QueryResult $db->query("SELECT LAST_INSERT_ID()");
    if ( !
    $QueryResult->isSuccess() ) {
          
    // Error handling  
    }
    list(
    $id) = $QueryResult->getRow(0);
    $QueryResult->close(); 
    You can do this:

    PHP Code:
    list($insert_id) = $db->simpleQuery("SELECT LAST_INSERT_ID()"); 
    I've also implemented other nifty, just plain useful things for web developers.

    For example, I took HarryF's Strategy example with the validate class and expanded on it, and made it even more useful, IMO. Now, you can do something like this:

    PHP Code:
    $ValidationInspector = new ValidationInspector($_POST);
    if ( !
    $ValidationInspector->isValid() ) {
            echo 
    $ValiadtionInspector->getErrorMessages();

    Actually, this I am debating on whether I should seperate the ValidationInspector object and the InspectorResult into two seperate classes. Suggestions here? This would allow me to create a InspectorResultIterator object as well.

    Anyways, back to the example, each element of $_POST would be run through a validation class that is stored in a validation directory (that you designate of course). It's actually really, really nice.

    What else did I add. Ahh yes, Phrasebook and PhrasebookSQL objects. I didn't write it, but I have one I can use.

    Oh yes, and certain classes will now have built in methods for Singleton use. Basically, something like:

    $Session =& Session::getInstance();

    Of course, this is also a standard method interface. All ::getInstance() methods do the same thing. So a

    Database::getInstance() also works. However, because Objects differ, certain objects may take parameters in their ::getInstance() method. Session has an optional argument to set a session id, such as:

    $Session =& Session:getInstance($SessionId);

    Let's see, FileCache has also been implemented. With the implementation of a common Reader/Writer inteface, this can be expanded to a general Cache object that simple takes a Reader and a Writer object as paramters. Of course, FileCache would be the default option. Ease of use is still just as important as flexibility.

    Anyways, that's a lot of information. More than I intended, but anways, I will take a look at SmallTalk (heard a lot of good things about it) and the others you mentioned. Thanks.
    If at first you don't succeed, sky-diving is not for you.

  5. #5
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm.... Any chance you could check this into the SF CVS so I can have a looksie? Sounds interesting...

  6. #6
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Montreal, Canada
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will see what I can do, but no promises...busy month and all.
    If at first you don't succeed, sky-diving is not for you.

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is your Library available to developers ? I'd be interested in seeing how it works myself, although I have one point on your Singleton implementation ?

    I am sure I read somewhere that you shouldn't place parameter's within this pattern ? I'm trying to remember that exact article myself since I'm not sure ?

    Just going by what I've read that's all.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •