Page 1 of 2

Custom Application Frameworks - What would you include?

Posted: Mon Mar 06, 2006 11:55 am
by Chris Corbyn
How many of you guys work with a pre-built framework when you start building an application? I'm not referring to a major commercial one, but just one you've written yourself some time in the past to save you wrtiting the same code from scratch each time you start building an app.

I started to notice a pattern evolving when I begin writing an application... the last few have almost always had the same base layout so I figured it's time to write a little framework (just for me... not something I'll release -- at least not any time soon). Last night I made a start and because I've done it a fair few times I got pretty far just in the space of an hour or so.

I'm just wondering what you'd include in a lite framework? I don't want something really feature-packed because clunky things bug me.....

So far I've put the things in that I *know* I'll use.

I always start with a config class (yeah, don't ask but I like keeping configuration directives in a class called config).

I then have a db wrapper class (just MySQL... hmm... I should add PgSQL too), a core engine (not a lot in this in the main framework because I fill that specific to the app in question), a template engine that ties in nicely with the framework, a function to load in classes & modules (easier in PHP5 of course), some very small example modules and some skeleton controller classes and templates just to serve as a mini-documentation.

One thing I don't like is things that do everything for you. For example... a db class that you don't actually have to write queries for... that's just silly and makes it less obvious what's going on... I like to write my queries by hand.

I'm in two minds as to whether to include a list/pagination class too. If you were writing a "lite" OOP/MVC framework what would you like to see in there? :)

Posted: Mon Mar 06, 2006 12:14 pm
by neophyte
What I might include:

database wrapper
unified templating
class(es) to work with files
class to hand requests (post/get)
class to hand module loading
singleton class to handle objects
xml functions/class
basic js library
form validation and error handling
form processing
configuration

I've probably missed something but every project I've been involved with thus far touched on all of those.

Thanks for askign this question. I've been pondering building my own custom lite weight framework too. I'm hoping to dive into application design by creating a light weight framework. Anybody know where I can read about application design and PHP?

Posted: Mon Mar 06, 2006 12:19 pm
by jmut
I got two right away:
- debugging class.
- logging class (file,db,sms,icq,mail etc.) :)

Posted: Mon Mar 06, 2006 1:21 pm
by Ree
What I always use when starting:

DB abstraction class
Basic controller/view classes
Validator and validation rule classes
Templating class

...and cfg.php ;)

That's pretty much it.

Posted: Mon Mar 06, 2006 2:35 pm
by Buddha443556
My idea of a framework may differ from all of yours. All I've got is a standard set of pages.

Posted: Mon Mar 06, 2006 2:47 pm
by Gambler
Persmission manager, user/group manager, session manager.

Posted: Mon Mar 06, 2006 2:50 pm
by Roja
Great question.

Me, I think of it in terms of challenges, and solutions:

1. Database - connectivity is basic. But I don't want to have connectivity, and add security, and session handling, and performance monitoring, and.. - I want something that handles everything I generally do with a database. I also want it to do all of those very well, and be well documented. I almost always choose adodb.

2. Output - I prefer my output to be seperate from my php. Of course, thats not *always* entirely possible, so I have to have some level of logic support in my template engine. Again, I don't want to write 15 mods to improve on it, I want it to do almost everything I need. So far, the choice that I tend to find fits best - for me - is Smarty.

3. Authentication - Almost every app needs a secure login system. That means javascript and php libraries for hashing the password before transmission. Right now, the sweet spot for me is Feyd's SHA-256. Its a little heavy, but it brings a ton of security, and its well-written.

4. Email - Most apps I write need to send an email at some point. Mail is a horrible mess on php, including security problems, interoperability problems (try using mail() on openbsd. I dare you!), and more. PHPMailer blissfully removes the majority of those issues from my "to-do" plate.

Armed with those four tools, I have the makings of a fairly solid framework. I have input/output seperation (weak MVC), I have db abstraction, I have secure authentication, and I have workable email.

From there, I can build a fairly large variety of sites, tools, games, and more.

Posted: Mon Mar 06, 2006 3:02 pm
by Christopher
The foundations for my frameworks are data containers, validation rules and filters. Most of my classes seem to conform to one of those interfaces.

Posted: Mon Mar 06, 2006 4:19 pm
by Chris Corbyn
Wow... that's what I call a response :) Thanks guys.

Yeah, I'd completely forgotten about things like email. I'm happy with the DB stuff the way I have it... I can send queries and fetch results in a variety of forms with ease as well as handle multiple database connections with little fuss. Email is a must and I'll probably just integrate phpMailer. Handling of POST/GET ? That's what I meant by too many fancy things... it's not something I'd want in a lite framework :)

Again, validation is something I'll generally code without even thinking about it and you always need slightly different validation methods for each project... that said there are some basic things you can include a validator for but === "clunk" :P

I'd never really included things like encryption/hashing/security in separate classes but it would be a nice idea actually.

Templating... I generally achieve as close to 100% separation as you can get without being a complete lunatic and trying to get the computer to eat cheese and drink wine. The template sstem I use does offer the ability to include PHP logic in a template if you really really need to.

Javascript... rather write JS myself. Gone off using things like XAJAX since I learnt how to write it myself === "clunk".


I do need a permissions system in place yes... I was aware of that but hadn't settled on an approach (DB or config)... it will be added ;)

I'll leave out pagination/listing too for the same reasons I gave above.

So that means I'm missing:

Email
Permissions
Security (hashing/encryption)
(possibly) Validation

I'm still open to suggestions for other things though :)

Posted: Mon Mar 06, 2006 4:26 pm
by Chris Corbyn
Doh I missed a really big one I'll use in a PHP5 framework.

Exception Handling :)

Posted: Mon Mar 06, 2006 4:27 pm
by Chris Corbyn
neophyte wrote:Anybody know where I can read about application design and PHP?
DevShed has some nice introductory (and advanced) articles into PHP application design patterns.

Posted: Mon Mar 06, 2006 4:39 pm
by feyd
Everyone's already covered everything I tend to need early on in most projects. So yeah, go team!

Posted: Mon Mar 06, 2006 8:30 pm
by alex.barylski
Just out of curiosity...why use a 'Config' class???

Do you include update/delete file operations in these classes for easy end user changes???

I personally just use an multi-dimensional array... :)

Posted: Mon Mar 06, 2006 8:46 pm
by John Cartwright
Hockey wrote:Just out of curiosity...why use a 'Config' class???

Do you include update/delete file operations in these classes for easy end user changes???

I personally just use an multi-dimensional array... :)
configurations generally should not ever be altered at run times, so your best bet is typically a constant.

Posted: Tue Mar 07, 2006 5:59 pm
by Gambler
onfigurations generally should not ever be altered at run times
I don't see why not. Configuration can be seen as a set of defaults.