1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace Fgm\ComposerCheck;
- /**
- * Class RequirementsLoader loads a composer.json file.
- */
- class RequirementsLoader implements LoaderInterface {
- protected $dev = [];
- protected $run = [];
- /**
- * {@inheritdoc}
- */
- public function __construct(string $directory) {
- $this->file = realpath("${directory}/composer.json");
- }
- /**
- * Return the --dev requirements.
- *
- * @return array
- * A requirements array, keyed by requirement string.
- */
- public function getDev() {
- return $this->dev;
- }
- /**
- * Return the non- --dev requirements.
- *
- * @return array
- * A requirements array, keyed by requirement string.
- */
- public function getRun() {
- return $this->run;
- }
- /**
- * {@inheritdoc}
- */
- public function load() {
- $json = json_decode(file_get_contents($this->file), TRUE);
- $this->run = $json['require'] ?? [];
- $this->dev = $json['require-dev'] ?? [];
- }
- }
|