-
-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from mingyoung/routes-for-lumen
Support Lumen routes.
- Loading branch information
Showing
7 changed files
with
153 additions
and
99 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
This file was deleted.
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,27 @@ | ||
<?php | ||
|
||
namespace Overtrue\LaravelWechat\Routing\Adapters; | ||
|
||
use Illuminate\Container\Container; | ||
|
||
abstract class Adapter | ||
{ | ||
/** | ||
* @var \Illuminate\Container\Container | ||
*/ | ||
protected $app; | ||
|
||
/** | ||
* Adapter constructor. | ||
* | ||
* @param \Illuminate\Container\Container $app | ||
*/ | ||
public function __construct(Container $app) | ||
{ | ||
$this->app = $app; | ||
} | ||
|
||
abstract public function group(array $attributes, $callback); | ||
|
||
abstract public function any($uri, $action); | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Overtrue\LaravelWechat\Routing\Adapters; | ||
|
||
class Laravel extends Adapter | ||
{ | ||
public function group(array $attributes, $callback) | ||
{ | ||
$this->app->router->group($attributes, $callback); | ||
} | ||
|
||
public function any($uri, $action) | ||
{ | ||
$this->app->router->any($uri, $action); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Overtrue\LaravelWechat\Routing\Adapters; | ||
|
||
class Lumen extends Adapter | ||
{ | ||
public function group(array $attributes, $callback) | ||
{ | ||
$this->app->group($attributes, $callback); | ||
} | ||
|
||
public function any($uri, $action) | ||
{ | ||
$verbs = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE']; | ||
|
||
$this->app->addRoute($verbs, $uri, $action); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace Overtrue\LaravelWechat\Routing; | ||
|
||
use Illuminate\Container\Container; | ||
use Illuminate\Foundation\Application as LaravelApplication; | ||
use Laravel\Lumen\Application as LumenApplication; | ||
|
||
class Router | ||
{ | ||
/** | ||
* Routing adapter instance. | ||
* | ||
* @var \Overtrue\LaravelWechat\Routing\Adapters\Adapter | ||
*/ | ||
protected $adapter; | ||
|
||
/** | ||
* Create a new route registrar instance. | ||
* | ||
* @param \Illuminate\Container\Container $app | ||
*/ | ||
public function __construct(Container $app) | ||
{ | ||
if ($app instanceof LaravelApplication) { | ||
$this->adapter = new Adapters\Laravel($app); | ||
} elseif ($app instanceof LumenApplication) { | ||
$this->adapter = new Adapters\Lumen($app); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $method | ||
* @param array $arguments | ||
*/ | ||
public function __call($method, $arguments) | ||
{ | ||
call_user_func_array([$this->adapter, $method], $arguments); | ||
} | ||
} |
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