Skip to content

Commit d254da5

Browse files
author
erika
committed
Initial commit
1 parent d79bdee commit d254da5

File tree

9 files changed

+628
-6
lines changed

9 files changed

+628
-6
lines changed

.gitignore

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
composer.phar
2-
/vendor/
3-
4-
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
5-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6-
# composer.lock
1+
.idea
2+
vendor/

composer.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "minicli/miniweb",
3+
"type": "library",
4+
"description": "Web Layer for minicli",
5+
"license": "MIT",
6+
"homepage": "https://github.com/erikaheidi/minicli",
7+
"keywords": ["micro","web","sites"],
8+
"autoload": {
9+
"psr-4": {
10+
"Minicli\\Miniweb\\": "src/"
11+
}
12+
},
13+
"require": {
14+
"minicli/minicli": "^1.0",
15+
"twig/twig": "^3.0"
16+
}
17+
}

composer.lock

Lines changed: 232 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
4+
namespace Minicli\Miniweb\Exception;
5+
6+
7+
class RouteNotFoundException extends \Exception
8+
{
9+
10+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
4+
namespace Minicli\Miniweb\Provider;
5+
6+
use Minicli\App;
7+
use Minicli\Miniweb\Exception\RouteNotFoundException;
8+
use Minicli\Miniweb\Request;
9+
use Minicli\ServiceInterface;
10+
11+
class RouterServiceProvider implements ServiceInterface
12+
{
13+
/** @var App */
14+
protected $app;
15+
16+
/** @var Request */
17+
protected $request;
18+
19+
/**
20+
* @param App $app
21+
*/
22+
public function load(App $app)
23+
{
24+
$this->app = $app;
25+
$this->request = new Request($_REQUEST, $_SERVER['REQUEST_URI']);
26+
}
27+
28+
/**
29+
* @return string
30+
*/
31+
public function getRoute()
32+
{
33+
return $this->request->getRoute() ?: 'index';
34+
}
35+
36+
/**
37+
* @return string
38+
* @throws RouteNotFoundException
39+
*/
40+
public function getCallableRoute()
41+
{
42+
$route = $this->getRoute();
43+
44+
$controller = $this->app->command_registry->getCallableController('web', $route);
45+
46+
if ($controller === null) {
47+
//no dedicated controller found. is it a static content from the data dir? if not, throw exception
48+
49+
if (!$this->app->config->has('data_path')) {
50+
throw new \Exception("Missing Static Data Path.");
51+
}
52+
53+
$data_path = $this->app->config->data_path;
54+
55+
if (is_dir($data_path . '/' . $route)) {
56+
return 'content';
57+
}
58+
59+
throw new RouteNotFoundException('Route not Found.');
60+
}
61+
62+
return $this->getRoute();
63+
}
64+
65+
/**
66+
* @return Request
67+
*/
68+
public function getRequest()
69+
{
70+
return $this->request;
71+
}
72+
}

0 commit comments

Comments
 (0)