PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.7
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.7
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 / mrclay / minify / lib / Minify / Controller / Files.php

Files.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.7, at vendor/mrclay/minify/lib/Minify/Controller/Files.php

71 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Minify_Controller_Files
4 * @package Minify
5 */
6
7 use Monolog\Logger;
8
9 /**
10 * Controller class for minifying a set of files
11 *
12 * E.g. the following would serve the minified Javascript for a site
13 * <code>
14 * $options = [
15 * 'checkAllowDirs' => false, // allow files to be anywhere
16 * ];
17 * $sourceFactory = new Minify_Source_Factory($env, $options, $cache);
18 * $controller = new Minify_Controller_Files($env, $sourceFactory);
19 * $minify->serve($controller, [
20 * 'files' => [
21 * '//js/jquery.js',
22 * '//js/plugins.js',
23 * '/home/username/file.js',
24 * ],
25 * ]);
26 * </code>
27 *
28 * @package Minify
29 * @author Stephen Clay <[email protected]>
30 */
31 class Minify_Controller_Files extends Minify_Controller_Base
32 {
33
34 /**
35 * Set up file sources
36 *
37 * @param array $options controller and Minify options
38 * @return Minify_ServeConfiguration
39 *
40 * Controller options:
41 *
42 * 'files': (required) array of complete file paths, or a single path
43 */
44 public function createConfiguration(array $options)
45 {
46 // strip controller options
47
48 $files = $options['files'];
49 // if $files is a single object, casting will break it
50 if (is_object($files)) {
51 $files = array($files);
52 } elseif (! is_array($files)) {
53 $files = (array)$files;
54 }
55 unset($options['files']);
56
57 $sources = array();
58 foreach ($files as $file) {
59 try {
60 $sources[] = $this->sourceFactory->makeSource($file);
61 } catch (Minify_Source_FactoryException $e) {
62 $this->logger->error($e->getMessage());
63
64 return new Minify_ServeConfiguration($options);
65 }
66 }
67
68 return new Minify_ServeConfiguration($options, $sources);
69 }
70 }
71