Completed
Pull Request — master (#6495)
by John
14:05
created
lib/private/Template/CSSResourceLocator.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -29,113 +29,113 @@
 block discarded – undo
29 29
 
30 30
 class CSSResourceLocator extends ResourceLocator {
31 31
 
32
-	/** @var SCSSCacher */
33
-	protected $scssCacher;
34
-
35
-	/**
36
-	 * @param ILogger $logger
37
-	 * @param string $theme
38
-	 * @param array $core_map
39
-	 * @param array $party_map
40
-	 * @param SCSSCacher $scssCacher
41
-	 */
42
-	public function __construct(ILogger $logger, $theme, $core_map, $party_map, $scssCacher) {
43
-		$this->scssCacher = $scssCacher;
44
-
45
-		parent::__construct($logger, $theme, $core_map, $party_map);
46
-	}
47
-
48
-	/**
49
-	 * @param string $style
50
-	 */
51
-	public function doFind($style) {
52
-		$app = substr($style, 0, strpos($style, '/'));
53
-		if (strpos($style, '3rdparty') === 0
54
-			&& $this->appendIfExist($this->thirdpartyroot, $style.'.css')
55
-			|| $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $app)
56
-			|| $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss')
57
-			|| $this->appendIfExist($this->serverroot, $style.'.css')
58
-			|| $this->appendIfExist($this->serverroot, 'core/'.$style.'.css')
59
-		) {
60
-			return;
61
-		}
62
-		$style = substr($style, strpos($style, '/')+1);
63
-		$app_path = \OC_App::getAppPath($app);
64
-		$app_url = \OC_App::getAppWebPath($app);
65
-
66
-		if ($app_path === false && $app_url === false) {
67
-			$this->logger->error('Could not find resource {resource} to load', [
68
-				'resource' => $app . '/' . $style . '.css',
69
-				'app' => 'cssresourceloader',
70
-			]);
71
-			return;
72
-		}
73
-
74
-		if(!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', $app)) {
75
-			$this->append($app_path, $style.'.css', $app_url);
76
-		}
77
-	}
78
-
79
-	/**
80
-	 * @param string $style
81
-	 */
82
-	public function doFindTheme($style) {
83
-		$theme_dir = 'themes/'.$this->theme.'/';
84
-		$this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css')
85
-			|| $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css')
86
-			|| $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css');
87
-	}
88
-
89
-	/**
90
-	 * cache and append the scss $file if exist at $root
91
-	 *
92
-	 * @param string $root path to check
93
-	 * @param string $file the filename
94
-	 * @return bool True if the resource was found and cached, false otherwise
95
-	 */
96
-	protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') {
97
-		if (is_file($root.'/'.$file)) {
98
-			if($this->scssCacher !== null) {
99
-				if($this->scssCacher->process($root, $file, $app)) {
100
-
101
-					$this->append($root, $this->scssCacher->getCachedSCSS($app, $file), false, true, true);
102
-					return true;
103
-				} else {
104
-					$this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
105
-					return false;
106
-				}
107
-			} else {
108
-				$this->logger->debug('Scss is disabled for '.$root.'/'.$file.', ignoring', ['app' => 'core']);
109
-				return true;
110
-			}
111
-		}
112
-		return false;
113
-	}
114
-
115
-	public function append($root, $file, $webRoot = null, $throw = true, $scss = false) {
116
-		if (!$scss) {
117
-			parent::append($root, $file, $webRoot, $throw);
118
-		} else {
119
-			if (!$webRoot) {
120
-				$webRoot = $this->findWebRoot($root);
121
-
122
-				if (!$webRoot) {
123
-					$webRoot = '';
124
-					$this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
125
-						'app' => 'lib',
126
-						'root' => $root,
127
-						'file' => $file,
128
-						'webRoot' => $webRoot,
129
-						'throw' => $throw ? 'true' : 'false'
130
-					]);
131
-
132
-					if ($throw && $root === '/') {
133
-						throw new ResourceNotFoundException($file, $webRoot);
134
-					}
135
-				}
136
-			}
137
-
138
-			$this->resources[] = array($webRoot? : '/', $webRoot, $file);
139
-		}
140
-	}
32
+    /** @var SCSSCacher */
33
+    protected $scssCacher;
34
+
35
+    /**
36
+     * @param ILogger $logger
37
+     * @param string $theme
38
+     * @param array $core_map
39
+     * @param array $party_map
40
+     * @param SCSSCacher $scssCacher
41
+     */
42
+    public function __construct(ILogger $logger, $theme, $core_map, $party_map, $scssCacher) {
43
+        $this->scssCacher = $scssCacher;
44
+
45
+        parent::__construct($logger, $theme, $core_map, $party_map);
46
+    }
47
+
48
+    /**
49
+     * @param string $style
50
+     */
51
+    public function doFind($style) {
52
+        $app = substr($style, 0, strpos($style, '/'));
53
+        if (strpos($style, '3rdparty') === 0
54
+            && $this->appendIfExist($this->thirdpartyroot, $style.'.css')
55
+            || $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $app)
56
+            || $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss')
57
+            || $this->appendIfExist($this->serverroot, $style.'.css')
58
+            || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css')
59
+        ) {
60
+            return;
61
+        }
62
+        $style = substr($style, strpos($style, '/')+1);
63
+        $app_path = \OC_App::getAppPath($app);
64
+        $app_url = \OC_App::getAppWebPath($app);
65
+
66
+        if ($app_path === false && $app_url === false) {
67
+            $this->logger->error('Could not find resource {resource} to load', [
68
+                'resource' => $app . '/' . $style . '.css',
69
+                'app' => 'cssresourceloader',
70
+            ]);
71
+            return;
72
+        }
73
+
74
+        if(!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', $app)) {
75
+            $this->append($app_path, $style.'.css', $app_url);
76
+        }
77
+    }
78
+
79
+    /**
80
+     * @param string $style
81
+     */
82
+    public function doFindTheme($style) {
83
+        $theme_dir = 'themes/'.$this->theme.'/';
84
+        $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css')
85
+            || $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css')
86
+            || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css');
87
+    }
88
+
89
+    /**
90
+     * cache and append the scss $file if exist at $root
91
+     *
92
+     * @param string $root path to check
93
+     * @param string $file the filename
94
+     * @return bool True if the resource was found and cached, false otherwise
95
+     */
96
+    protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') {
97
+        if (is_file($root.'/'.$file)) {
98
+            if($this->scssCacher !== null) {
99
+                if($this->scssCacher->process($root, $file, $app)) {
100
+
101
+                    $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), false, true, true);
102
+                    return true;
103
+                } else {
104
+                    $this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
105
+                    return false;
106
+                }
107
+            } else {
108
+                $this->logger->debug('Scss is disabled for '.$root.'/'.$file.', ignoring', ['app' => 'core']);
109
+                return true;
110
+            }
111
+        }
112
+        return false;
113
+    }
114
+
115
+    public function append($root, $file, $webRoot = null, $throw = true, $scss = false) {
116
+        if (!$scss) {
117
+            parent::append($root, $file, $webRoot, $throw);
118
+        } else {
119
+            if (!$webRoot) {
120
+                $webRoot = $this->findWebRoot($root);
121
+
122
+                if (!$webRoot) {
123
+                    $webRoot = '';
124
+                    $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
125
+                        'app' => 'lib',
126
+                        'root' => $root,
127
+                        'file' => $file,
128
+                        'webRoot' => $webRoot,
129
+                        'throw' => $throw ? 'true' : 'false'
130
+                    ]);
131
+
132
+                    if ($throw && $root === '/') {
133
+                        throw new ResourceNotFoundException($file, $webRoot);
134
+                    }
135
+                }
136
+            }
137
+
138
+            $this->resources[] = array($webRoot? : '/', $webRoot, $file);
139
+        }
140
+    }
141 141
 }
Please login to merge, or discard this patch.