Created
July 30, 2012 03:05
-
-
Save animecyc/3203857 to your computer and use it in GitHub Desktop.
CreateFlow Library
This file contains hidden or 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 | |
namespace CreateFlow; | |
use Laravel; | |
use Route; | |
use Controller; | |
use Response; | |
/** | |
* Hark! It's a unicorn. | |
* @package CreateFlow | |
*/ | |
Laravel\Autoloader::$aliases['CreateFlow'] = 'CreateFlow\CreateFlow'; | |
class CreateFlow { | |
/** | |
* Holds our ExtensionManager instance | |
*/ | |
protected static $extension_manager; | |
/** | |
* Starts the CreateFlow engine | |
* @return null | |
*/ | |
public static function start() { | |
static::extension_manager()->init(); | |
} | |
/** | |
* Returns an instance of ExtensionManager; | |
* creates if it doesn't exist. | |
* @return type | |
*/ | |
public static function extension_manager() { | |
if(static::$extension_manager === NULL) { | |
return new ExtensionManager; | |
} | |
return static::$extension_manager; | |
} | |
/** | |
* Resolves the correct controller for a | |
* given route or path. | |
* @param bool $handle | |
* @return closure | |
*/ | |
public static function route($handle = FALSE) { | |
if($handle) { | |
return function($controller = 'dashboard', $action = 'index', $params = NULL) use ($handle) { | |
$extension = constant('CreateFlow\ExtensionManager::DEFAULT_EXTENSION'); | |
if(Controller::resolve($extension, $controller)) { | |
return Controller::call($extension . '::' . $controller . '@' . $action, explode('/', $params)); | |
} else { | |
return Response::error('404'); | |
} | |
}; | |
} else { | |
return function($path) { | |
@ list($extension, $controller, $action) = $path_pieces = explode('/', $path); | |
if(Controller::resolve($extension, $controller)) { | |
return Controller::call($extension . '::' . $controller . '@' . ($action ?: 'index'), array_slice($path_pieces, 3)); | |
} elseif(Controller::resolve(DEFAULT_BUNDLE, $extension)) { | |
return Controller::call(DEFAULT_BUNDLE . '::' . $extension . '@' . ($controller ?: 'index'), array_slice($path_pieces, 2)); | |
} else { | |
return Response::error('404'); | |
} | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment