Bigfoot php framework
From n² wiki
Bigfoot Framework
Contents |
[edit] Structure
.htaccess
dispatch.php
/config
routes.php (define the url routing )
namespaces.php (define all the prefix => namespaces you want to use )
mimetypes.php (define file extensions => mimetypes )
/lib
/requests (classes for processing requests)
/templates (php templates)
[edit] Requirements
PHP5 Apache mod_rewrite
[edit] Installation
Copy the files to the root directory of your server
[edit] How it Works
When the application receives a request, the rewrite directive in .htaccess passes the request to dispatch.php, which looks at the routes you have defined, and calls the appropriate method of the request class, with the parameters you defined in routes, for that url.
The class method will populate the variables, call the template you defined in the parameters, and return the response;
[edit] configuring URLs in routes.php
Here are some example URLs and their parameters:
$urls = array(
'/Res/*' => array(
'class' => 'Item',
'template' => 'item',
'uri' => isset($_GET['uri'])? trim($_GET['uri']): 'false',
'store_uri' => "http://api.talis.com/stores/kwijibo-dev1",
),
'/Catalogues/*' => array(
'class'=>'Collection',
'template' => 'collection',
'store_uri' => 'http://api.talis.com/stores/kwijibo-dev1',
'rdf_type' => $namespaces['pbac'].'PBAC',
'title' => 'Printed Book Auction Catalogues',
),
);
The key in this array is a regular expression. The regular expression should match the entire URL, except for any file extensions or query strings.
eg: if you want to respond to URL requests like "/example.html?q=John", your regular expression should only try to match "/example"
File extensions are stripped off requests before the URL regular expressions are tested, and passed to the request class you defined for that URL space.
Notice also that the 'template' parameter is bereft of file extension - which is decided dynamically via content negotiation, and the file extension in the http request url.
You can pass whatever parameters you want to the request class in the array identified by the URL regex, though you need to make sure that the request class has a class variable corresponding to the key of the parameter value.
[edit] Request Classes
The class parameter defines what request class will be called to respond to the URL. The other parameters can either be defined here in the $urls array, or you can create new classes extending the existing request classes. For example, instead of defining the store_uri for each of your URLs you might create silkwormitems.php:
class SilkwormItem extends Item { var $store_uri = 'http://api.talis.com/stores/silkworm-dev'; }
The request classes have methods named after the HTTP methods they respond to - eg: Item::GET() is called when a GET request is done on a URL that uses the Item class
[edit] Item
The base class is Item, which serves up a representation of the resource identified by the URI you pass to it.
The Item class (which all other classes inherit from ) has a render method to render templates, exposing all the variables in Item::variables directly to the template. The current object ($this) is also available to the template
[edit] Collection
This class serves lists of resources - instead of passing it a URI, you can pass it an rdf:type (or an array of rdf:types) of resources that you want to list.
[edit] Templates
Templates go in the template directory. The file extensions used should have an entry in the mimetypes array so the application knows which mimetype to serve.
Some templates are called 'default' - 'default.json' and 'default.rdf'. These templates are called when, for example, the requested file extension is json, and template is 'item', but 'item.json' doesn't exist. They are useful for formats that can be transformed (from the available php variables) generically.
Templating is just done with regular embedded PHP - there is no special syntax.

