From e01790aa2391dcbf3b9aacda718d97d02c4595c2 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Thu, 19 Nov 2020 17:31:04 +0800 Subject: [PATCH] =?UTF-8?q?update:composer=E6=96=B0=E5=A2=9E=E6=9F=A5?= =?UTF-8?q?=E6=89=BEpackage=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/library/Composer.php | 60 ++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/extend/catcher/library/Composer.php b/extend/catcher/library/Composer.php index eaa887d..aaf716c 100644 --- a/extend/catcher/library/Composer.php +++ b/extend/catcher/library/Composer.php @@ -14,22 +14,72 @@ use catcher\facade\FileSystem; class Composer { + /** + * psr4 + * + * @time 2020年11月19日 + * @return mixed + */ public function psr4Autoload() { - return $this->composerContent()['autoload']['psr-4']; + return $this->content()['autoload']['psr-4']; } + /** + * require + * + * @time 2020年11月19日 + * @return mixed + */ public function requires() { - return $this->composerContent()['require']; + return $this->content()['require']; } - protected function composerContent() + /** + * require dev + * + * @time 2020年11月19日 + * @return mixed + */ + public function requireDev() { - return \json_decode(FileSystem::get($this->composerJsonPath()), true); + return $this->content()['require-dev']; } - protected function composerJsonPath() + /** + * composer has package + * + * @time 2020年11月19日 + * @param $name + * @return bool + */ + public function hasPackage($name) + { + $packages = array_merge($this->requires(), $this->requireDev()); + + + return in_array($name, $packages); + } + + /** + * composer content + * + * @time 2020年11月19日 + * @return mixed + */ + protected function content() + { + return \json_decode(FileSystem::sharedGet($this->path()), true); + } + + /** + * composer path + * + * @time 2020年11月19日 + * @return string + */ + protected function path() { return root_path() . 'composer.json'; }