Created
July 10, 2012 10:18
-
-
Save gsdevme/3082504 to your computer and use it in GitHub Desktop.
Idea for my RESTless framework...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* None of this works, just an idea. | |
* | |
* Idea is a REST based framework for backend of Backbonejs | |
* | |
* @twitter gsphpdev | |
*/ | |
/** | |
* This is the bootstrap basically, however its within a | |
* class so we dont expose global variables | |
*/ | |
require_once realpath(dirname(__FILE__)) . '/../Restless.php'; | |
$app = new Restless(array( | |
'mode' => 'debug', | |
'db' => 'mysql:dbname=testdb;host=127.0.0.1' | |
)); | |
################################## | |
# HOOKS ! | |
################################## | |
/** | |
* Making these hooks work is going to be hard, might have to do some hacky code | |
* around Reflection & __call(), or even go crazy and have some kind of master object and not use 'mew' | |
* | |
* new foo but instead | |
* | |
* $x = new hookable(new foo); | |
* | |
* So every method is call is a sudo method call, hookable checks for hooks then calls the actual method.. | |
*/ | |
/** | |
* These kind of hooks would be nice for a ACL through the application, | |
* just have a hook after the request. | |
* | |
* Or even a ACL before X model is called | |
*/ | |
// This will call the callback 'before' Restless\Request->payload | |
$app->hook('before//Restless\Request->payload', function(){ | |
}); | |
// Idea behind this would be same as hook() with a $bind passed to the callback | |
$app->hookbind('before//Restless\Request->payload', function(&$bind){ | |
// Woop! we have the Request object! $bind->_foo = 1; | |
}); | |
/** | |
* Used to load a file upon a hook, useful for loading little functions. | |
* | |
* Say you want to load a custom function if /Collections/Users is called | |
*/ | |
$app->exposeHook('Collections\\Users', 'myawesomefunction.php'); | |
// Perhaps need to allow for multiple files | |
$app->exposeHook(array('Collections\\Users', 'Collections\\Bob'), 'myawesomefunction.php'); | |
// Perhaps also allow a callback just incase they want to do multiple, however will require they do the loading. | |
$app->exposeHook('Collections\\Users', function(){ | |
require 'myawesomefunction.php'; | |
require 'myawen.php'; | |
require 'myaw.php'; | |
require 'myaction.php'; | |
require 'myawon.php'; | |
}); | |
################################## | |
# ROUTES ! | |
################################## | |
/** | |
* Thinking i will have the routes built via using the Models & Collections, | |
* so a Model called User becomes /User/ payload of {id:4} does new User()->getById(4) | |
* | |
* Once the routes are created they are cached | |
*/ | |
/** | |
* using Memcached for our Routecache will be good as it will allow 1 App server to cache it | |
* then have multiple App servers grabbing the cache.. | |
*/ | |
// So if the router is User and the payload was {id:something}, we create a memcache key of route-user-something | |
$app->routeCache('/user/[id]', array( | |
'etag' => true, | |
'expire' => 3600, // Memcache time | |
'expireHeader' => true, // Match HTTP Expires header to memcached (with 1 less second just incase) | |
'type' => 'Memcached' | |
)); | |
/** | |
* Without an expire it will be a checksum, meaning it will be live | |
* however it will etag meaning we will save bandwidth | |
*/ | |
$app->routeCache('/user/[id]', array( | |
'etag' => true, | |
'type' => 'Memcached' | |
)); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment