Page MenuHomePhabricator

D663.id2053.diff
No OneTemporary

D663.id2053.diff

diff --git a/App.php b/App.php
--- a/App.php
+++ b/App.php
@@ -1,12 +1,5 @@
<?php namespace spitfire;
-use spitfire\core\app\AppAssetsInterface;
-use spitfire\core\app\RecursiveAppAssetLocator;
-use spitfire\core\Environment;
-use spitfire\core\Path;
-use spitfire\core\router\Parameters;
-use spitfire\core\router\reverser\ClosureReverser;
-use spitfire\core\router\Router;
/**
* Spitfire Application Class. This class is the base of every other 'app', an
@@ -21,6 +14,8 @@
abstract class App
{
+ private $router;
+
/**
* Instances a new application. The application maps a directory where it's residing
* with it's name-space and the URL it's serving.
@@ -29,11 +24,11 @@
* properly work (like inline-routes and prebuilt assets). It is recommendable
* that the 'baking' is performed automatically on composer::install or similar.
*
- * @param string $url The URL space the application is intended to be managing
- * this is used for URL generation, etc
+ * @param string $router A scoped router for this application to write it's routes
+ * to.
*/
- public function __construct($url) {
- $this->url = '/' . trim($url, '\/');
+ public function __construct($router) {
+ $this->router = $router;
}
/**
@@ -43,7 +38,7 @@
*
* @return string
*/
- public function url() { return $this->url; }
+ public function url() { return $this->router->namespace(); }
/**
* Returns the directory this application is watching.
@@ -57,34 +52,5 @@
* spitfire will look for controllers, models etc for this application.
*/
abstract public function namespace();
-
- public function makeRoutes() {
- #Include the routes from the user definitions
- file_exists("{$this->directory()}/settings/routes.php") && include "{$this->directory()}/settings/routes.php";
-
- #Build some defaults
- $ns = $this->url();
-
- #The default route just returns a path based on app/controller/action/object
- #If your application does not wish this to happen, please override createRoutes
- #with your custome code.
- $default = Router::getInstance()->request($ns, function (Parameters$params, Parameters$server, $extension) {
- $args = $params->getUnparsed();
- return new Path($this, array_shift($args), array_shift($args), $args, $extension);
- });
-
- #The reverser for the default route is rather simple again.
- #It will concatenate app, controller and action
- $default->setReverser(new ClosureReverser(function (Path$path, $explicit = false) {
- $controller = $path->getController();
- $action = $path->getAction();
- $object = $path->getObject();
-
- if ($action === Environment::get('default_action') && empty($object) && !$explicit) { $action = ''; }
- if ($controller === (array)Environment::get('default_controller') && empty($object) && empty($action) && !$explicit) { $controller = Array(); }
-
- return '/' . trim(implode('/', array_filter(array_merge((array)$controller, [$action], $object))), '/');
- }));
- }
}

File Metadata

Mime Type
text/plain
Expires
Apr 11 2021, 4:41 AM (9 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6087
Default Alt Text
D663.id2053.diff (2 KB)

Event Timeline