PluginProbe
WP Super Minify • Minify, Compress and Cache HTML, CSS & JavaScript / trunk
WP Super Minify • Minify, Compress and Cache HTML, CSS & JavaScript vtrunk
trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.4 1.5 1.5.1 1.6 2.0 2.0.1
wp-super-minify / includes / min / lib / Minify / Controller / Files.php

Files.php in WP Super Minify • Minify, Compress and Cache HTML, CSS & JavaScript trunk, at includes/min/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 <steve@mrclay.org>
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