-
Notifications
You must be signed in to change notification settings - Fork 0
Home
lafka edited this page Apr 30, 2012
·
2 revisions
A quick and uncluttered way to setup a structure for routing requests. Wave can be though of as a mini-toolkit with a autoloader implementation, it makes structuring multiple libraries/frameworks together an easy task and allows developers to focus on the business logic rather than trying to make the tools behave they want.
This is a nice way to turn:
<?php
switch ($_GET['page']) {
case "home":
// logic
break;
case "contact":
// logic
break;
default:
// Oh noes....
break;
}
?>
Into this (yes that is really annotations in php.....)
<?php
/**
* @GET /
* @GET /home
*/
class Route extends Wave\Route\Annotated implements Wave\Route\IFace {
public function dispatch ($uri) {
// Home sweet home
}
}
To install it you need to setup a webserver with PHP and make it point everything to index.php. After doing that you need to install some files:
mkdir my-src-dir && cd my-src-dir
git init
git submodule add https://[email protected]/lafka/wave.git Wave
ln -P Wave/index.php .
mkdir -p MyPackage/HelloWorld/
cat >> MyPackage/HelloWorld/Route.php <<EOF
<?php
namespace MyPackage\HelloWorld;
use Wave\Route\Iface, Wave\Route\Regex;
class Route extends Regex implements Iface {
protected \$regex = '~/(hello|good-?day)~i';
public function dispatch (\$uri) {
echo "Good day to you!";
}
}
EOF
Now go to http://your-example-host/hello and see for yourself