ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ComponentInstaller\Process\RequireCssProcess Class Reference

Builds the require.css file from all Component stylesheets. More...

+ Inheritance diagram for ComponentInstaller\Process\RequireCssProcess:
+ Collaboration diagram for ComponentInstaller\Process\RequireCssProcess:

Public Member Functions

 process ()
 {{Called when running through the process.
Returns
boolean True or false depending on whether the process was successful.
}} More...
 
 packageStyles (array $packages)
 Retrieves an array of styles from a collection of packages. More...
 
- Public Member Functions inherited from ComponentInstaller\Process\Process
 __construct (Composer $composer=null, IOInterface $io=null)
 {Create a new Process.
Parameters
Composer$composerThe Composer object to act on.
IOInterface$ioInput/Output object to act on.
} More...
 
 process ()
 {Called when running through the process.
Returns
boolean True or false depending on whether the process was successful.
} More...
 
 getComponentName ($prettyName, array $extra=array())
 Retrieves the component name for the component. More...
 
 getComponentDir ()
 Retrieves the component directory. More...
 
 setComponentDir ($dir)
 Sets the component directory. More...
 
 getVendorDir (array $package)
 Retrieves the given package's vendor directory, where it's installed. More...
 
- Public Member Functions inherited from ComponentInstaller\Process\ProcessInterface
 __construct (Composer $composer, IOInterface $io)
 Create a new Process. More...
 
 init ()
 Initialize the process before its run. More...
 
 process ()
 Called when running through the process. More...
 

Additional Inherited Members

- Protected Attributes inherited from ComponentInstaller\Process\Process
 $composer
 
 $io
 
 $config
 
 $packages = array()
 
 $componentDir = 'components'
 
 $fs
 
 $installationManager
 

Detailed Description

Builds the require.css file from all Component stylesheets.

Definition at line 23 of file RequireCssProcess.php.

Member Function Documentation

◆ packageStyles()

ComponentInstaller\Process\RequireCssProcess::packageStyles ( array  $packages)

Retrieves an array of styles from a collection of packages.

Parameters
array$packagesAn array of packages from the composer.lock file.
Returns
array A set of package styles.

Definition at line 98 of file RequireCssProcess.php.

99 {
100 $output = array();
101
102 // Construct the packages configuration.
103 foreach ($packages as $package) {
104 // Retrieve information from the extra options.
105 $extra = isset($package['extra']) ? $package['extra'] : array();
106 $name = $this->getComponentName($package['name'], $extra);
107 $component = isset($extra['component']) ? $extra['component'] : array();
108 $styles = isset($component['styles']) ? $component['styles'] : array();
109 $vendorDir = $this->getVendorDir($package);
110
111 // Loop through each style.
112 foreach ($styles as $style) {
113 // Find the style path from the vendor directory.
114 $path = strtr($vendorDir.'/'.$style, '/', DIRECTORY_SEPARATOR);
115
116 // Search for the candidate with a glob recursive file search.
117 $files = $this->fs->recursiveGlobFiles($path);
118 foreach ($files as $file) {
119 // Provide the package name, style and full path.
120 $output[$name][$style][] = $file;
121 }
122 }
123 }
124
125 return $output;
126 }
$files
Definition: add-vimline.php:18
$path
Definition: aliased.php:25
$vendorDir
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
$style
Definition: example_012.php:70
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $file, $files, $output, ComponentInstaller\Process\Process\$packages, $path, $style, $styles, $vendorDir, ComponentInstaller\Process\Process\getComponentName(), and ComponentInstaller\Process\Process\getVendorDir().

Referenced by ComponentInstaller\Process\RequireCssProcess\process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ process()

ComponentInstaller\Process\RequireCssProcess::process ( )

{{Called when running through the process.

Returns
boolean True or false depending on whether the process was successful.
}}

Reimplemented from ComponentInstaller\Process\Process.

Definition at line 28 of file RequireCssProcess.php.

29 {
30 $filters = array(new CssRewriteFilter());
31 if ($this->config->has('component-styleFilters')) {
32 $customFilters = $this->config->get('component-styleFilters');
33 if (isset($customFilters) && is_array($customFilters)) {
34 foreach ($customFilters as $filter => $filterParams) {
35 $reflection = new \ReflectionClass($filter);
36 $filters[] = $reflection->newInstanceArgs($filterParams);
37 }
38 }
39 }
40
41 $filterCollection = new FilterCollection($filters);
42
43 $assets = new AssetCollection();
44 $styles = $this->packageStyles($this->packages);
45 foreach ($styles as $package => $packageStyles) {
46 $packageAssets = new AssetCollection();
47 $packagePath = $this->componentDir.'/'.$package;
48
49 foreach ($packageStyles as $style => $paths) {
50 foreach ($paths as $path) {
51 // The full path to the CSS file.
52 $assetPath = realpath($path);
53 // The root of the CSS file.
54 $sourceRoot = dirname($path);
55 // The style path to the CSS file when external.
56 $sourcePath = $package . '/' . $style;
57 //Replace glob patterns with filenames.
58 $filename = basename($style);
59 if(preg_match('~^\*(\.[^\.]+)$~', $filename, $matches)){
60 $sourcePath = str_replace($filename, basename($assetPath), $sourcePath);
61 }
62 // Where the final CSS will be generated.
63 $targetPath = $this->componentDir;
64 // Build the asset and add it to the collection.
65 $asset = new FileAsset($assetPath, $filterCollection, $sourceRoot, $sourcePath);
66 $asset->setTargetPath($targetPath);
67 $assets->add($asset);
68 // Add asset to package collection.
69 $sourcePath = preg_replace('{^.*'.preg_quote($package).'/}', '', $sourcePath);
70 $asset = new FileAsset($assetPath, $filterCollection, $sourceRoot, $sourcePath);
71 $asset->setTargetPath($packagePath);
72 $packageAssets->add($asset);
73 }
74 }
75
76 if (file_put_contents($packagePath.'/'.$package.'-built.css', $packageAssets->dump()) === FALSE) {
77 $this->io->write("<error>Error writing $package-built.css to destination</error>");
78 }
79 }
80
81 if (file_put_contents($this->componentDir . '/require.css', $assets->dump()) === FALSE) {
82 $this->io->write('<error>Error writing require.css to destination</error>');
83 return false;
84 }
85
86 return null;
87 }
packageStyles(array $packages)
Retrieves an array of styles from a collection of packages.

References ComponentInstaller\Process\Process\$componentDir, $filename, $path, $style, $styles, and ComponentInstaller\Process\RequireCssProcess\packageStyles().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: