PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / robloach / component-installer / src / ComponentInstaller / Process / Process.php

Process.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/robloach/component-installer/src/ComponentInstaller/Process/Process.php

177 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of Component Installer.
5 *
6 * (c) Rob Loach (http://robloach.net)
7 *
8 * For the full copyright and license information, please view the LICENSE.md
9 * file that was distributed with this source code.
10 */
11
12 namespace ComponentInstaller\Process;
13
14 use Composer\IO\IOInterface;
15 use Composer\Composer;
16 use Composer\IO\NullIO;
17 use Composer\Package\Dumper\ArrayDumper;
18 use ComponentInstaller\Util\Filesystem;
19 use Composer\Package\Loader\ArrayLoader;
20
21 /**
22 * The base Process type.
23 *
24 * Processes are initialized, and then run during installation.
25 */
26 class Process implements ProcessInterface
27 {
28 protected $composer;
29 protected $io;
30 protected $config;
31 protected $packages = array();
32 protected $componentDir = 'components';
33 protected $fs;
34
35 /**
36 * The Composer installation manager to find Component vendor directories.
37 */
38 protected $installationManager;
39
40 /**
41 * {@inheritdoc}
42 */
43 public function __construct(Composer $composer = null, IOInterface $io = null)
44 {
45 $this->composer = isset($composer) ? $composer : new Composer();
46 $this->io = isset($io) ? $io : new NullIO();
47 $this->fs = new Filesystem();
48 $this->installationManager = $this->composer->getInstallationManager();
49 }
50
51 /**
52 * {@inheritdoc}
53 */
54 public function init()
55 {
56 // Retrieve the configuration variables.
57 $this->config = $this->composer->getConfig();
58 if (isset($this->config)) {
59 if ($this->config->has('component-dir')) {
60 $this->componentDir = $this->config->get('component-dir');
61 }
62 }
63
64 // Get the available packages.
65 $allPackages = array();
66 $locker = $this->composer->getLocker();
67 if (isset($locker)) {
68 $lockData = $locker->getLockData();
69 $allPackages = isset($lockData['packages']) ? $lockData['packages'] : array();
70
71 // Also merge in any of the development packages.
72 $dev = isset($lockData['packages-dev']) ? $lockData['packages-dev'] : array();
73 foreach ($dev as $package) {
74 $allPackages[] = $package;
75 }
76 }
77
78 // Only add those packages that we can reasonably
79 // assume are components into our packages list
80 foreach ($allPackages as $package) {
81 $extra = isset($package['extra']) ? $package['extra'] : array();
82 if (isset($extra['component']) && is_array($extra['component'])) {
83 $this->packages[] = $package;
84 }
85 }
86
87 // Add the root package to the packages list.
88 $root = $this->composer->getPackage();
89 if ($root) {
90 $dumper = new ArrayDumper();
91 $package = $dumper->dump($root);
92 $package['is-root'] = true;
93 $this->packages[] = $package;
94 }
95
96 return true;
97 }
98
99 /**
100 * {@inheritdoc}
101 */
102 public function process()
103 {
104 return false;
105 }
106
107 /**
108 * Retrieves the component name for the component.
109 *
110 * @param string $prettyName
111 * The Composer package name.
112 * @param array $extra
113 * The extra config options sent from Composer.
114 *
115 * @return string
116 * The name of the component, without its vendor name.
117 */
118 public function getComponentName($prettyName, array $extra = array())
119 {
120 // Parse the pretty name for the vendor and name.
121 if (strpos($prettyName, '/') !== false) {
122 list($vendor, $name) = explode('/', $prettyName);
123 } else {
124 // Vendor wasn't found, so default to the pretty name instead.
125 $name = $prettyName;
126 }
127
128 // Allow the component to define its own name.
129 $component = isset($extra['component']) ? $extra['component'] : array();
130 if (isset($component['name'])) {
131 $name = $component['name'];
132 }
133
134 return $name;
135 }
136
137 /**
138 * Retrieves the component directory.
139 */
140 public function getComponentDir()
141 {
142 return $this->componentDir;
143 }
144
145 /**
146 * Sets the component directory.
147 */
148 public function setComponentDir($dir)
149 {
150 return $this->componentDir = $dir;
151 }
152
153 /**
154 * Retrieves the given package's vendor directory, where it's installed.
155 *
156 * @param array $package
157 * The package to retrieve the vendor directory for.
158 */
159 public function getVendorDir(array $package)
160 {
161 // The root package vendor directory is not handled by getInstallPath().
162 if (isset($package['is-root']) && $package['is-root'] === true) {
163 // @todo Handle cases where the working directory is not where the
164 // root package is installed.
165 return getcwd();
166 }
167
168 if (!isset($package['version'])) {
169 $package['version'] = '1.0.0';
170 }
171 $loader = new ArrayLoader();
172 $completePackage = $loader->load($package);
173
174 return $this->installationManager->getInstallPath($completePackage);
175 }
176 }
177