-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathTwig.php
45 lines (37 loc) · 1.05 KB
/
Twig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Gettext\Extractors;
use Gettext\Translations;
use Twig_Loader_Array;
use Twig_Environment;
use Twig_Source;
use Twig_Extensions_Extension_I18n;
/**
* Class to get gettext strings from twig files returning arrays.
*/
class Twig extends Extractor implements ExtractorInterface
{
public static $options = [
'extractComments' => 'notes:',
'twig' => null,
];
/**
* {@inheritdoc}
*/
public static function fromString($string, Translations $translations, array $options = [])
{
$options += static::$options;
$twig = $options['twig'] ?: self::createTwig();
PhpCode::fromString($twig->compileSource(new Twig_Source($string, '')), $translations, $options);
}
/**
* Returns a Twig instance.
*
* @return Twig_Environment
*/
private static function createTwig()
{
$twig = new Twig_Environment(new Twig_Loader_Array(['' => '']));
$twig->addExtension(new Twig_Extensions_Extension_I18n());
return static::$options['twig'] = $twig;
}
}