Created
July 31, 2010 14:30
-
-
Save viccherubini/502235 to your computer and use it in GitHub Desktop.
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 | |
| declare(encoding='UTF-8'); | |
| use \Jolt\Router, | |
| \Jolt\Route\Named\NamedGet, | |
| \Jolt\Route\Named\NamedPost, | |
| \Jolt\Dispatcher, | |
| \Jolt\Client, | |
| \Jolt\Jolt; | |
| // Configuration | |
| $configuration = new \stdClass; | |
| $configuration->layoutDirectory = '/path/to/layout/directory/'; | |
| $configuration->controllerDirectory = '/path/to/controller/directory/'; | |
| $configuration->viewDirectory = '/path/to/view/directory/'; | |
| $configuration->url = 'http://jolt.dev'; | |
| $configuration->secureUrl = 'https://jolt.dev'; | |
| $configuration->useRewrite = true; | |
| // Configure the routes and router, of course, this could be pushed to another file | |
| $router = new Router; | |
| $router->setParameters($_GET) | |
| ->setRequestMethod($_SERVER['REQUEST_METHOD']) | |
| ->setHttp404Route(new Named('/', 'NotFound', 'index')); | |
| $router->addRoute(new NamedGet('/', 'Controller', 'action')) | |
| ->addRoute(new NamedGet('/abc', 'Controller', 'actionAbc')) | |
| ->addRoute(new NamedPost('/product/%n', 'Product', 'view')) | |
| ->addRoute(new NamedPost('/customer', 'Customer', 'index')); | |
| // Dispatcher loads up a matched route and executes it | |
| $dispatcher = new Dispatcher; | |
| // Client returns data back to the browser, has a nice __toString() | |
| $client = new Client; | |
| // Build a view to attach to the Dispatcher -> Controller heirarchy | |
| $view = new View; | |
| // Build the entire application and execute it | |
| $jolt = new Jolt; | |
| $jolt->setConfiguration($configuration); | |
| $jolt->attachRouter($router); | |
| $jolt->attachDispatcher($dispatcher); | |
| $jolt->attachClient($client); | |
| $jolt->attachView($view); | |
| echo $jolt->execute(); | |
| /* | |
| public function Jolt::execute() { | |
| $c = $this->configuration; | |
| // Set up the View | |
| $this->view->setViewDirectory($this->configuration->viewDirectory) | |
| ->setUrl($c->url) | |
| ->setSecureUrl($c->secureUrl) | |
| ->setUseRewrite($c->useRewrite); | |
| // Get the matched route based on the URL parameters | |
| $matchedRoute = $this->router->execute(); | |
| // Load and execute the matched Controller and Action from the matched route | |
| $this->dispatcher | |
| ->setControllerDirectory($c->controllerDirectory) | |
| ->attachRoute($matchedRoute) | |
| ->attachView($this->view) | |
| ->execute(); | |
| // Determine what the headers and HTTP status are and return that | |
| $this->client | |
| ->attachDispatcher($this->dispatcher) | |
| ->execute(); | |
| return $this->client; | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment