Skip to content

Commit a525cc7

Browse files
authored
Merge pull request #33 from suzumaze/2.x
update twig 2.7
2 parents c44d81a + 06447be commit a525cc7

11 files changed

+48
-41
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"php": ">=7.0.0",
1818
"bear/sunday": "^1.2",
1919
"bear/app-meta": "^1.1",
20-
"twig/twig": "^2.4.8",
20+
"twig/twig": "^2.7",
2121
"mobiledetect/mobiledetectlib": "^2.7",
2222
"ray/di": "^2.7"
2323
},

src/ErrorPagerRenderer.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
use BEAR\Resource\RenderInterface;
1010
use BEAR\Resource\ResourceObject;
1111
use Madapaja\TwigModule\Annotation\TwigErrorPath;
12+
use Twig\Environment;
1213

1314
class ErrorPagerRenderer implements RenderInterface
1415
{
1516
/**
16-
* @var \Twig_Environment
17+
* @var Environment
1718
*/
1819
private $twig;
1920

@@ -22,16 +23,16 @@ class ErrorPagerRenderer implements RenderInterface
2223
/**
2324
* @TwigErrorPath("errorPage")
2425
*/
25-
public function __construct(\Twig_Environment $twig, string $errorPage)
26+
public function __construct(Environment $twig, string $errorPage)
2627
{
2728
$this->twig = $twig;
2829
$this->errorPage = $errorPage;
2930
}
3031

3132
/**
32-
* @throws \Twig_Error_Loader
33-
* @throws \Twig_Error_Runtime
34-
* @throws \Twig_Error_Syntax
33+
* @throws \Twig\Error\LoaderError
34+
* @throws \Twig\Error\RuntimeError
35+
* @throws \Twig\Error\SyntaxError
3536
*
3637
* @return string
3738
*/

src/TwigErrorHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
namespace Madapaja\TwigModule;
88

9-
use BEAR\Package\Provide\Error\LogRef;
109
use BEAR\Resource\Code;
1110
use BEAR\Resource\Exception\BadRequestException as BadRequest;
1211
use BEAR\Resource\Exception\ResourceNotFoundException as NotFound;

src/TwigModule.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
use Madapaja\TwigModule\Annotation\TwigPaths;
1313
use Ray\Di\AbstractModule;
1414
use Ray\Di\Scope;
15-
use Twig_Environment;
16-
use Twig_Loader_Filesystem;
17-
use Twig_LoaderInterface;
15+
use Twig\Environment;
16+
use Twig\Loader\FilesystemLoader;
17+
use Twig\Loader\LoaderInterface;
1818

1919
class TwigModule extends AbstractModule
2020
{
@@ -29,8 +29,9 @@ class TwigModule extends AbstractModule
2929
private $options;
3030

3131
/**
32-
* @param array $paths Twig template paths
33-
* @param array $options Twig_Environment options
32+
* @param array $paths Twig template paths
33+
* @param array $options Twig_Environment options
34+
* @param AbstractModule|null $module
3435
*
3536
* @see http://twig.sensiolabs.org/api/master/Twig_Environment.html
3637
*/
@@ -63,31 +64,31 @@ private function bindRender()
6364
private function bindTwigLoader()
6465
{
6566
$this
66-
->bind(Twig_LoaderInterface::class)
67+
->bind(LoaderInterface::class)
6768
->annotatedWith(TwigLoader::class)
6869
->toConstructor(
69-
Twig_Loader_Filesystem::class,
70+
FilesystemLoader::class,
7071
'paths=Madapaja\TwigModule\Annotation\TwigPaths'
7172
);
7273
}
7374

7475
private function bindTwigEnvironment()
7576
{
7677
$this
77-
->bind(Twig_Environment::class)
78+
->bind(Environment::class)
7879
->annotatedWith('original')
7980
->toConstructor(
80-
Twig_Environment::class,
81+
Environment::class,
8182
[
8283
'loader' => TwigLoader::class,
8384
'options' => TwigOptions::class
8485
]
8586
);
8687

8788
$this
88-
->bind(Twig_Environment::class)
89+
->bind(Environment::class)
8990
->toConstructor(
90-
Twig_Environment::class,
91+
Environment::class,
9192
[
9293
'loader' => TwigLoader::class,
9394
'options' => TwigOptions::class

src/TwigRenderer.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
use BEAR\Resource\RenderInterface;
1111
use BEAR\Resource\ResourceObject;
1212
use Ray\Aop\WeavedInterface;
13-
use Twig_Environment;
13+
use Twig\Environment;
14+
use Twig\Error\LoaderError;
15+
use Twig\Loader\FilesystemLoader;
16+
use Twig\TemplateWrapper;
1417

1518
class TwigRenderer implements RenderInterface
1619
{
@@ -22,7 +25,7 @@ class TwigRenderer implements RenderInterface
2225
const EXT = '.html.twig';
2326

2427
/**
25-
* @var Twig_Environment
28+
* @var \Twig\Environment
2629
*/
2730
public $twig;
2831

@@ -31,7 +34,7 @@ class TwigRenderer implements RenderInterface
3134
*/
3235
private $templateFinder;
3336

34-
public function __construct(Twig_Environment $twig, TemplateFinderInterface $templateFinder = null)
37+
public function __construct(Environment $twig, TemplateFinderInterface $templateFinder = null)
3538
{
3639
$this->twig = $twig;
3740
$this->templateFinder = $templateFinder ?: new TemplateFinder;
@@ -63,13 +66,13 @@ private function renderView(ResourceObject $ro)
6366
}
6467

6568
/**
66-
* @return null|\Twig_TemplateWrapper
69+
* @return null|\Twig\TemplateWrapper
6770
*/
6871
private function load(ResourceObject $ro)
6972
{
7073
try {
7174
return $this->loadTemplate($ro);
72-
} catch (\Twig_Error_Loader $e) {
75+
} catch (LoaderError $e) {
7376
if ($ro->code === 200) {
7477
throw new Exception\TemplateNotFound($e->getMessage(), 500, $e);
7578
}
@@ -81,10 +84,10 @@ private function isNoContent(ResourceObject $ro) : bool
8184
return $ro->code === Code::NO_CONTENT || $ro->view === '';
8285
}
8386

84-
private function loadTemplate(ResourceObject $ro) : \Twig_TemplateWrapper
87+
private function loadTemplate(ResourceObject $ro) : TemplateWrapper
8588
{
8689
$loader = $this->twig->getLoader();
87-
if ($loader instanceof \Twig_Loader_Filesystem) {
90+
if ($loader instanceof FilesystemLoader) {
8891
$classFile = $this->getReflection($ro)->getFileName();
8992
$templateFile = ($this->templateFinder)($classFile);
9093

tests/AppPathProviderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use PHPUnit_Framework_TestCase;
1010
use Ray\Di\Injector;
11+
use Twig\Loader\FilesystemLoader;
1112

1213
class AppPathProviderTest extends PHPUnit_Framework_TestCase
1314
{
@@ -27,9 +28,9 @@ public function testAppPathProvider()
2728

2829
/** @var TwigRenderer $renderer */
2930
$renderer = (new Injector(new AppPathProviderTestModule($appDir)))->getInstance(TwigRenderer::class);
30-
/** @var \Twig_Loader_Filesystem $loader */
31+
/** @var FilesystemLoader $loader */
3132
$loader = $renderer->twig->getLoader();
32-
$this->assertInstanceOf(\Twig_Loader_Filesystem::class, $loader);
33+
$this->assertInstanceOf(FilesystemLoader::class, $loader);
3334
$this->assertSame($paths, $loader->getPaths());
3435
}
3536
}

tests/Fake/src/ExtendedTwigEnvironmentProvider.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88

99
use Ray\Di\Di\Named;
1010
use Ray\Di\ProviderInterface;
11-
use Twig_Environment;
11+
use Twig\Environment;
1212

1313
class ExtendedTwigEnvironmentProvider implements ProviderInterface
1414
{
1515
private $twig;
1616

1717
/**
1818
* @Named("original")
19+
* @param Environment $twig
1920
*/
20-
public function __construct(Twig_Environment $twig)
21+
public function __construct(Environment $twig)
2122
{
22-
// $twig is an original Twig_Environment instance
23+
// $twig is an original Twig\Environment instance
2324
$this->twig = $twig;
2425
}
2526

tests/Fake/src/MyTwigExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
*/
77
namespace Madapaja\TwigModule;
88

9-
use Twig_Extension;
10-
use Twig_SimpleFilter;
9+
use Twig\Extension\AbstractExtension;
10+
use Twig\TwigFilter;
1111

12-
class MyTwigExtension extends Twig_Extension
12+
class MyTwigExtension extends AbstractExtension
1313
{
1414
public function getFilters()
1515
{
1616
return [
17-
new Twig_SimpleFilter('rot13', function ($string) {
17+
new TwigFilter('rot13', function ($string) {
1818
return str_rot13($string);
1919
}),
2020
];

tests/Fake/src/TwigArrayLoaderTestModule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
use Madapaja\TwigModule\Annotation\TwigLoader;
1010
use Ray\Di\AbstractModule;
11-
use Twig_Loader_Array;
12-
use Twig_LoaderInterface;
11+
use Twig\Loader\ArrayLoader;
12+
use Twig\Loader\LoaderInterface;
1313

1414
class TwigArrayLoaderTestModule extends AbstractModule
1515
{
@@ -30,10 +30,10 @@ protected function configure()
3030
EOD
3131
]);
3232
$this
33-
->bind(Twig_LoaderInterface::class)
33+
->bind(LoaderInterface::class)
3434
->annotatedWith(TwigLoader::class)
3535
->toConstructor(
36-
Twig_Loader_Array::class,
36+
ArrayLoader::class,
3737
'templates=twig_templates'
3838
);
3939
}

tests/Fake/src/TwigExtensionTestModule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use Ray\Di\AbstractModule;
1010
use Ray\Di\Scope;
11-
use Twig_Environment;
11+
use Twig\Environment;
1212

1313
class TwigExtensionTestModule extends AbstractModule
1414
{
@@ -27,7 +27,7 @@ protected function configure()
2727
{
2828
$this->install(new TwigModule($this->paths));
2929
$this
30-
->bind(Twig_Environment::class)
30+
->bind(Environment::class)
3131
->toProvider(ExtendedTwigEnvironmentProvider::class)
3232
->in(Scope::SINGLETON);
3333
}

0 commit comments

Comments
 (0)