Source of file ComposerLoader.php
Size: 2,468 Bytes - Last Modified: 2021-12-24T06:48:16+00:00
/var/www/docs.ssmods.com/process/src/src/Util/ComposerLoader.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 | <?php namespace BringYourOwnIdeas\Maintenance\Util; use Exception; use SilverStripe\Core\Extensible; /** * The composer loader class is responsible for dealing directly with composer.json and composer.lock files, * in terms of loading and parsing their contents. * * Any requirements for dealing with these files directly should use this class as a proxy. */ class ComposerLoader { use Extensible; /** * @var object */ protected $json; /** * @var object */ protected $lock; /** * @var string */ protected $basePath; /** * @param string $basePath * @throws Exception */ public function __construct($basePath = '') { if ($basePath) { $this->setBasePath($basePath); } $this->build(); } /** * Load and build the composer.json and composer.lock files * * @return $this * @throws Exception If either file could not be loaded */ public function build() { $basePath = $this->getBasePath(); $composerJson = file_get_contents($basePath . '/composer.json'); $composerLock = file_get_contents($basePath . '/composer.lock'); if (!$composerJson || !$composerLock) { throw new Exception('composer.json or composer.lock could not be found!'); } $this->setJson(json_decode($composerJson)); $this->setLock(json_decode($composerLock)); $this->extend('onAfterBuild'); } /** * @param object $json * @return ComposerLoader */ public function setJson($json) { $this->json = $json; return $this; } /** * @return object */ public function getJson() { return $this->json; } /** * @param object $lock * @return ComposerLoader */ public function setLock($lock) { $this->lock = $lock; return $this; } /** * @return object */ public function getLock() { return $this->lock; } /** * Set the base path, if not specified the default will be `BASE_PATH` * * @param string $basePath * @return $this */ public function setBasePath($basePath) { $this->basePath = $basePath; return $this; } /** * @return string */ public function getBasePath() { return $this->basePath ?: BASE_PATH; } } |