ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
CopyProcess.php
Go to the documentation of this file.
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
13
17class CopyProcess extends Process
18{
22 public function process()
23 {
24 return $this->copy($this->packages);
25 }
26
34 public function copy($packages)
35 {
36 // Iterate over each package that should be processed.
37 foreach ($packages as $package) {
38 // Retrieve some information about the package.
39 $packageDir = $this->getVendorDir($package);
40 $name = isset($package['name']) ? $package['name'] : '__component__';
41 $extra = isset($package['extra']) ? $package['extra'] : array();
42 $componentName = $this->getComponentName($name, $extra);
43
44 // Cycle through each asset type.
45 $fileType = array('scripts', 'styles', 'files');
46 foreach ($fileType as $type) {
47 // Only act on the files if they're available.
48 if (isset($extra['component'][$type]) && is_array($extra['component'][$type])) {
49 foreach ($extra['component'][$type] as $file) {
50 // Make sure the file itself is available.
51 $source = $packageDir.DIRECTORY_SEPARATOR.$file;
52
53 // Perform a recursive glob file search on the pattern.
54 foreach ($this->fs->recursiveGlobFiles($source) as $filesource) {
55 // Find the final destination without the package directory.
56 $withoutPackageDir = str_replace($packageDir.DIRECTORY_SEPARATOR, '', $filesource);
57
58 // Construct the final file destination.
59 $destination = $this->componentDir.DIRECTORY_SEPARATOR.$componentName.DIRECTORY_SEPARATOR.$withoutPackageDir;
60
61 // Ensure the directory is available.
62 $this->fs->ensureDirectoryExists(dirname($destination));
63
64 // Copy the file to its destination.
65 copy($filesource, $destination);
66 }
67 }
68 }
69 }
70 }
71
72 return true;
73 }
74}
An exception for terminatinating execution or to throw for unit testing.
Process which copies components from their source to the components folder.
Definition: CopyProcess.php:18
process()
{{Called when running through the process.boolean True or false depending on whether the process was ...
Definition: CopyProcess.php:22
copy($packages)
Copy file assets from the given packages to the component directory.
Definition: CopyProcess.php:34
The base Process type.
Definition: Process.php:27
getComponentName($prettyName, array $extra=array())
Retrieves the component name for the component.
Definition: Process.php:154
getVendorDir(array $package)
Retrieves the given package's vendor directory, where it's installed.
Definition: Process.php:199
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file