-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
erika
committed
Feb 24, 2020
1 parent
d79bdee
commit d254da5
Showing
9 changed files
with
628 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
composer.phar | ||
/vendor/ | ||
|
||
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control | ||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file | ||
# composer.lock | ||
.idea | ||
vendor/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "minicli/miniweb", | ||
"type": "library", | ||
"description": "Web Layer for minicli", | ||
"license": "MIT", | ||
"homepage": "https://github.com/erikaheidi/minicli", | ||
"keywords": ["micro","web","sites"], | ||
"autoload": { | ||
"psr-4": { | ||
"Minicli\\Miniweb\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"minicli/minicli": "^1.0", | ||
"twig/twig": "^3.0" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
|
||
namespace Minicli\Miniweb\Exception; | ||
|
||
|
||
class RouteNotFoundException extends \Exception | ||
{ | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
|
||
namespace Minicli\Miniweb\Provider; | ||
|
||
use Minicli\App; | ||
use Minicli\Miniweb\Exception\RouteNotFoundException; | ||
use Minicli\Miniweb\Request; | ||
use Minicli\ServiceInterface; | ||
|
||
class RouterServiceProvider implements ServiceInterface | ||
{ | ||
/** @var App */ | ||
protected $app; | ||
|
||
/** @var Request */ | ||
protected $request; | ||
|
||
/** | ||
* @param App $app | ||
*/ | ||
public function load(App $app) | ||
{ | ||
$this->app = $app; | ||
$this->request = new Request($_REQUEST, $_SERVER['REQUEST_URI']); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRoute() | ||
{ | ||
return $this->request->getRoute() ?: 'index'; | ||
} | ||
|
||
/** | ||
* @return string | ||
* @throws RouteNotFoundException | ||
*/ | ||
public function getCallableRoute() | ||
{ | ||
$route = $this->getRoute(); | ||
|
||
$controller = $this->app->command_registry->getCallableController('web', $route); | ||
|
||
if ($controller === null) { | ||
//no dedicated controller found. is it a static content from the data dir? if not, throw exception | ||
|
||
if (!$this->app->config->has('data_path')) { | ||
throw new \Exception("Missing Static Data Path."); | ||
} | ||
|
||
$data_path = $this->app->config->data_path; | ||
|
||
if (is_dir($data_path . '/' . $route)) { | ||
return 'content'; | ||
} | ||
|
||
throw new RouteNotFoundException('Route not Found.'); | ||
} | ||
|
||
return $this->getRoute(); | ||
} | ||
|
||
/** | ||
* @return Request | ||
*/ | ||
public function getRequest() | ||
{ | ||
return $this->request; | ||
} | ||
} |
Oops, something went wrong.