1 | <?php |
||
20 | class SharedPackageDataManager implements PackageDataManagerInterface |
||
21 | { |
||
22 | const PACKAGE_DATA_FILENAME = 'packages.json'; |
||
23 | const PACKAGE_INSTALLATION_SOURCE = 'source'; |
||
24 | |||
25 | /** |
||
26 | * @var Composer |
||
27 | */ |
||
28 | protected $composer; |
||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $vendorDir; |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $packagesData; |
||
38 | |||
39 | |||
40 | /** |
||
41 | * @param Composer $composer |
||
42 | */ |
||
43 | public function __construct(Composer $composer) |
||
47 | |||
48 | /** |
||
49 | * @param string $vendorDir |
||
50 | */ |
||
51 | public function setVendorDir($vendorDir) |
||
55 | |||
56 | /** |
||
57 | * @param PackageInterface $package |
||
58 | * @param array $packageData |
||
59 | */ |
||
60 | protected function updatePackageUsageFile(PackageInterface $package, array $packageData) |
||
83 | |||
84 | /** |
||
85 | * Add a row in the "packages.json" file, with the project name for the "package/version" key |
||
86 | * |
||
87 | * @param PackageInterface $package |
||
88 | */ |
||
89 | public function addPackageUsage(PackageInterface $package) |
||
100 | |||
101 | /** |
||
102 | * Remove the row in the "packages.json" file |
||
103 | * |
||
104 | * @param PackageInterface $package |
||
105 | */ |
||
106 | public function removePackageUsage(PackageInterface $package) |
||
120 | |||
121 | /** |
||
122 | * Return usage of the current package |
||
123 | * |
||
124 | * @param PackageInterface $package |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | public function getPackageUsage(PackageInterface $package) |
||
132 | |||
133 | /** |
||
134 | * Initialize the package data array if not set |
||
135 | */ |
||
136 | protected function initializePackageData() |
||
145 | |||
146 | /** |
||
147 | * @param PackageInterface $package |
||
148 | * @param string $key |
||
149 | * @param mixed $defaultValue |
||
150 | * |
||
151 | * @return mixed |
||
152 | */ |
||
153 | protected function getPackageDataKey(PackageInterface $package, $key, $defaultValue = null) |
||
154 | { |
||
155 | if (!isset($this->packagesData)) { |
||
156 | $this->initializePackageData(); |
||
157 | } |
||
158 | |||
159 | $packageKey = $package->getPrettyName() . '/' . $package->getPrettyVersion(); |
||
160 | if (!isset($this->packagesData[$packageKey]) || !isset($this->packagesData[$packageKey][$key])) { |
||
161 | return $defaultValue; |
||
162 | } |
||
163 | |||
164 | return $this->packagesData[$packageKey][$key]; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @param PackageInterface $package |
||
169 | */ |
||
170 | public function setPackageInstallationSource(PackageInterface $package) |
||
174 | } |
||
175 |