Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
72d7746e
Commit
72d7746e
authored
Nov 06, 2016
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added support for Twig runtime loaders
parent
147d7cc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
src/Silex/Provider/Twig/RuntimeLoader.php
src/Silex/Provider/Twig/RuntimeLoader.php
+41
-0
src/Silex/Provider/TwigServiceProvider.php
src/Silex/Provider/TwigServiceProvider.php
+21
-0
No files found.
src/Silex/Provider/Twig/RuntimeLoader.php
0 → 100644
View file @
72d7746e
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Silex\Provider\Twig
;
use
Pimple\Container
;
/**
* Loads Twig extension runtimes via Pimple.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class
RuntimeLoader
implements
\Twig_RuntimeLoaderInterface
{
private
$container
;
private
$mapping
;
public
function
__construct
(
Container
$container
,
array
$mapping
)
{
$this
->
container
=
$container
;
$this
->
mapping
=
$mapping
;
}
/**
* {@inheritdoc}
*/
public
function
load
(
$class
)
{
if
(
isset
(
$this
->
mapping
[
$class
]))
{
return
$this
->
container
[
$this
->
mapping
[
$class
]];
}
}
}
src/Silex/Provider/TwigServiceProvider.php
View file @
72d7746e
...
@@ -13,6 +13,7 @@ namespace Silex\Provider;
...
@@ -13,6 +13,7 @@ namespace Silex\Provider;
use
Pimple\Container
;
use
Pimple\Container
;
use
Pimple\ServiceProviderInterface
;
use
Pimple\ServiceProviderInterface
;
use
Silex\Provider\Twig\RuntimeLoader
;
use
Symfony\Bridge\Twig\AppVariable
;
use
Symfony\Bridge\Twig\AppVariable
;
use
Symfony\Bridge\Twig\Extension\AssetExtension
;
use
Symfony\Bridge\Twig\Extension\AssetExtension
;
use
Symfony\Bridge\Twig\Extension\DumpExtension
;
use
Symfony\Bridge\Twig\Extension\DumpExtension
;
...
@@ -24,6 +25,7 @@ use Symfony\Bridge\Twig\Extension\HttpFoundationExtension;
...
@@ -24,6 +25,7 @@ use Symfony\Bridge\Twig\Extension\HttpFoundationExtension;
use
Symfony\Bridge\Twig\Extension\HttpKernelExtension
;
use
Symfony\Bridge\Twig\Extension\HttpKernelExtension
;
use
Symfony\Bridge\Twig\Form\TwigRendererEngine
;
use
Symfony\Bridge\Twig\Form\TwigRendererEngine
;
use
Symfony\Bridge\Twig\Form\TwigRenderer
;
use
Symfony\Bridge\Twig\Form\TwigRenderer
;
use
Symfony\Bridge\Twig\Extension\HttpKernelRuntime
;
/**
/**
* Twig integration for Silex.
* Twig integration for Silex.
...
@@ -118,6 +120,10 @@ class TwigServiceProvider implements ServiceProviderInterface
...
@@ -118,6 +120,10 @@ class TwigServiceProvider implements ServiceProviderInterface
if
(
isset
(
$app
[
'var_dumper.cloner'
]))
{
if
(
isset
(
$app
[
'var_dumper.cloner'
]))
{
$twig
->
addExtension
(
new
DumpExtension
(
$app
[
'var_dumper.cloner'
]));
$twig
->
addExtension
(
new
DumpExtension
(
$app
[
'var_dumper.cloner'
]));
}
}
if
(
class_exists
(
HttpKernelRuntime
::
class
))
{
$twig
->
addRuntimeLoader
(
$app
[
'twig.runtime_loader'
]);
}
}
}
return
$twig
;
return
$twig
;
...
@@ -141,5 +147,20 @@ class TwigServiceProvider implements ServiceProviderInterface
...
@@ -141,5 +147,20 @@ class TwigServiceProvider implements ServiceProviderInterface
$app
[
'twig.environment_factory'
]
=
$app
->
protect
(
function
(
$app
)
{
$app
[
'twig.environment_factory'
]
=
$app
->
protect
(
function
(
$app
)
{
return
new
\Twig_Environment
(
$app
[
'twig.loader'
],
$app
[
'twig.options'
]);
return
new
\Twig_Environment
(
$app
[
'twig.loader'
],
$app
[
'twig.options'
]);
});
});
$app
[
'twig.runtime.httpkernel'
]
=
function
(
$app
)
{
return
new
HttpKernelRuntime
(
$app
[
'fragment.handler'
]);
};
$app
[
'twig.runtimes'
]
=
function
(
$app
)
{
return
array
(
HttpKernelRuntime
::
class
=>
'twig.runtime.httpkernel'
,
TwigRenderer
::
class
=>
'twig.form.renderer'
,
);
};
$app
[
'twig.runtime_loader'
]
=
function
(
$app
)
{
return
new
RuntimeLoader
(
$app
,
$app
[
'twig.runtimes'
]);
};
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment