A PHP framework for sticking the old to the new.
NOTE: You shouldn't use this thing, it isn't remotely stable. I'm kind of just getting my feet wet with github and writing a framework so I know some pitfalls and can better pick an established one.
Glue is a lightweight PHP framework designed for those who aren't building a new site from scratch. More often than not you can't just throw away all the code you've got on a website. Maybe you don't have the manpower, maybe you don't have the time. Maybe you realize that if it works you should probably just let it continue to work until you're good and ready to replace it.
Incremental improvements are the reason Glue exists. It's designed to offer a modern classloader, router, and templating system -- plus some management of configuration and credentials. All tied into tools for integrating it all together with various legacy anti-patterns.
- Place your
_glue
directory somewhere. Preferably above your web root so it can't possibly be browsed. - Create a new directory somewhere else to hold your site-specific code and configuration. You shouldn't ever need to touch the core
_glue
directory. You can copy_glue-site
as a starting point. - Place
_glue.php
somewhere in your web directory. The root is good. Fill out its configuration options at the top. - Modify your .htaccess to route requests for nonexistent files to
_glue.php
. See_glue/sample.htaccess
for more information.
The following assumes your site's configuration folder is named _glue-site
Edit _glue-site\config\glue.yaml
to set up the basics. You can load files from this directory by their name using \glue\Conf::get([filename/path/to/option])
Note that config options are cached per-request, and changing the config files at runtime (gross, don't do that) will not change what is returned by Conf::get()
.
Glue has a built-in OOP CRUD tool called CRUDder.
Code for your site should be placed in _glue-site/classes
and _glue-site/routes
.
Anything in _glue-site/classes
will be loaded by the autoloader. You should definitely namespace your code to avoid collisions. For example, place a class called MyClass
in the file _glue-site/classes/mynamespace/MyClass.php
and declare namespace mynamespace;
at the top of the file. If you haven't used namespaces in PHP before, check out the documentation.
Which code handles which URLs is handled by the class \glue\Route
.
The class contains static methods for specifying the handling of GET and POST requests. Note that all paths for Route should have a leading slash, and do support regular expressions. Any pieces of the regular expression grouped with parentheses will be passed to the handler function.
\glue\Route::get(string $path, function $handler)
Handles GET requests to the path matching $path
with the function $handler
.
\glue\Route::post(string $path, function $handler)
Handles POST requests to the path matching $path
with the function $handler
.
\glue\Route::any(string $path, function $handler)
Handles any requests to the path matching $path
with the function $handler
.