-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project.php
82 lines (68 loc) · 1.96 KB
/
Project.php
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*
* This file is part of the Installer package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Installer;
use Composer\Config;
use Composer\Composer;
use Composer\Installer\PackageEvent;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
use Composer\Package\RootPackageInterface;
final class Project
{
private $composer;
private $io;
private $configuredPackage;
private $configuredPackagePath;
/**
* @internal
*/
public function __construct(Composer $composer, IOInterface $io, PackageInterface $configuredPackage)
{
$this->composer = $composer;
$this->io = $io;
$this->configuredPackage = $configuredPackage;
}
/**
* @internal
*/
public static function fromPackageEvent(PackageEvent $event): self
{
$installedPackage = $event->getOperation()->getPackage();
return new self($event->getComposer(), $event->getIO(), $installedPackage);
}
public function getIO(): IOInterface
{
return $this->io;
}
public function getRootPackage(): RootPackageInterface
{
return $this->composer->getPackage();
}
public function getRootPackagePath(): string
{
return getcwd();
}
public function getConfiguredPackage(): PackageInterface
{
return $this->configuredPackage;
}
public function getConfiguredPackagePath(): string
{
if (null === $this->configuredPackagePath) {
$installationManager = $this->composer->getInstallationManager();
$this->configuredPackagePath = $installationManager->getInstallPath($this->configuredPackage);
}
return $this->configuredPackagePath;
}
public function getVendorDir(): string
{
return $this->composer->getConfig()->get('vendor-dir', Config::RELATIVE_PATHS);
}
}