Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
199 lars 1
<?php namespace Clockwork\Web;
2
 
3
// Helper class for serving app assets
4
class Web
5
{
6
	// Return the absolute path and a mime type of an asset, protects from accessing files outside Clockwork public dir
7
	public function asset($path)
8
	{
9
		$path = $this->resolveAssetPath($path);
10
 
11
		if (! $path) return;
12
 
13
		switch (pathinfo($path, PATHINFO_EXTENSION)) {
14
			case 'css': $mime = 'text/css'; break;
15
			case 'js': $mime = 'application/javascript'; break;
16
			case 'json': $mime = 'application/json'; break;
17
			case 'png': $mime = 'image/png'; break;
18
			default: $mime = 'text/html'; break;
19
		}
20
 
21
		return [
22
			'path' => $path,
23
			'mime' => $mime
24
		];
25
	}
26
 
27
	// Resolves absolute path of the asset, protects from accessing files outside Clockwork public dir
28
	protected function resolveAssetPath($path)
29
	{
30
		$publicPath = realpath(__DIR__ . '/public');
31
 
32
		$path = realpath("$publicPath/{$path}");
33
 
34
		return strpos($path, $publicPath) === 0 ? $path : false;
35
	}
36
}