Roto

Written 09:46 am 10/1/2013 Modifed 10:30 am 10/1/2013

With the creation of the Bureau of Facts and Statistics, I am also announcing my new microframework off of which it is based: Roto. Roto is a simple PHP framework that lets you build web applications quickly, by using scoped views and components (Widgets).

It is used as a composer package, and all class files are under the namespace "Roto". It's still in development, but will be updated over time as I use it for my upcoming community text-adventure site: Peril.io (under development).

Router

Roto is primarily a routing library. It uses the Router to route requests, using the following flow:

  1. Evaluate any folder files,
  2. Evaluate the controller file
  3. Render the view file using buffering
  4. Render the template if there is one, otherwise echo the main output of the view.

Folder files are files that operate on any requests in or not under that directory. By default, they are named "_folder.php", but that can be changed by the user.

A controller file is any .php file that matches the request (index.html => index.php). The designated controller can be modified by any folder files. All logic should be performed here.

A view file is any ..php file that matches the request (index.html => index.html.php). The view file may be changed by the folder files or the controller file. Inside the view file, $this refers to the View object. The output of the file gets stored as the main region in the View object, unless otherwise specified. You can route output to other regions by using the *startRegion, or endRegion commands, or store data into regions using the region command. Regions are how the view is loaded into the template. If there is no template, the main region is outputted.

A template is a reusable file in which to route the output of the view. You can see an example here.

Service

There is only one singleton- the Service class. This is used to be a general purpose key / object store. For example, you can store a database connection, a config object, router, or view as services. This should be done in a single "services" file, but there are no hard rules about this.

Example:

Service::register('CFG', function() use ($root) {
    return new Config(
        $root.'/config/config.development.ini',
        $root.'/config/config.appdefault.ini'
    );
});

$cfg = Service::CFG();

Config Files

Roto uses ini files to store configuration. You pass in the config file locations as variable parameter lists to the Config object. The earlier the file appears in the list indicates its precedence.

BREAD

Roto allows for a verbose BREAD api calls using the BREAD class. For convention, this should be added in the folder file, IE:

/api/animals/_folder.php.

The BREAD class allows for chainable callback additions, using ->onBrowse, ->onRead, ->onEdit, ->onAdd, and ->onDelete, with execution being triggered by the dispatch() function. This will automatically map requests /api/animals/ and /api/animals/$id to their proper functions, using the proper HTTP verbs: PUT, POST, DELETE, and GET.

Quickstart

To get set up with a new Roto App instantly, run the command:

composer create-project oranj/roto-app --stability="dev"