The register
function will be one of the most important functions in the Bones
class down the road, but we'll just get started by adding the following code at the end of our lib/bones.php
file:
/Library/Webserver/Documents/verge/lib/bones.php
public static function register($route, $callback) { $bones = static::get_instance(); if ($route == $bones->route && !static::$route_found) { static::$route_found = true; echo $callback($bones); } else { return false; } }
We started by creating a public static function called register
. This function has two parameters: $route
and $callback. $route
contains the route that we are attempting to match against the actual route, and $callback
is the function that will be executed if the routes do match. Notice that, at the start of the register
function, we call for our Bones
instance, using the static:get_instance()
function. This is the Singleton Pattern...