PHP Framework
Another PHP Framework. I started this micro-framework when I was frustrated by the steep learning curve needed for most PHP frameworks, at the time. The goal was to provide a thin, simple orchestration of app flow while avoiding reinvention of key components by leveraging existing outside components when they already exist (e.g., Redbean, Smarty, LessCSS, etc.). The main idea should be to get up and running as quickly as possible. You can build complexity in, as needed, but it shouldn’t be needed from the get-go.
.htaccess
file there (assuming you’re running apache).$app->setPage(new AppClass())
if you want to avoid using ccChainDispatcher$dispatch->addPage(new AppClass())
, which allows easy expandability (recommended).htdocs
, www
, public_html
, or wherever directory your server exposes, contains a simple index.php
file that references…The public directory contains the application’s “hook” file (e.g., index.php
) to direct the web-server to the app code. This file simply includes the app’s starting file (app.php
, in our sample). That starting file ties the app-specific code to the ccPhp framework by including ccApp.php
.
.htaccess
(to send all processing to the PHP app-code). This file resides in the public facing area.ccApp
singleton instance that represents the infrastructure functionality of the app.The framework requires a is a class to render web content. As such, the main purpose of the app is to implement the render() method of a class (implementing ccPageInterface). ccApp
calls the render()
method and it generates the output. It can interpret the URI (via the ccRequest
object) and output content, as necessary. Simple!
There are several “controller” classes which extend this simple concept and can be used as a base-class for the app’s class. A good starting class is ccSimpleController. With this class, you simply implement public methods whose names correspond to URL components, i.e., ‘/‘ delimited path components. Thus the URL implies an Action which corresponds to a method of the same name in the controller instance. With this class you needn’t implement the render()
method; its implementation correlates and calls the public method that corresponds to the URL component name.
The an instance of the class is attached to the ccApp
instance via ccApp::setPage()
. When run, the ccApp
instance calls the render()
method of the class to render the page.
The ccApp
calls the ccPageInterface::render()
method (and methods invoked via the ccSimpleController::render() as a proxy for that method). If render()
return TRUE it has processed and generated output. If it returns FALSE, then it has not and ccApp
generates a 404.
It can be useful to break your application up into separate classes. This might be to break up handing of the URL or it may be for different kinds of handling (e.g., JSON, HTML, AJAX, …). The ccChainDispatcher
will call each of the classes registered with it in sequence until one of the render calls return TRUE. If none of them handle the URI (i.e., all return FALSE), the ccChainDispatcher
‘s render()
returns FALSE and 404 is triggered. So, this class enables multiple ccPageInterface implementations to be active at the same time, but ccChainDispatcher
is, itself, a ccPageInterface
implementation, so they all follow the same pattern.
Development builds can be pretty noisy. But it is a pain to have to remove all the diagnostic output when moving to production; then more of a pain to add them back in, if a problem is discovered. The framework helps to control whether and where diagnostic output should go, without making a lot of source code changes to add/delete debugging code.
Output can be included in the output content—which is convenient during development. The output can be formatted for HTML output or output as plain text—depending on how the output will be viewed. It can also be redirected to log files with a simple setting. The default is to output as HTML within the content output, to allow getting started, easily.
Setup, usage & viewing [to be completed]
This class provides utilities to generate and control the output of diagnostics,
debugging and error messages.
tail -f .var/logs/project.log
The idea of the framework is to get you up and running as quick as possible, then as you find a need to refine, the features are there to support that. As such, there are several defaults that you may want to override. To start, you can perform these settings in the app.php file.
.var
. This is where the application can put “disposable” files (e.g., temporary files, cache files, etc.). You can retrieve the directory with ccApp::getWorkingDir()
.app.php
.ccRequest
, which the implementation can use to determine what to render.ccPageInterface
objects, therebyThere are three components that have to be in place for your app, each referencing the other:
index.php
anchor, the landing page. This simply contains a reference to…ccApp
class definition, i.e., the ccPhp framework.ccPhp
framework.As mentioned earlier, you can start by copying the sample directory, part of ccPhp.
It contains a sample app.php
. You can call it whatever you’d like, the only thing that needs to know its name is the index.php, included in the sample.
You app’s execution and definition center around this main file. Most of the application’s meaty work is implemented in its page rendering classes, but this file gets things started and is the central point tying everything together. Here are the things it needs to think about doing:
ccApp
.ccPageInterface
.ccApp::dispatch()
See the todo list