-
Notifications
You must be signed in to change notification settings - Fork 3
/
start.php
executable file
·98 lines (80 loc) · 2.2 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Push the bootstrap until after application start to give time to set configs
*/
Event::listen('laravel.started: twig', function()
{
/**
* Grab the Twig file extension.
*/
$ext = Config::get('twig::config.extension');
/**
* Get the path to the Twig compilation directory.
*/
$cache = Config::get('twig::config.cache');
/**
* Get various other Twig configuration items
*/
$debug = Config::get('twig::config.debug');
$autoescape = Config::get('twig::config.autoescape');
/**
* Make the cache directory if it is enabled and doesn't exist.
*/
if ($cache and ! is_dir($cache)) mkdir($cache);
/**
* Register the Twig library with the auto-loader
*/
Laravel\Autoloader::underscored(array(
'Twig' => Bundle::path('twig').'lib/Twig')
);
/**
* Instantiate a new Laravel Twig loader
*/
include 'loader.php';
/**
* If it's registered in the IoC, resolve from there... otherwise use default
*/
if (IoC::registered('twig::loader'))
{
$loader = IoC::resolve('twig::loader');
}
else
{
$loader = new Laravel_Twig_Loader($ext);
}
/**
* Hook into the Laravel view loader
*/
Laravel\Event::override(Laravel\View::loader, function($bundle, $view) use ($loader, $ext)
{
// Use the custom Laravel Twig loader for Twig views...
if (starts_with($view, 'twig|'))
{
return $loader->getPath($bundle, substr($view, 5));
}
elseif (starts_with($bundle, 'twig|'))
{
return $loader->getPath(substr($bundle, 5), $view);
}
// Otherwise use the default Laravel loading conventions...
else
{
return View::file($bundle, $view);
}
});
/**
* Hook into the Laravel view engine
*/
Laravel\Event::listen(Laravel\View::engine, function($view) use ($loader, $cache, $ext, $debug, $autoescape)
{
// Only handle views that have the Twig marker
if ( ! starts_with($view->view, 'twig|')) return false;
// Load the Laravel Twig extensions
require_once 'extensions/HTML.php';
$twig = new Twig_Environment($loader, compact('cache', 'debug', 'autoescape'));
// Register the Laravel Twig extensions
$twig->addExtension(new Laravel_Twig_Extension);
// Render back the template contents
return $twig->render(substr($view->view, 5), $view->data());
});
});