I have started to create my own PHP framework, mainly because I will know what's going on with the code and secondly because it should not take that much longer than learning a framework that might be obsolete in a year or so anyway. This series of post will be about how to create your own framework regardless of language, PHP, Ruby, Java, Python, C#, VB, Perl, Etc.
If you are writing your own framework you will need to account for these things:
- Language - The language you want to use. Pick one, I have found dynamic languages the most flexible to work with, but it does not really matter.
- IDE - The IDE you want to use is also very important. You will spend most of your time working with this tool, so pick one that's flexible, extensible, and you like.
- Versioning - Here the choice is something you can version your software with. I prefer CVS (Concurrent Versioning System) or SVN (SubVersion).
- MVC or Classic – I have never been a fan of full blown MVC frameworks, usually they rely too much on configuration and don't really save you much time (ala Struts), but if you are comfortable with MVC or Classic pick one and that will decide how you will structure most your framework.
- ORM / Data Abstraction – You will have a database, or some data store, this will map your data store to classes or functions making it easier to work with.
- Error Control – Your error control should work with all other aspects of your framework, I will call this an infrastructure component.
- Logging - While the web server provides some logging, and analytic packages exist, debugging and identifying problems when your applications breaks, the inclusion of a logging component makes fixing it much faster.
- Security (Authentication / Authorization) – Unless you have a static site, you will have users that need to be authenticated and authorized to do certain things with the data behind your site.
- Caching – Sometimes to improve the performance of your site, you may need to implement your own caching mechanism rather than relying on your language, web server, or a client's browser.
- Batch - If you have CRON, or Batch jobs for your application you will need to create a batch framework to interact with your data and/or the business logic of your application.
- Configuration - The more complicated an application becomes, the more likely you will want to extract all your hard coded strings to configuration files. While I don't recommend putting everything in a configuration file (a.k.a. J2EE) some configuration is handy.
- Mail / Distribution – Communication with systems and people whether via email gateway, phone, fax, or printing might be required and need to be coupled with your business logic, batch, or any of the other sub-systems of your application.
- Modules & Extensibility - Your framework should provide a way for people to extend it without impact on it's major sub-systems.
- Templating & Widgets & Skinning – If your application is reused by over and over or if used by others (anti-pattern of this blog) you might want to give the it the ability to apply themes or skins to it as well as custom site templates (similar to WordPress).
- Documentation - Well if it's just you, using your framework might not need any documentation, however if you build it move on to something else, then come back to your app after a few months or years (if it's good enough) having a documentation generator from code will be really nice.
- Testing - Unit, Integration, Regression test are all parts of building a stable robust application, but automating the process is even better.
That's it for this post, in the next 17 or so post I will talk about each aspect of creating a framework. Stay Tuned…