-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWebApplication.php
More file actions
46 lines (41 loc) · 1.41 KB
/
WebApplication.php
File metadata and controls
46 lines (41 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace bookin\composer\api;
use Composer\Console\Application;
use Composer\Json\JsonValidationException;
use Composer\Factory;
class WebApplication extends Application
{
/**
* @param $composer
*/
public function setComposer($composer){
$this->composer = $composer;
}
/**
* @param bool|true $required
* @param bool|false $disablePlugins
* @return \Composer\Composer
* @throws JsonValidationException
*/
public function getComposer($required = true, $disablePlugins = false)
{
if (null === $this->composer) {
$fileConfig = Composer::$configFile;
$configFilePath = Composer::$configFilePath;
try {
$factory = new Factory();
$this->composer = $factory->createComposer($this->io, $fileConfig, $disablePlugins, $configFilePath);
} catch (\InvalidArgumentException $e) {
if ($required) {
$this->io->writeError($e->getMessage());
throw new \InvalidArgumentException($e->getMessage());
}
} catch (JsonValidationException $e) {
$errors = ' - ' . implode(PHP_EOL . ' - ', $e->getErrors());
$message = $e->getMessage() . ':' . PHP_EOL . $errors;
throw new JsonValidationException($message);
}
}
return $this->composer;
}
}