Completed
Push — master ( 146c69...6a1c49 )
by Morris
21:32
created
lib/private/Template/ResourceLocator.php 1 patch
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -27,106 +27,106 @@  discard block
 block discarded – undo
27 27
 namespace OC\Template;
28 28
 
29 29
 abstract class ResourceLocator {
30
-	protected $theme;
31
-
32
-	protected $mapping;
33
-	protected $serverroot;
34
-	protected $thirdpartyroot;
35
-	protected $webroot;
36
-
37
-	protected $resources = array();
38
-
39
-	/** @var \OCP\ILogger */
40
-	protected $logger;
41
-
42
-	/**
43
-	 * @param \OCP\ILogger $logger
44
-	 * @param string $theme
45
-	 * @param array $core_map
46
-	 * @param array $party_map
47
-	 */
48
-	public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) {
49
-		$this->logger = $logger;
50
-		$this->theme = $theme;
51
-		$this->mapping = $core_map + $party_map;
52
-		$this->serverroot = key($core_map);
53
-		$this->thirdpartyroot = key($party_map);
54
-		$this->webroot = $this->mapping[$this->serverroot];
55
-	}
56
-
57
-	/**
58
-	 * @param string $resource
59
-	 */
60
-	abstract public function doFind($resource);
61
-
62
-	/**
63
-	 * @param string $resource
64
-	 */
65
-	abstract public function doFindTheme($resource);
66
-
67
-	/**
68
-	 * Finds the resources and adds them to the list
69
-	 *
70
-	 * @param array $resources
71
-	 */
72
-	public function find($resources) {
73
-		foreach ($resources as $resource) {
74
-			try {
75
-				$this->doFind($resource);
76
-			} catch (ResourceNotFoundException $e) {
77
-				$resourceApp = substr($resource, 0, strpos($resource, '/'));
78
-				$this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
79
-			}
80
-		}
81
-		if (!empty($this->theme)) {
82
-			foreach ($resources as $resource) {
83
-				try {
84
-					$this->doFindTheme($resource);
85
-				} catch (ResourceNotFoundException $e) {
86
-					$resourceApp = substr($resource, 0, strpos($resource, '/'));
87
-					$this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
88
-				}
89
-			}
90
-		}
91
-	}
92
-
93
-	/**
94
-	 * append the $file resource if exist at $root
95
-	 *
96
-	 * @param string $root path to check
97
-	 * @param string $file the filename
98
-	 * @param string|null $webRoot base for path, default map $root to $webRoot
99
-	 * @return bool True if the resource was found, false otherwise
100
-	 */
101
-	protected function appendIfExist($root, $file, $webRoot = null) {
102
-		if (is_file($root.'/'.$file)) {
103
-			$this->append($root, $file, $webRoot, false);
104
-			return true;
105
-		}
106
-		return false;
107
-	}
108
-
109
-	/**
110
-	 * append the $file resource at $root
111
-	 *
112
-	 * @param string $root path to check
113
-	 * @param string $file the filename
114
-	 * @param string|null $webRoot base for path, default map $root to $webRoot
115
-	 * @param bool $throw Throw an exception, when the route does not exist
116
-	 * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing
117
-	 */
118
-	protected function append($root, $file, $webRoot = null, $throw = true) {
119
-
120
-		if (!is_string($root)) {
121
-			if ($throw) {
122
-				throw new ResourceNotFoundException($file, $webRoot);
123
-			}
124
-			return;
125
-		}
126
-
127
-		if (!$webRoot) {
128
-			$tmpRoot = realpath($root);
129
-			/*
30
+    protected $theme;
31
+
32
+    protected $mapping;
33
+    protected $serverroot;
34
+    protected $thirdpartyroot;
35
+    protected $webroot;
36
+
37
+    protected $resources = array();
38
+
39
+    /** @var \OCP\ILogger */
40
+    protected $logger;
41
+
42
+    /**
43
+     * @param \OCP\ILogger $logger
44
+     * @param string $theme
45
+     * @param array $core_map
46
+     * @param array $party_map
47
+     */
48
+    public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) {
49
+        $this->logger = $logger;
50
+        $this->theme = $theme;
51
+        $this->mapping = $core_map + $party_map;
52
+        $this->serverroot = key($core_map);
53
+        $this->thirdpartyroot = key($party_map);
54
+        $this->webroot = $this->mapping[$this->serverroot];
55
+    }
56
+
57
+    /**
58
+     * @param string $resource
59
+     */
60
+    abstract public function doFind($resource);
61
+
62
+    /**
63
+     * @param string $resource
64
+     */
65
+    abstract public function doFindTheme($resource);
66
+
67
+    /**
68
+     * Finds the resources and adds them to the list
69
+     *
70
+     * @param array $resources
71
+     */
72
+    public function find($resources) {
73
+        foreach ($resources as $resource) {
74
+            try {
75
+                $this->doFind($resource);
76
+            } catch (ResourceNotFoundException $e) {
77
+                $resourceApp = substr($resource, 0, strpos($resource, '/'));
78
+                $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
79
+            }
80
+        }
81
+        if (!empty($this->theme)) {
82
+            foreach ($resources as $resource) {
83
+                try {
84
+                    $this->doFindTheme($resource);
85
+                } catch (ResourceNotFoundException $e) {
86
+                    $resourceApp = substr($resource, 0, strpos($resource, '/'));
87
+                    $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]);
88
+                }
89
+            }
90
+        }
91
+    }
92
+
93
+    /**
94
+     * append the $file resource if exist at $root
95
+     *
96
+     * @param string $root path to check
97
+     * @param string $file the filename
98
+     * @param string|null $webRoot base for path, default map $root to $webRoot
99
+     * @return bool True if the resource was found, false otherwise
100
+     */
101
+    protected function appendIfExist($root, $file, $webRoot = null) {
102
+        if (is_file($root.'/'.$file)) {
103
+            $this->append($root, $file, $webRoot, false);
104
+            return true;
105
+        }
106
+        return false;
107
+    }
108
+
109
+    /**
110
+     * append the $file resource at $root
111
+     *
112
+     * @param string $root path to check
113
+     * @param string $file the filename
114
+     * @param string|null $webRoot base for path, default map $root to $webRoot
115
+     * @param bool $throw Throw an exception, when the route does not exist
116
+     * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing
117
+     */
118
+    protected function append($root, $file, $webRoot = null, $throw = true) {
119
+
120
+        if (!is_string($root)) {
121
+            if ($throw) {
122
+                throw new ResourceNotFoundException($file, $webRoot);
123
+            }
124
+            return;
125
+        }
126
+
127
+        if (!$webRoot) {
128
+            $tmpRoot = realpath($root);
129
+            /*
130 130
 			 * traverse the potential web roots upwards in the path
131 131
 			 *
132 132
 			 * example:
@@ -137,39 +137,39 @@  discard block
 block discarded – undo
137 137
 			 * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
138 138
 			 * valid web root
139 139
 			 */
140
-			do {
141
-				if (isset($this->mapping[$tmpRoot])) {
142
-					$webRoot = $this->mapping[$tmpRoot];
143
-					break;
144
-				}
145
-
146
-				if ($tmpRoot === '/') {
147
-					$webRoot = '';
148
-					$this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
149
-						'app' => 'lib',
150
-						'root' => $root,
151
-						'file' => $file,
152
-						'webRoot' => $webRoot,
153
-						'throw' => $throw ? 'true' : 'false'
154
-					]);
155
-					break;
156
-				}
157
-				$tmpRoot = dirname($tmpRoot);
158
-			} while(true);
159
-
160
-		}
161
-		$this->resources[] = array($root, $webRoot, $file);
162
-
163
-		if ($throw && !is_file($root . '/' . $file)) {
164
-			throw new ResourceNotFoundException($file, $webRoot);
165
-		}
166
-	}
167
-
168
-	/**
169
-	 * Returns the list of all resources that should be loaded
170
-	 * @return array
171
-	 */
172
-	public function getResources() {
173
-		return $this->resources;
174
-	}
140
+            do {
141
+                if (isset($this->mapping[$tmpRoot])) {
142
+                    $webRoot = $this->mapping[$tmpRoot];
143
+                    break;
144
+                }
145
+
146
+                if ($tmpRoot === '/') {
147
+                    $webRoot = '';
148
+                    $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
149
+                        'app' => 'lib',
150
+                        'root' => $root,
151
+                        'file' => $file,
152
+                        'webRoot' => $webRoot,
153
+                        'throw' => $throw ? 'true' : 'false'
154
+                    ]);
155
+                    break;
156
+                }
157
+                $tmpRoot = dirname($tmpRoot);
158
+            } while(true);
159
+
160
+        }
161
+        $this->resources[] = array($root, $webRoot, $file);
162
+
163
+        if ($throw && !is_file($root . '/' . $file)) {
164
+            throw new ResourceNotFoundException($file, $webRoot);
165
+        }
166
+    }
167
+
168
+    /**
169
+     * Returns the list of all resources that should be loaded
170
+     * @return array
171
+     */
172
+    public function getResources() {
173
+        return $this->resources;
174
+    }
175 175
 }
Please login to merge, or discard this patch.
lib/private/Template/CSSResourceLocator.php 1 patch
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -29,96 +29,96 @@  discard block
 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
-				$tmpRoot = realpath($root);
121
-				/*
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
+                $tmpRoot = realpath($root);
121
+                /*
122 122
 				 * traverse the potential web roots upwards in the path
123 123
 				 *
124 124
 				 * example:
@@ -129,33 +129,33 @@  discard block
 block discarded – undo
129 129
 				 * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
130 130
 				 * valid web root
131 131
 				 */
132
-				do {
133
-					if (isset($this->mapping[$tmpRoot])) {
134
-						$webRoot = $this->mapping[$tmpRoot];
135
-						break;
136
-					}
137
-
138
-					if ($tmpRoot === '/') {
139
-						$webRoot = '';
140
-						$this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
141
-							'app' => 'lib',
142
-							'root' => $root,
143
-							'file' => $file,
144
-							'webRoot' => $webRoot,
145
-							'throw' => $throw ? 'true' : 'false'
146
-						]);
147
-						break;
148
-					}
149
-					$tmpRoot = dirname($tmpRoot);
150
-				} while(true);
151
-
152
-			}
153
-
154
-			if ($throw && $tmpRoot === '/') {
155
-				throw new ResourceNotFoundException($file, $webRoot);
156
-			}
157
-
158
-			$this->resources[] = array($tmpRoot, $webRoot, $file);
159
-		}
160
-	}
132
+                do {
133
+                    if (isset($this->mapping[$tmpRoot])) {
134
+                        $webRoot = $this->mapping[$tmpRoot];
135
+                        break;
136
+                    }
137
+
138
+                    if ($tmpRoot === '/') {
139
+                        $webRoot = '';
140
+                        $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
141
+                            'app' => 'lib',
142
+                            'root' => $root,
143
+                            'file' => $file,
144
+                            'webRoot' => $webRoot,
145
+                            'throw' => $throw ? 'true' : 'false'
146
+                        ]);
147
+                        break;
148
+                    }
149
+                    $tmpRoot = dirname($tmpRoot);
150
+                } while(true);
151
+
152
+            }
153
+
154
+            if ($throw && $tmpRoot === '/') {
155
+                throw new ResourceNotFoundException($file, $webRoot);
156
+            }
157
+
158
+            $this->resources[] = array($tmpRoot, $webRoot, $file);
159
+        }
160
+    }
161 161
 }
Please login to merge, or discard this patch.