Skip to content

Commit bfff974

Browse files
author
Andrew Smith
committed
updated the TwigView and Autoloader to use Twig Extensions path and included support for Composer
1 parent 3c3434e commit bfff974

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

Views/Extension/README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ the Extension directory under the template parser directory of choice.
88
To use this in Twig just include the code below at the top of your Slim index.php file after including TwigView.
99

1010
TwigView::$twigExtensions = array(
11-
'Extension_Twig_Slim',
11+
'Twig_Extensions_Slim',
1212
);
1313

1414
Inside your Smarty template you would write:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class Extension_Twig_Slim extends Twig_Extension
3+
class Twig_Extensions_Slim extends Twig_Extension
44
{
55
public function getName()
66
{

Views/Extension/TwigAutoloader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ static public function register()
3535
*/
3636
static public function autoload($class)
3737
{
38-
if (0 !== strpos($class, 'Extension_Twig')) {
38+
if (0 !== strpos($class, 'Twig_Extensions')) {
3939
return;
4040
}
4141

42-
if (file_exists($file = dirname(dirname(__FILE__)) . '/' . str_replace('_', '/', $class).'.php')) {
42+
if (file_exists($file = dirname(__FILE__) . '/' . str_replace('_', '/', $class).'.php')) {
4343
require $file;
4444
}
4545
}

Views/TwigView.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ public function render( $template ) {
8282
*/
8383
public function getEnvironment() {
8484
if ( !$this->twigEnvironment ) {
85-
require_once self::$twigDirectory . '/Autoloader.php';
85+
/*
86+
* Check for Composer Package Autoloader class loading
87+
*/
88+
if (!class_exists('Twig_Autoloader')) {
89+
require_once self::$twigDirectory . '/Autoloader.php';
90+
}
91+
8692
Twig_Autoloader::register();
8793
$loader = new Twig_Loader_Filesystem($this->getTemplatesDirectory());
8894
$this->twigEnvironment = new Twig_Environment(

Views/composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "slim/extras",
3+
"type": "library",
4+
"description": "Extras package for Slim Framework",
5+
"keywords": ["templating","extensions"],
6+
"homepage": "http://github.com/codeguy/Slim-Extras",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Josh Lockhart",
11+
"email": "[email protected]",
12+
"homepage": "http://www.joshlockhart.com/"
13+
},
14+
{
15+
"name": "Andrew Smith",
16+
"email": "[email protected]"
17+
}
18+
],
19+
"require": {
20+
"php": ">=5.2.0"
21+
},
22+
"autoload": {
23+
"psr-0": { "Twig_Extensions_": "Extension/" }
24+
}
25+
}

0 commit comments

Comments
 (0)