Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
twn39 committed Aug 26, 2017
1 parent 8b91bd6 commit a94cb94
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class App
*/
private $events = [];

/**
* @var string
*/
private $routePrefix = '';

/**
* App constructor.
* @param array $setting
Expand Down Expand Up @@ -148,10 +153,7 @@ private function parsePsr7Response(ResponseInterface $psr7Response, $response)
*/
public function get($uri, $callback, $middleware = null)
{
$this->container['router.collector']->addRoute('GET', $uri, [
'uses' => new Handler($this->container, $callback),
'middleware' => $middleware,
]);
$this->addRoute('GET', $uri, $callback, $middleware);
}

/**
Expand All @@ -162,10 +164,7 @@ public function get($uri, $callback, $middleware = null)
*/
public function post($uri, $callback, $middleware = null)
{
$this->container['router.collector']->addRoute('POST', $uri, [
'uses' => new Handler($this->container, $callback),
'middleware' => $middleware,
]);
$this->addRoute('POST', $uri, $callback, $middleware);
}

/**
Expand All @@ -176,10 +175,7 @@ public function post($uri, $callback, $middleware = null)
*/
public function put($uri, $callback, $middleware = null)
{
$this->container['router.collector']->addRoute('PUT', $uri, [
'uses' => new Handler($this->container, $callback),
'middleware' => $middleware,
]);
$this->addRoute('PUT', $uri, $callback, $middleware);
}

/**
Expand All @@ -190,10 +186,7 @@ public function put($uri, $callback, $middleware = null)
*/
public function delete($uri, $callback, $middleware = null)
{
$this->container['router.collector']->addRoute('DELETE', $uri, [
'uses' => new Handler($this->container, $callback),
'middleware' => $middleware,
]);
$this->addRoute('DELETE', $uri, $callback, $middleware);
}

/**
Expand All @@ -204,10 +197,7 @@ public function delete($uri, $callback, $middleware = null)
*/
public function patch($uri, $callback, $middleware = null)
{
$this->container['router.collector']->addRoute('PATCH', $uri, [
'uses' => new Handler($this->container, $callback),
'middleware' => $middleware,
]);
$this->addRoute('PATCH', $uri, $callback, $middleware);
}

/**
Expand All @@ -218,10 +208,7 @@ public function patch($uri, $callback, $middleware = null)
*/
public function head($uri, $callback, $middleware = null)
{
$this->container['router.collector']->addRoute('HEAD', $uri, [
'uses' => new Handler($this->container, $callback),
'middleware' => $middleware,
]);
$this->addRoute('HEAD', $uri, $callback, $middleware);
}

/**
Expand All @@ -233,7 +220,7 @@ public function head($uri, $callback, $middleware = null)
*/
public function addRoute($method, $uri, $callback, $middleware = null)
{
$this->container['router.collector']->addRoute($method, $uri, [
$this->container['router.collector']->addRoute($method, $this->routePrefix.$uri, [
'uses' => new Handler($this->container, $callback),
'middleware' => $middleware,
]);
Expand All @@ -245,7 +232,10 @@ public function addRoute($method, $uri, $callback, $middleware = null)
*/
public function group($prefix, $callback)
{
$this->container['router.collector']->addGroup($prefix, $callback);
$originPrefix = $this->routePrefix;
$this->routePrefix = $prefix;
$callback($this);
$this->routePrefix = $originPrefix;
}

/**
Expand Down

0 comments on commit a94cb94

Please sign in to comment.