Fase is a minimalist VC (View+Controller, no Model as so far) framework
. Roughly it does what Cake does (url passed do dispatcher, parsed into
class+method+params, run and returned).
It's quite simple -- 32 files in 8 directories, including a few CSS', 3
charset translation tables (Polish, but there's more where they came
from), .htaccess (roughly the same as Cake's) and error pages.
To start it up edit two entries in /app/config.php: FASE_DEFAULT_APP
says which controller is taking care of the homepage, and
FASE_DATABASE_CFG which describes the database connection (optional).
There's a few ideas in it, that Cake could benefit from (if it doesn't
already, I don't follow the development of Cake anymore).
- All CSS and JS files are parsed with PHP by default. This not only
allows for portable web apps, but also allows for include()'s in CSS
and JS (which they sadly lack) and constants in CSS ( .Foo { color:
#5870a2 } can become .Foo { color: COLOR_FUCHSIA } which is far more
readable and less error-prone). Comments and unnecessary whitespace are
automatically stripped in-flight (unless constant DEBUG is true)). I
haven't used it yet on any sites with enough traffic to warrant a
cache, but it wouldn't be very difficult to implement (or you can skip
the thing and link to static files.)
- The database is accessed using a abstract static class DB_Base
extended with a database-specific DB_Mysql (as so far, there's only
MySQL). The database connection resource is kept in a constant. While
this prevents you from using more than one database connection for one
HTTP request, the point here is that you don't have to pass the $DB
variable around any more. Standard helper methods include
- DB::insert('comments', $data)
- DB::find_all('users', 'login,password', 'active == 1')
- DB::delete('posts', 'id = 5')
- There's a few introspection functions used mostly for debugging and
logging (i.e. each error log entry contains a call stack), notably
caller_file() which returns full path to the file from which the
function that called it was called.
Take, for example, the insert() function. You can use it to include
views within views (including CSS and Javascript) in much the same way
you use include() for standard PHP. But what makes it quite useful is
that if the insert()ed file is not present, it tries with a relative by
prepending the view file's path to the arguments it received.
Additionally, it figures out the file extension from the callers'. In
example, when from /app/css/default.css you call:
<?=insert('tools/yahoo_fonts')?>
...by the lack of slash it figures out the path is relative, so it
takes the caller's path (/app/css/default.css) and extracts the context
(/app/css) and file extension (.css) from it. It then tries to load the
file as usual.
What's more, this makes it easier to provide:
- Automatic multiple output types handling -- appropriate headers are
sent, and appropriate views are parsed depending on what output format
is expected. The default output type is HTML, but that's configurable
(per-controller). When you call, say
www.example.com/posts/list
by default HTML from /app/posts/list.html (a PHP script) is returned
(if it exists). But if you add a different file extension:
www.example.com/posts/list.rss
The latter call uses the same controller and method as the former, but
renders /app/posts/list.rss (which in reality is also a PHP script) as
its view. More so, insert()'s are output-type-agnostic, so an
_insert('item')_ tries to insert a .html file if called from a .html
file, and an .rss file with the same base name if called from a .rss.
With proper application code (which is not really difficult to develop)
providing an alternative output option is as easy as adding another
view of the same data.
- Debugging, logging and testing functions are in place and ready to
be extended. Tests are to be kept together with the libraries they
test, so that it's less painful to actually write any.
- And more :)
I wouldn't actually recommend anyone using it commercially (it's a
beta), but if you're a developer who likes to experiment a bit, Fase
provides a small-footprint, unrestricting framework for applications.
Download from: http://sputnik.pl/dev/labs/fase/fase_0.8.zip
Most of the files are licenced under the MIT licence, and files which
don't specify a license are in Public Domain. Please let me know if you
[use|like|hate] it.
Michal Tatarynowicz aka Pies.