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'; }