-
Notifications
You must be signed in to change notification settings - Fork 23
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 #51 from juvenn/feature/leanengine
添加支持 Laravel 的中间件 LaravelEngine
- Loading branch information
Showing
4 changed files
with
86 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace LeanCloud\Engine; | ||
|
||
/** | ||
* LeanEngine as Laravel middleware | ||
* | ||
* Add LaravelEngine::class to Laravel middleware stack: | ||
* | ||
* ```php | ||
* // in app/Http/Kernel.php | ||
* $middleware = [ | ||
* \LeanCloud\Engine\LaravelEngine::class | ||
* ]; | ||
* ``` | ||
* | ||
* @link https://laravel.com/docs/5.1/middleware | ||
*/ | ||
class LaravelEngine extends LeanEngine { | ||
|
||
/** | ||
* Get request header value | ||
* | ||
* @param string $key Header key | ||
* @return string | ||
*/ | ||
protected function getHeaderLine($key) { | ||
return $this->request->header($key); | ||
} | ||
|
||
/** | ||
* Get request body string | ||
* | ||
* @return string | ||
*/ | ||
protected function getBody() { | ||
return $this->request->getContent(); | ||
} | ||
|
||
/** | ||
* Laravel middleware entry point | ||
* | ||
* @param \Illuminate\Http\Reuqest $request Laravel request | ||
* @param \Closure $next Laravel closure | ||
* @return mixed | ||
*/ | ||
public function handle($request, $next) { | ||
$this->request = $request; | ||
$this->dispatch($request->method(), | ||
$request->url()); | ||
return $next($this->request); | ||
} | ||
} | ||
|
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 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 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