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 / CopyProcess.php

CopyProcess.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/CopyProcess.php

82 lines 2.9 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\Composer;
15 use Composer\Package\Package;
16 use Composer\Util\Filesystem;
17
18 /**
19 * Process which copies components from their source to the components folder.
20 */
21 class CopyProcess extends Process
22 {
23 /**
24 * {@inheritdoc}
25 */
26 public function process()
27 {
28 return $this->copy($this->packages);
29 }
30
31 /**
32 * Copy file assets from the given packages to the component directory.
33 *
34 * @param array $packages
35 * An array of packages.
36 */
37 public function copy($packages)
38 {
39 // Iterate over each package that should be processed.
40 foreach ($packages as $package) {
41 // Retrieve some basic information about the package.
42 $type = isset($package['type']) ? $package['type'] : 'library';
43 $root = isset($package['is-root']) ? $package['is-root'] : false;
44
45 // Retrieve some information about the package.
46 $packageDir = $this->getVendorDir($package);
47 $name = isset($package['name']) ? $package['name'] : '__component__';
48 $extra = isset($package['extra']) ? $package['extra'] : array();
49 $componentName = $this->getComponentName($name, $extra);
50
51 // Cycle through each asset type.
52 $fileType = array('scripts', 'styles', 'files');
53 foreach ($fileType as $type) {
54 // Only act on the files if they're available.
55 if (isset($extra['component'][$type]) && is_array($extra['component'][$type])) {
56 foreach ($extra['component'][$type] as $file) {
57 // Make sure the file itself is available.
58 $source = $packageDir.DIRECTORY_SEPARATOR.$file;
59
60 // Perform a recursive glob file search on the pattern.
61 foreach ($this->fs->recursiveGlobFiles($source) as $filesource) {
62 // Find the final destination without the package directory.
63 $withoutPackageDir = str_replace($packageDir.DIRECTORY_SEPARATOR, '', $filesource);
64
65 // Construct the final file destination.
66 $destination = $this->componentDir.DIRECTORY_SEPARATOR.$componentName.DIRECTORY_SEPARATOR.$withoutPackageDir;
67
68 // Ensure the directory is available.
69 $this->fs->ensureDirectoryExists(dirname($destination));
70
71 // Copy the file to its destination.
72 copy($filesource, $destination);
73 }
74 }
75 }
76 }
77 }
78
79 return true;
80 }
81 }
82