Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
erika committed Feb 24, 2020
1 parent d79bdee commit d254da5
Show file tree
Hide file tree
Showing 9 changed files with 628 additions and 6 deletions.
8 changes: 2 additions & 6 deletions .gitignore
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/
17 changes: 17 additions & 0 deletions composer.json
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"
}
}
232 changes: 232 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Exception/RouteNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php


namespace Minicli\Miniweb\Exception;


class RouteNotFoundException extends \Exception
{

}
72 changes: 72 additions & 0 deletions src/Provider/RouterServiceProvider.php
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;
}
}
Loading

0 comments on commit d254da5

Please sign in to comment.