forked from jasonlewis/basset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.php
77 lines (64 loc) · 2.42 KB
/
start.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Register all the classes that are used by Basset with the autoloader.
*/
Autoloader::map(array(
'Basset' => __DIR__ . DS . 'classes' . DS . 'basset.php',
'Basset\\Asset' => __DIR__ . DS . 'classes' . DS . 'asset.php',
'Basset\\Cache' => __DIR__ . DS . 'classes' . DS . 'cache.php',
'Basset\\Config' => __DIR__ . DS . 'classes' . DS . 'config.php',
'Basset\\Container' => __DIR__ . DS . 'classes' . DS . 'container.php',
'Basset\\Vendor\\CSSCompress' => __DIR__ . DS . 'classes' . DS . 'vendor' . DS . 'csscompress.php',
'Basset\\Vendor\\JSMin' => __DIR__ . DS . 'classes' . DS . 'vendor' . DS . 'jsmin.php',
'Basset\\Vendor\\URIRewriter' => __DIR__ . DS . 'classes' . DS . 'vendor' . DS . 'urirewriter.php',
'Basset\\Vendor\\lessc' => __DIR__ . DS . 'classes' . DS . 'vendor' . DS . 'less.php'
));
if(starts_with(URI::current(), Bundle::option('basset', 'handles')))
{
/**
* In this before filter we'll grab the compiled assets for this route and return them here.
* This is what makes it possible for Basset routes to be adjusted prior to them being displayed.
*/
$handler = Bundle::handles(URI::current());
Route::filter("{$handler}::before", function()
{
Config::set('session.driver', '');
return Basset::compiled();
});
/**
* After the Basset route is run we'll adjust the response object setting the appropriate content
* type for the assets.
*/
Route::filter("{$handler}::after", function($response)
{
$types = array(
'less' => 'text/css',
'sass' => 'text/css',
'scss' => 'text/css',
'css' => 'text/css',
'js' => 'text/javascript'
);
$extension = File::extension(Request::uri());
if(array_key_exists($extension, $types))
{
$response->header('Content-Type', $types[$extension]);
$response->header('Cache-Control', 'max-age='.(24*60*60).', public');
$response->header('Pragma', 'cache');
$response->header('Last-Modified', gmdate('D, d M Y H:i:s').' GMT');
}
// To prevent any further output being added to any Basset routes we'll clear any events listening
// for the laravel.done event.
Event::clear('laravel.done');
});
}
/**
* If the current URI is not being handled by Basset then all registered Basset routes will be
* compiled once Laravel has finished doing its thing.
*/
if(!starts_with(URI::current(), Bundle::option('basset', 'handles')))
{
Event::listen('laravel.done', function()
{
Basset::compile();
});
}