From 8550c99133017ba3a8cd401963ad5facaf7d95fc Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Fri, 5 Jun 2020 15:35:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eparseclass=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/library/ParseClass.php | 104 ++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/extend/catcher/library/ParseClass.php b/extend/catcher/library/ParseClass.php index b3d9bbc..215461f 100644 --- a/extend/catcher/library/ParseClass.php +++ b/extend/catcher/library/ParseClass.php @@ -1 +1,105 @@ getClass(); + + $parent = $class->getParentClass(); + + $methods = []; + + foreach ($parent->getMethods() as $method) { + if (!$this->isMagicMethod($method->getName())) { + $methods[] = $method->getName(); + } + } + + return $methods; + } + + + public function methods() + { + $class = $this->getClass(); + + $methods = []; + + foreach ($class->getMethods() as $method) { + if (!$this->isMagicMethod($method->getName())) { + $methods[] = $method->getName(); + } + } + + return $methods; + } + + + /** + * @return mixed + */ + public function onlySelfMethods() + { + $methods = []; + + $parentMethods = $this->parentMethods(); + + foreach ($this->methods() as $method) { + if (!in_array($method, $parentMethods)) { + $methods[] = $method; + } + } + + return $methods; + } + + + public function getClass() + { + + return new \ReflectionClass($this->namespace . $this->module . '\\controller\\'. + + ucfirst($this->controller)); + } + + + protected function isMagicMethod($method) + { + return strpos($method, '__') !== false; + } + + public function setModule($module) + { + $composer = \json_decode(file_get_contents(root_path() . 'composer.json'), true); + + $psr4 = $composer['autoload']['psr-4']; + + foreach ($psr4 as $key => $_module) { + if ($_module == $module) { + $this->namespace = $key; + break; + } + } + + return $this; + } + + + public function setRule($module, $controller) + { + $this->module = $module; + + $this->controller = $controller; + + return $this; + } + +} \ No newline at end of file