2016-09-29 18:22:33 +01:00
< ? php
/*
* This file is part of the Symfony package .
*
* ( 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 Symfony\Bundle\TwigBundle ;
2017-12-31 05:33:21 +00:00
@ trigger_error ( sprintf ( 'The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use the Twig\RuntimeLoader\ContainerRuntimeLoader class instead.' , ContainerAwareRuntimeLoader :: class ), E_USER_DEPRECATED );
2017-02-14 19:09:41 +00:00
2016-10-01 17:45:45 +01:00
use Psr\Log\LoggerInterface ;
2016-09-29 18:22:33 +01:00
use Symfony\Component\DependencyInjection\ContainerInterface ;
2017-06-02 09:55:39 +01:00
use Twig\RuntimeLoader\RuntimeLoaderInterface ;
2016-09-29 18:22:33 +01:00
/**
* Loads Twig extension runtimes via the service container .
*
* @ author Fabien Potencier < fabien @ symfony . com >
2017-02-14 19:09:41 +00:00
*
2017-06-02 09:55:39 +01:00
* @ deprecated since version 3.3 , will be removed in 4.0 . Use \Twig\Loader\ContainerRuntimeLoader instead .
2016-09-29 18:22:33 +01:00
*/
2017-06-02 09:55:39 +01:00
class ContainerAwareRuntimeLoader implements RuntimeLoaderInterface
2016-09-29 18:22:33 +01:00
{
private $container ;
private $mapping ;
2016-10-01 17:45:45 +01:00
private $logger ;
2016-09-29 18:22:33 +01:00
2016-10-01 17:45:45 +01:00
public function __construct ( ContainerInterface $container , array $mapping , LoggerInterface $logger = null )
2016-09-29 18:22:33 +01:00
{
$this -> container = $container ;
$this -> mapping = $mapping ;
2016-10-01 17:45:45 +01:00
$this -> logger = $logger ;
2016-09-29 18:22:33 +01:00
}
/**
* { @ inheritdoc }
*/
public function load ( $class )
{
2016-10-01 17:45:45 +01:00
if ( isset ( $this -> mapping [ $class ])) {
return $this -> container -> get ( $this -> mapping [ $class ]);
2016-09-29 18:22:33 +01:00
}
2016-10-01 17:45:45 +01:00
if ( null !== $this -> logger ) {
$this -> logger -> warning ( sprintf ( 'Class "%s" is not configured as a Twig runtime. Add the "twig.runtime" tag to the related service in the container.' , $class ));
}
2019-08-19 22:30:37 +01:00
return null ;
2016-09-29 18:22:33 +01:00
}
}