From 2e04f5a9b7fa3ce79c4cb38f31786b4b1cc6520b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 10 Nov 2020 18:04:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Controller.php | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/HttpServer/Controller.php b/HttpServer/Controller.php index 2bfc6e13..8be68454 100644 --- a/HttpServer/Controller.php +++ b/HttpServer/Controller.php @@ -9,13 +9,13 @@ use HttpServer\Http\HttpParams; use HttpServer\Http\Request; use Exception; use Snowflake\Abstracts\BaseGoto; +use Snowflake\Exception\ComponentException; use Snowflake\Snowflake; /** * Class WebController * @package Snowflake\Snowflake\Web * @property BaseGoto $goto - * @property \Snowflake\Application $app */ class Controller extends Application { @@ -32,16 +32,12 @@ class Controller extends Application public Request $request; - public BaseGoto $goto; - - - public $app; - - + /** + * Controller constructor. + * @param array $config + */ public function __construct($config = []) { - $this->app = Snowflake::app(); - $this->goto = $this->app->goto; parent::__construct($config); } @@ -106,4 +102,25 @@ class Controller extends Application } + /** + * @param $methods + * @return mixed + * @throws ComponentException + */ + public function __get($methods) + { + // TODO: Change the autogenerated stub + if (property_exists($this, $methods)) { + return $this->$methods; + } + + $method = 'get' . ucfirst($methods); + if (method_exists($this, $method)) { + return $this->{$method}(); + } + + return Snowflake::app()->get($methods); + } + + }