Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ad9e40

Browse files
authored
Merge pull request#71 from hason/twig1
Increase Twig 1 version
2 parents2b8a9b5 +9b1fdcb commit6ad9e40

9 files changed

+71
-142
lines changed

‎.travis.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ matrix:
1010
include:
1111
-php:5.5
1212
dist:trusty
13-
env:TWIG_VERSION='^1.28'
13+
env:TWIG_VERSION='^1.38'
1414
-php:5.6
15-
env:TWIG_VERSION='^1.28'
15+
env:TWIG_VERSION='^1.38'
1616
-php:7.0
17-
env:TWIG_VERSION='^1.28'
17+
env:TWIG_VERSION='^1.38'
1818
-php:7.1
19-
env:TWIG_VERSION='^1.28'
19+
env:TWIG_VERSION='^1.38'
2020
-php:7.2
21-
env:TWIG_VERSION='^1.28'
21+
env:TWIG_VERSION='^1.38'
2222
-php:7.3
23-
env:TWIG_VERSION='^1.28'
23+
env:TWIG_VERSION='^1.38'
2424
-php:7.4
25-
env:TWIG_VERSION='^1.28'
25+
env:TWIG_VERSION='^1.38'
2626

2727
# Twig 2
2828
-php:7.0
29-
env:TWIG_VERSION='^2.0'
29+
env:TWIG_VERSION='^2.4'
3030
-php:7.1
31-
env:TWIG_VERSION='^2.0'
31+
env:TWIG_VERSION='^2.4'
3232
-php:7.2
33-
env:TWIG_VERSION='^2.0'
33+
env:TWIG_VERSION='^2.4'
3434
-php:7.3
35-
env:TWIG_VERSION='^2.0'
35+
env:TWIG_VERSION='^2.4'
3636
-php:7.4
37-
env:TWIG_VERSION='^2.0'
37+
env:TWIG_VERSION='^2.4'
3838

3939
# Twig 3
4040
-php:7.2
@@ -47,9 +47,9 @@ matrix:
4747
# oldest possible deps for twig
4848
-php:5.5# for twig 1.x
4949
dist:trusty
50-
env:COMPOSER_FLAGS='--prefer-lowest --prefer-stable' TWIG_VERSION=^1.28
50+
env:COMPOSER_FLAGS='--prefer-lowest --prefer-stable' TWIG_VERSION=^1.38
5151
-php:7.0# for twig 2.x
52-
env:COMPOSER_FLAGS='--prefer-lowest --prefer-stable' TWIG_VERSION=^2.0
52+
env:COMPOSER_FLAGS='--prefer-lowest --prefer-stable' TWIG_VERSION=^2.4
5353
-php:7.2# for twig 3.x
5454
env:COMPOSER_FLAGS='--prefer-lowest --prefer-stable' TWIG_VERSION=^3.0 PHPUNIT_VERSION=^7.0
5555
fast_finish:true

‎composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"php" :"^5.5|^7.0",
1919
"ext-dom":"*",
2020
"masterminds/html5" :"^2.1.2",
21-
"twig/twig" :"^1.28|^2.0|^3.0",
21+
"twig/twig" :"^1.38|^2.4|^3.0",
2222
"symfony/event-dispatcher" :"^3.0|^4.0|^5.0"
2323
},
2424
"require-dev" : {

‎src/TwitalLoader.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,10 @@
44
useTwig\Loader\ExistsLoaderInterface;
55
useTwig\Loader\LoaderInterface;
66
useTwig\Loader\SourceContextLoaderInterface;
7-
useTwig\Source;
87

98
if (interface_exists(\Twig_ExistsLoaderInterface::class)) {// Twig 1
109
abstractclass BaseTwitalLoaderextends TwitalLoaderTwigLt3implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface, \Twig_SourceContextLoaderInterface
1110
{
12-
publicfunction__construct(\Twig_LoaderInterface$loader =null,Twital$twital =null,$addDefaults =true)
13-
{
14-
parent::__construct($loader,$twital,$addDefaults);
15-
}
16-
17-
publicfunctiongetSourceContext($name)
18-
{
19-
$context =$this->doGetSourceContext($name);
20-
21-
returnnew \Twig_Source($context[0],$context[1],$context[2]);
22-
}
23-
2411
/**
2512
* {@inheritdoc}
2613
*/
@@ -32,17 +19,6 @@ public function getSource($name)
3219
}elseif (interface_exists(ExistsLoaderInterface::class)) {// Twig 2
3320
abstractclass BaseTwitalLoaderextends TwitalLoaderTwigLt3implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
3421
{
35-
publicfunction__construct(LoaderInterface$loader =null,Twital$twital =null,$addDefaults =true)
36-
{
37-
parent::__construct($loader,$twital,$addDefaults);
38-
}
39-
40-
publicfunctiongetSourceContext($name)
41-
{
42-
$context =$this->doGetSourceContext($name);
43-
44-
returnnewSource($context[0],$context[1],$context[2]);
45-
}
4622
}
4723
}else {// Twig 3
4824
abstractclass BaseTwitalLoaderextends TwitalLoaderTwigGte3

‎src/TwitalLoaderTrait.php

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
useTwig\Loader\ExistsLoaderInterface;
1111
useTwig\Loader\LoaderInterface;
1212
useTwig\Loader\SourceContextLoaderInterface;
13+
useTwig\Source;
1314

1415
/**
1516
* @author Martin Hasoň <martin.hason@gmail.com>
@@ -38,7 +39,28 @@ trait TwitalLoaderTrait
3839
*/
3940
protected$loader;
4041

41-
private$twigMajorVersion;
42+
/**
43+
* Creates a new Twital loader.
44+
*
45+
* @param LoaderInterface $loader
46+
* @param Twital $twital
47+
* @param bool $addDefaults If NULL, some standard rules will be used (`*.twital.*` and `*.twital`).
48+
*/
49+
publicfunction__construct(LoaderInterface$loader =null,Twital$twital =null,$addDefaults =true)
50+
{
51+
$this->loader =$loader;
52+
$this->twital =$twital;
53+
54+
if ($addDefaults ===true || (is_array($addDefaults) &&in_array('html',$addDefaults))) {
55+
$this->addSourceAdapter('/\.twital\.html$/i',newHTML5Adapter());
56+
}
57+
if ($addDefaults ===true || (is_array($addDefaults) &&in_array('xml',$addDefaults))) {
58+
$this->addSourceAdapter('/\.twital\.xml$/i',newXMLAdapter());
59+
}
60+
if ($addDefaults ===true || (is_array($addDefaults) &&in_array('xhtml',$addDefaults))) {
61+
$this->addSourceAdapter('/\.twital\.xhtml$/i',newXHTMLAdapter());
62+
}
63+
}
4264

4365
/**
4466
* Add a new pattern that can decide if a template is twital-compilable or not.
@@ -118,9 +140,9 @@ public function getTwital()
118140
return$this->twital;
119141
}
120142

121-
protectedfunctiondoGetSourceContext($name)
143+
privatefunctiondoGetSourceContext($name)
122144
{
123-
if ($this->getTwigMajorVersion() >=2 ||$this->loaderinstanceof SourceContextLoaderInterface) {
145+
if (Environment::MAJOR_VERSION >=2 ||$this->loaderinstanceof SourceContextLoaderInterface) {
124146
$originalContext =$this->loader->getSourceContext($name);
125147
$code =$originalContext->getCode();
126148
$path =$originalContext->getPath();
@@ -133,35 +155,12 @@ protected function doGetSourceContext($name)
133155
$code =$this->getTwital()->compile($adapter,$code);
134156
}
135157

136-
returnarray($code,$name,$path);
137-
}
138-
139-
/**
140-
* Creates a new Twital loader.
141-
*
142-
* @param LoaderInterface|\Twig_LoaderInterface $loader
143-
* @param Twital $twital
144-
* @param bool $addDefaults If NULL, some standard rules will be used (`*.twital.*` and `*.twital`).
145-
*/
146-
privatefunctiondoConstruct($loader =null,Twital$twital =null,$addDefaults =true)
147-
{
148-
$this->loader =$loader;
149-
$this->twital =$twital;
150-
151-
if ($addDefaults ===true || (is_array($addDefaults) &&in_array('html',$addDefaults))) {
152-
$this->addSourceAdapter('/\.twital\.html$/i',newHTML5Adapter());
153-
}
154-
if ($addDefaults ===true || (is_array($addDefaults) &&in_array('xml',$addDefaults))) {
155-
$this->addSourceAdapter('/\.twital\.xml$/i',newXMLAdapter());
156-
}
157-
if ($addDefaults ===true || (is_array($addDefaults) &&in_array('xhtml',$addDefaults))) {
158-
$this->addSourceAdapter('/\.twital\.xhtml$/i',newXHTMLAdapter());
159-
}
158+
returnnewSource($code,$name,$path);
160159
}
161160

162161
privatefunctiondoExists($name)
163162
{
164-
if ($this->getTwigMajorVersion() >=2 ||$this->loaderinstanceof ExistsLoaderInterface) {
163+
if (Environment::MAJOR_VERSION >=2 ||$this->loaderinstanceof ExistsLoaderInterface) {
165164
return$this->loader->exists($name);
166165
}else {
167166
try {
@@ -170,18 +169,7 @@ private function doExists($name)
170169
returntrue;
171170
}catch (LoaderError$e) {
172171
returnfalse;
173-
}catch (\Twig_Error_Loader$e) {
174-
returnfalse;
175172
}
176173
}
177174
}
178-
179-
privatefunctiongetTwigMajorVersion()
180-
{
181-
if (null ===$this->twigMajorVersion) {
182-
$this->twigMajorVersion =class_exists(Environment::class) ? Environment::MAJOR_VERSION : \Twig_Environment::MAJOR_VERSION;
183-
}
184-
185-
return$this->twigMajorVersion;
186-
}
187175
}

‎src/TwitalLoaderTwigGte3.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,9 @@ abstract class TwitalLoaderTwigGte3 implements LoaderInterface
1212
{
1313
use TwitalLoaderTrait;
1414

15-
publicfunction__construct(LoaderInterface$loader =null,Twital$twital =null,$addDefaults =true)
16-
{
17-
$this->doConstruct($loader,$twital,$addDefaults);
18-
}
19-
2015
publicfunctiongetSourceContext(string$name):Source
2116
{
22-
$context =$this->doGetSourceContext($name);
23-
24-
returnnewSource($context[0],$context[1],$context[2]);
17+
return$this->doGetSourceContext($name);
2518
}
2619

2720
publicfunctiongetCacheKey(string$name):string

‎src/TwitalLoaderTwigLt3.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ abstract class TwitalLoaderTwigLt3
99
{
1010
use TwitalLoaderTrait;
1111

12-
publicfunction__construct($loader =null,Twital$twital =null,$addDefaults =true)
13-
{
14-
$this->doConstruct($loader,$twital,$addDefaults);
15-
}
16-
1712
publicfunctiongetCacheKey($name)
1813
{
1914
return$this->loader->getCacheKey($name);
@@ -24,7 +19,10 @@ public function isFresh($name, $time)
2419
return$this->loader->isFresh($name,$time);
2520
}
2621

27-
abstractpublicfunctiongetSourceContext($name);
22+
publicfunctiongetSourceContext($name)
23+
{
24+
return$this->doGetSourceContext($name);
25+
}
2826

2927
publicfunctionexists($name)
3028
{

‎tests/Tests/DynamicAttrAttributeTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
class DynamicAttrAttributeTestextends TestCase
1010
{
1111
/**
12-
* @var Environment|\Twig_Environment
12+
* @var Environment
1313
*/
1414
protected$twig;
1515

1616
/**
17-
* @var ArrayLoader|\Twig_Loader_ArrayLoader
17+
* @var ArrayLoader
1818
*/
1919
protected$loader;
2020

@@ -25,18 +25,17 @@ protected function setUp()
2525
{
2626
parent::setUp();
2727

28-
$this->loader =class_exists(ArrayLoader::class) ?newArrayLoader() :new \Twig_Loader_Array();
28+
$this->loader =newArrayLoader();
2929
$twitalLoader =newTwitalLoader($this->loader,null,false);
3030
$twitalLoader->addSourceAdapter("/.*/",newXMLAdapter());
3131

32-
$class =class_exists(Environment::class) ? Environment::class : \Twig_Environment::class;
33-
$this->twig =new$class($twitalLoader);
32+
$this->twig =newEnvironment($twitalLoader);
3433
}
3534

3635
/**
3736
* @dataProvider getData
3837
*/
39-
publicfunctiontestVisitAttribute($source,$expected,$vars=null)
38+
publicfunctiontestVisitAttribute($source,$expected,$vars =null)
4039
{
4140
$this->loader->setTemplate('template',$source);
4241
$rendered =$this->twig->render('template',$vars ?:array());

‎tests/Tests/Html5DynamicAttrAttributeTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
class Html5DynamicAttrAttributeTestextends TestCase
1010
{
1111
/**
12-
* @var Environment|\Twig_Environment
12+
* @var Environment
1313
*/
1414
protected$twig;
1515

1616
/**
17-
* @var ArrayLoader|\Twig_Loader_ArrayLoader
17+
* @var ArrayLoader
1818
*/
1919
protected$loader;
2020

@@ -25,12 +25,11 @@ protected function setUp()
2525
{
2626
parent::setUp();
2727

28-
$this->loader =class_exists(ArrayLoader::class) ?newArrayLoader() :new \Twig_Loader_Array();
28+
$this->loader =newArrayLoader();
2929
$twitalLoader =newTwitalLoader($this->loader,null,false);
3030
$twitalLoader->addSourceAdapter("/.*/",newHTML5Adapter());
3131

32-
$class =class_exists(Environment::class) ? Environment::class : \Twig_Environment::class;
33-
$this->twig =new$class($twitalLoader,array(
32+
$this->twig =newEnvironment($twitalLoader,array(
3433
'strict_variables' =>true
3534
));
3635
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp