Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 959dd61435 | |||
| 6e63c1f2e8 | |||
| 8a91476e86 | |||
| 714bf6ad8e |
@@ -48,6 +48,9 @@ class AppKernel extends Kernel
|
||||
//oAuth
|
||||
new Http\HttplugBundle\HttplugBundle(),
|
||||
new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
|
||||
|
||||
//CookieBar
|
||||
new Fairlane\CookieConsentBundle\FairlaneCookieConsentBundle(),
|
||||
];
|
||||
|
||||
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
{% if fairlane_cookie_consent.active == true and app.request.cookies.get('fairlane-cookie-consent') != 'ok'%}
|
||||
{% if fairlane_cookie_consent.translate == true %}
|
||||
{% set text_info = fairlane_cookie_consent.twig.text_info | trans %}
|
||||
{% set text_additional_info_link = fairlane_cookie_consent.twig.text_additional_info_link | trans %}
|
||||
{% set text_accept_button = fairlane_cookie_consent.twig.text_accept_button | trans %}
|
||||
{% else %}
|
||||
{% set text_info = fairlane_cookie_consent.twig.text_info %}
|
||||
{% set text_additional_info_link = fairlane_cookie_consent.twig.text_additional_info_link %}
|
||||
{% set text_accept_button = fairlane_cookie_consent.twig.text_accept_button %}
|
||||
{% endif %}
|
||||
<div id="fairlane-cookie-consent" {% if fairlane_cookie_consent.useBootstrap == true %}class="navbar navbar-fixed-top"{% endif %}>
|
||||
<p>
|
||||
{{ text_info }}
|
||||
{% if fairlane_cookie_consent.twig.url_additional_info| length > 1 and text_additional_info_link | length > 1 %}
|
||||
<a href="{{ fairlane_cookie_consent.twig.url_additional_info }}" target="_blank">{{ text_additional_info_link }}</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
<button class="btn btn-default">{{ text_accept_button }}</button>
|
||||
</div>
|
||||
{% if fairlane_cookie_consent.useJquery %}
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function() {
|
||||
jQuery("#fairlane-cookie-consent button").click(function(){
|
||||
jQuery.ajax({
|
||||
async: true,
|
||||
type: 'POST',
|
||||
url: '{{ url('fairlane_cookie_consent_accept') }}',
|
||||
data: JSON.stringify({'cookie-consent': 'ok'}),
|
||||
success: function(data) {
|
||||
jQuery("#fairlane-cookie-consent").fadeOut("fast");
|
||||
},
|
||||
contentType: "application/json",
|
||||
dataType: 'json'
|
||||
});
|
||||
})
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
@@ -21,7 +21,7 @@
|
||||
<script type="text/javascript" defer="defer" src="https://extend.vimeocdn.com/ga/64189815.js"></script>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>{% block title %}Talents Tube : Le 1er job board 100% vidéo{% endblock %}</title>
|
||||
<title>{% block title %}Talents Tube : La 1ère plateforme pour l’emploi 100% vidéo{% endblock %}</title>
|
||||
|
||||
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}"/>
|
||||
{% block metarobot %}<meta name="robots" content="index,follow">{% endblock %}
|
||||
@@ -83,5 +83,6 @@
|
||||
<script src="{{ asset_url }}"></script>
|
||||
{% endjavascripts %}
|
||||
{% endblock %}
|
||||
{{ include('FairlaneCookieConsentBundle::cookie-info.html.twig') }}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
<li>
|
||||
<a class="white-text" href="{{ path('service_cgu') }}">Conditions générales d'utilisation</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="white-text" href="{{ path('page_Confidentialite') }}">Politique de confidentialité et protection des données</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col xl3 l3 m6 s12 left-align">
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<li><a href="{{ path('page_accompagnementTalent') }}" title="Accompagnement talent">Accompagnement</a></li>
|
||||
</ul>
|
||||
<ul id='dropdown_company' class='dropdown-content'>
|
||||
<li><a href="{{ path('company_list') }}" title="Listes entreprises">Listes entreprises</a></li>
|
||||
<li><a href="{{ path('company_list') }}" title="Les entreprises qui recrutent">Les entreprises qui recrutent</a></li>
|
||||
<li><a href="{{ path('page_OffreEmploi') }}" title="L'offre d'emploi en vidéo">L'offre d'emploi en vidéo</a></li>
|
||||
<li><a href="{{ path('page_reussirOffrevideo') }}" title="Comment faire une offre en vidéo">Comment faire une offre en vidéo</a></li>
|
||||
<li><a href="{{ path('page_MarqueEmployeur') }}" title="Vidéo Marque Employeur">Vidéo Marque Employeur</a></li>
|
||||
|
||||
@@ -59,10 +59,26 @@ doctrine:
|
||||
naming_strategy: doctrine.orm.naming_strategy.underscore
|
||||
mappings:
|
||||
AppBundle: ~
|
||||
|
||||
fairlane_cookie_consent:
|
||||
active: true
|
||||
use_bootstrap: true
|
||||
use_jquery: true
|
||||
translate: false
|
||||
cookie_lifetime: 90 # days
|
||||
twig:
|
||||
text_info: 'Notre site utilise des cookies et recueille des informations vous concernant à des fins fonctionnelles et / ou publicitaires. Nous vous invitons à accepter la collecte ou configurer vos choix. Vous pouvez modifier vos paramètres à tout moment.'
|
||||
text_accept_button: 'Accepter'
|
||||
text_additional_info_link: 'En savoir plus'
|
||||
url_additional_info: 'https://www.talentstube.com/confidentialite'
|
||||
|
||||
# Twig Configuration
|
||||
twig:
|
||||
debug: "%kernel.debug%"
|
||||
strict_variables: "%kernel.debug%"
|
||||
globals:
|
||||
fairlane_cookie_consent: '@fairlane_cookie_consent.twig'
|
||||
|
||||
|
||||
# Swiftmailer Configuration
|
||||
swiftmailer:
|
||||
|
||||
@@ -19,4 +19,7 @@ hwi_oauth_connect:
|
||||
|
||||
hwi_oauth_redirect:
|
||||
resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
|
||||
prefix: /login
|
||||
prefix: /login
|
||||
|
||||
fairlane_cookie_consent:
|
||||
resource: "@FairlaneCookieConsentBundle/Resources/config/routing.yml"
|
||||
@@ -50,7 +50,9 @@
|
||||
"php-http/httplug-bundle": "^1.8",
|
||||
"symfony/assetic-bundle": "^2.8",
|
||||
"friendsofsymfony/elastica-bundle": "4.1.*",
|
||||
"liip/imagine-bundle": "^1.9"
|
||||
"liip/imagine-bundle": "^1.9",
|
||||
"twig/extensions": "^1.5",
|
||||
"fairlane/cookie-consent-bundle": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"sensio/generator-bundle": "^3.0",
|
||||
|
||||
Generated
+98
-2
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "1ee242a3c7f90797f49f553ffc4a342d",
|
||||
"content-hash": "4f2ac88cf6d46bc55a35e28d9e2a66f5",
|
||||
"packages": [
|
||||
{
|
||||
"name": "alcaeus/mongo-php-adapter",
|
||||
@@ -1498,6 +1498,46 @@
|
||||
],
|
||||
"time": "2017-07-17T17:04:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "fairlane/cookie-consent-bundle",
|
||||
"version": "1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/fairlane/cookie-consent-bundle.git",
|
||||
"reference": "db2ca1c40a44e13c090406da6704b428d00dfd84"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/fairlane/cookie-consent-bundle/zipball/db2ca1c40a44e13c090406da6704b428d00dfd84",
|
||||
"reference": "db2ca1c40a44e13c090406da6704b428d00dfd84",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0",
|
||||
"symfony/framework-bundle": ">=2.7",
|
||||
"symfony/twig-bundle": ">=2.7",
|
||||
"twig/twig": ">=1.28"
|
||||
},
|
||||
"type": "symfony-bundle",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Fairlane\\CookieConsentBundle\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"WTFPL"
|
||||
],
|
||||
"description": "EU Cookie Consent Bundle for Symfony",
|
||||
"keywords": [
|
||||
"cookie",
|
||||
"cookie consent"
|
||||
],
|
||||
"time": "2017-11-12T00:24:21+00:00"
|
||||
},
|
||||
{
|
||||
"name": "friendsofsymfony/elastica-bundle",
|
||||
"version": "v4.1.1",
|
||||
@@ -4107,6 +4147,7 @@
|
||||
"compression",
|
||||
"minification"
|
||||
],
|
||||
"abandoned": "symfony/webpack-encore-pack",
|
||||
"time": "2017-07-14T07:26:46+00:00"
|
||||
},
|
||||
{
|
||||
@@ -4715,6 +4756,61 @@
|
||||
],
|
||||
"time": "2017-11-16T18:00:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "twig/extensions",
|
||||
"version": "v1.5.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig-extensions.git",
|
||||
"reference": "2c1a86526d0044065220d1b51ac08348bea5ca82"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig-extensions/zipball/2c1a86526d0044065220d1b51ac08348bea5ca82",
|
||||
"reference": "2c1a86526d0044065220d1b51ac08348bea5ca82",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"twig/twig": "^1.27|^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/phpunit-bridge": "^3.4",
|
||||
"symfony/translation": "^2.7|^3.4"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/translation": "Allow the time_diff output to be translated"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.5-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Twig_Extensions_": "lib/"
|
||||
},
|
||||
"psr-4": {
|
||||
"Twig\\Extensions\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
}
|
||||
],
|
||||
"description": "Common additional features for Twig that do not directly belong in core",
|
||||
"keywords": [
|
||||
"i18n",
|
||||
"text"
|
||||
],
|
||||
"time": "2018-05-22T13:26:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v2.4.4",
|
||||
|
||||
@@ -233,4 +233,17 @@ class PageController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/confidentialite", name="page_Confidentialite")
|
||||
*/
|
||||
public function ConfidentialiteAction()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$page = $em->getRepository('AppBundle:Page')->findOneByRef('CONFIDENTIALITE');
|
||||
|
||||
return $this->render('default/page.html.twig', [
|
||||
'page' => $page
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ class Page
|
||||
$pages[] = 'MARQUEEMPLOYEUR';
|
||||
$pages[] = 'VIDEOTERRITTORY';
|
||||
$pages[] = 'ACCTERRITTORY';
|
||||
$pages[] = 'CONFIDENTIALITE';
|
||||
// $pages[] = '';
|
||||
|
||||
return $pages;
|
||||
|
||||
+3
-3
@@ -377,11 +377,11 @@ class ClassLoader
|
||||
$subPath = $class;
|
||||
while (false !== $lastPos = strrpos($subPath, '\\')) {
|
||||
$subPath = substr($subPath, 0, $lastPos);
|
||||
$search = $subPath.'\\';
|
||||
$search = $subPath . '\\';
|
||||
if (isset($this->prefixDirsPsr4[$search])) {
|
||||
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
|
||||
foreach ($this->prefixDirsPsr4[$search] as $dir) {
|
||||
$length = $this->prefixLengthsPsr4[$first][$search];
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
|
||||
if (file_exists($file = $dir . $pathEnd)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ return array(
|
||||
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
|
||||
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
|
||||
'5255c38a0faeba867671b61dfda6d864' => $vendorDir . '/paragonie/random_compat/lib/random.php',
|
||||
'023d27dca8066ef29e6739335ea73bad' => $vendorDir . '/symfony/polyfill-php70/bootstrap.php',
|
||||
'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php',
|
||||
'6a47392539ca2329373e0d33e1dba053' => $vendorDir . '/symfony/polyfill-intl-icu/bootstrap.php',
|
||||
'32dcc8afd4335739640db7d200c1971d' => $vendorDir . '/symfony/polyfill-apcu/bootstrap.php',
|
||||
'ce89ac35a6c330c55f4710717db9ff78' => $vendorDir . '/kriswallsmith/assetic/src/functions.php',
|
||||
'32dcc8afd4335739640db7d200c1971d' => $vendorDir . '/symfony/polyfill-apcu/bootstrap.php',
|
||||
'6a47392539ca2329373e0d33e1dba053' => $vendorDir . '/symfony/polyfill-intl-icu/bootstrap.php',
|
||||
'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php',
|
||||
'023d27dca8066ef29e6739335ea73bad' => $vendorDir . '/symfony/polyfill-php70/bootstrap.php',
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Twig_Extensions_' => array($vendorDir . '/twig/extensions/lib'),
|
||||
'Twig_' => array($vendorDir . '/twig/twig/lib'),
|
||||
'SensioLabs\\Security' => array($vendorDir . '/sensiolabs/security-checker'),
|
||||
'RequestLab\\VimeoBundle' => array($vendorDir . '/requestlab/vimeo-bundle'),
|
||||
|
||||
@@ -9,6 +9,7 @@ return array(
|
||||
'Zend\\EventManager\\' => array($vendorDir . '/zendframework/zend-eventmanager/src'),
|
||||
'Zend\\Code\\' => array($vendorDir . '/zendframework/zend-code/src'),
|
||||
'Vimeo\\' => array($vendorDir . '/vimeo/vimeo-api/src/Vimeo'),
|
||||
'Twig\\Extensions\\' => array($vendorDir . '/twig/extensions/src'),
|
||||
'Twig\\' => array($vendorDir . '/twig/twig/src'),
|
||||
'Tests\\' => array($baseDir . '/tests'),
|
||||
'Symfony\\Polyfill\\Util\\' => array($vendorDir . '/symfony/polyfill-util'),
|
||||
@@ -40,10 +41,10 @@ return array(
|
||||
'Jaybizzle\\CrawlerDetect\\' => array($vendorDir . '/jaybizzle/crawler-detect/src'),
|
||||
'Incenteev\\ParameterHandler\\' => array($vendorDir . '/incenteev/composer-parameter-handler'),
|
||||
'Http\\Promise\\' => array($vendorDir . '/php-http/promise/src'),
|
||||
'Http\\Message\\' => array($vendorDir . '/php-http/message-factory/src', $vendorDir . '/php-http/message/src'),
|
||||
'Http\\Message\\' => array($vendorDir . '/php-http/message/src', $vendorDir . '/php-http/message-factory/src'),
|
||||
'Http\\HttplugBundle\\' => array($vendorDir . '/php-http/httplug-bundle'),
|
||||
'Http\\Discovery\\' => array($vendorDir . '/php-http/discovery/src'),
|
||||
'Http\\Client\\Common\\Plugin\\' => array($vendorDir . '/php-http/stopwatch-plugin/src', $vendorDir . '/php-http/logger-plugin/src', $vendorDir . '/php-http/cache-plugin/src'),
|
||||
'Http\\Client\\Common\\Plugin\\' => array($vendorDir . '/php-http/cache-plugin/src', $vendorDir . '/php-http/logger-plugin/src', $vendorDir . '/php-http/stopwatch-plugin/src'),
|
||||
'Http\\Client\\Common\\' => array($vendorDir . '/php-http/client-common/src'),
|
||||
'Http\\Client\\' => array($vendorDir . '/php-http/httplug/src'),
|
||||
'Http\\Adapter\\Guzzle6\\' => array($vendorDir . '/php-http/guzzle6-adapter/src'),
|
||||
@@ -51,6 +52,7 @@ return array(
|
||||
'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'),
|
||||
'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),
|
||||
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
|
||||
'Fairlane\\CookieConsentBundle\\' => array($vendorDir . '/fairlane/cookie-consent-bundle'),
|
||||
'FOS\\UserBundle\\' => array($vendorDir . '/friendsofsymfony/user-bundle'),
|
||||
'FOS\\ElasticaBundle\\' => array($vendorDir . '/friendsofsymfony/elastica-bundle'),
|
||||
'Elastica\\' => array($vendorDir . '/ruflin/elastica/lib/Elastica'),
|
||||
|
||||
+22
-8
@@ -18,11 +18,11 @@ class ComposerStaticInit1b32d02bd8fea2d524bf79b36ada5830
|
||||
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
|
||||
'2c102faa651ef8ea5874edb585946bce' => __DIR__ . '/..' . '/swiftmailer/swiftmailer/lib/swift_required.php',
|
||||
'5255c38a0faeba867671b61dfda6d864' => __DIR__ . '/..' . '/paragonie/random_compat/lib/random.php',
|
||||
'023d27dca8066ef29e6739335ea73bad' => __DIR__ . '/..' . '/symfony/polyfill-php70/bootstrap.php',
|
||||
'bd9634f2d41831496de0d3dfe4c94881' => __DIR__ . '/..' . '/symfony/polyfill-php56/bootstrap.php',
|
||||
'6a47392539ca2329373e0d33e1dba053' => __DIR__ . '/..' . '/symfony/polyfill-intl-icu/bootstrap.php',
|
||||
'32dcc8afd4335739640db7d200c1971d' => __DIR__ . '/..' . '/symfony/polyfill-apcu/bootstrap.php',
|
||||
'ce89ac35a6c330c55f4710717db9ff78' => __DIR__ . '/..' . '/kriswallsmith/assetic/src/functions.php',
|
||||
'32dcc8afd4335739640db7d200c1971d' => __DIR__ . '/..' . '/symfony/polyfill-apcu/bootstrap.php',
|
||||
'6a47392539ca2329373e0d33e1dba053' => __DIR__ . '/..' . '/symfony/polyfill-intl-icu/bootstrap.php',
|
||||
'bd9634f2d41831496de0d3dfe4c94881' => __DIR__ . '/..' . '/symfony/polyfill-php56/bootstrap.php',
|
||||
'023d27dca8066ef29e6739335ea73bad' => __DIR__ . '/..' . '/symfony/polyfill-php70/bootstrap.php',
|
||||
);
|
||||
|
||||
public static $prefixLengthsPsr4 = array (
|
||||
@@ -37,6 +37,7 @@ class ComposerStaticInit1b32d02bd8fea2d524bf79b36ada5830
|
||||
),
|
||||
'T' =>
|
||||
array (
|
||||
'Twig\\Extensions\\' => 16,
|
||||
'Twig\\' => 5,
|
||||
'Tests\\' => 6,
|
||||
),
|
||||
@@ -109,6 +110,7 @@ class ComposerStaticInit1b32d02bd8fea2d524bf79b36ada5830
|
||||
),
|
||||
'F' =>
|
||||
array (
|
||||
'Fairlane\\CookieConsentBundle\\' => 29,
|
||||
'FOS\\UserBundle\\' => 15,
|
||||
'FOS\\ElasticaBundle\\' => 19,
|
||||
),
|
||||
@@ -156,6 +158,10 @@ class ComposerStaticInit1b32d02bd8fea2d524bf79b36ada5830
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/vimeo/vimeo-api/src/Vimeo',
|
||||
),
|
||||
'Twig\\Extensions\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/twig/extensions/src',
|
||||
),
|
||||
'Twig\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/twig/twig/src',
|
||||
@@ -282,8 +288,8 @@ class ComposerStaticInit1b32d02bd8fea2d524bf79b36ada5830
|
||||
),
|
||||
'Http\\Message\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/php-http/message-factory/src',
|
||||
1 => __DIR__ . '/..' . '/php-http/message/src',
|
||||
0 => __DIR__ . '/..' . '/php-http/message/src',
|
||||
1 => __DIR__ . '/..' . '/php-http/message-factory/src',
|
||||
),
|
||||
'Http\\HttplugBundle\\' =>
|
||||
array (
|
||||
@@ -295,9 +301,9 @@ class ComposerStaticInit1b32d02bd8fea2d524bf79b36ada5830
|
||||
),
|
||||
'Http\\Client\\Common\\Plugin\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/php-http/stopwatch-plugin/src',
|
||||
0 => __DIR__ . '/..' . '/php-http/cache-plugin/src',
|
||||
1 => __DIR__ . '/..' . '/php-http/logger-plugin/src',
|
||||
2 => __DIR__ . '/..' . '/php-http/cache-plugin/src',
|
||||
2 => __DIR__ . '/..' . '/php-http/stopwatch-plugin/src',
|
||||
),
|
||||
'Http\\Client\\Common\\' =>
|
||||
array (
|
||||
@@ -327,6 +333,10 @@ class ComposerStaticInit1b32d02bd8fea2d524bf79b36ada5830
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/guzzlehttp/guzzle/src',
|
||||
),
|
||||
'Fairlane\\CookieConsentBundle\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/fairlane/cookie-consent-bundle',
|
||||
),
|
||||
'FOS\\UserBundle\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/friendsofsymfony/user-bundle',
|
||||
@@ -412,6 +422,10 @@ class ComposerStaticInit1b32d02bd8fea2d524bf79b36ada5830
|
||||
public static $prefixesPsr0 = array (
|
||||
'T' =>
|
||||
array (
|
||||
'Twig_Extensions_' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/twig/extensions/lib',
|
||||
),
|
||||
'Twig_' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/twig/twig/lib',
|
||||
|
||||
+3600
-3500
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
### 1.0.2
|
||||
* Fix hiding the cookie info div
|
||||
* Update instructions
|
||||
|
||||
### 1.0.1
|
||||
* Fix the composer dependencies
|
||||
|
||||
### 1.0.0
|
||||
* Initial release
|
||||
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Fairlane\CookieConsentBundle\Controller;
|
||||
|
||||
use Fairlane\CookieConsentBundle\Type\Constant;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class CookieController extends Controller
|
||||
{
|
||||
public function acceptAction()
|
||||
{
|
||||
$request = Request::createFromGlobals();
|
||||
$content = json_decode($request->getContent(), true);
|
||||
if (isset($content['cookie-consent']) && $content['cookie-consent'] == 'ok') {
|
||||
$expires = new \DateTime("now");
|
||||
$dateInterval = new \DateInterval(
|
||||
sprintf(
|
||||
'P%dD',
|
||||
$this->getFairlaneParameter(Constant::BUNDLE_CONFIG_COOKIE_LIFETIME)
|
||||
)
|
||||
);
|
||||
$expires->add($dateInterval);
|
||||
$cookie = new Cookie(Constant::BUNDLE_COOKIE_NAME,'ok', $expires);
|
||||
$jsonResponse = new JsonResponse(['success' => true]);
|
||||
$jsonResponse->headers->setCookie($cookie);
|
||||
|
||||
return $jsonResponse;
|
||||
} else {
|
||||
|
||||
return new JsonResponse(['success' => false], 400);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFairlaneParameter($key)
|
||||
{
|
||||
$params = $this->getParameter('fairlane_cookie_consent');
|
||||
if (!empty($params[$key])) {
|
||||
return $params[$key];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Fairlane\CookieConsentBundle\DependencyInjection;
|
||||
|
||||
use Fairlane\CookieConsentBundle\Type\Constant;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
/**
|
||||
* This is the class that validates and merges configuration from your app/config files.
|
||||
*
|
||||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root(Constant::BUNDLE_CONFIG_ROOT);
|
||||
|
||||
// Here you should define the parameters that are allowed to
|
||||
// configure your bundle. See the documentation linked above for
|
||||
// more information on that topic.
|
||||
$rootNode
|
||||
->children()
|
||||
->booleanNode(Constant::BUNDLE_CONFIG_BOOTSTRAP)->end()
|
||||
->booleanNode(Constant::BUNDLE_CONFIG_ACTIVE)->end()
|
||||
->booleanNode(Constant::BUNDLE_CONFIG_TRANSLATE)->end()
|
||||
->booleanNode(Constant::BUNDLE_CONFIG_JQUERY)->end()
|
||||
->integerNode(Constant::BUNDLE_CONFIG_COOKIE_LIFETIME)->end()
|
||||
->arrayNode(Constant::BUNDLE_CONFIG_TWIG)
|
||||
->children()
|
||||
->scalarNode(Constant::BUNDLE_CONFIG_TEXT_INFO)->end()
|
||||
->scalarNode(Constant::BUNDLE_CONFIG_TEXT_INFO_LINK)->end()
|
||||
->scalarNode(Constant::BUNDLE_CONFIG_TEXT_ACCEPT_BUTTON)->end()
|
||||
->scalarNode(Constant::BUNDLE_CONFIG_URL_ADDITIONAL_INFO)->end()
|
||||
->end()
|
||||
->end()
|
||||
->end();
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Fairlane\CookieConsentBundle\DependencyInjection;
|
||||
|
||||
use Fairlane\CookieConsentBundle\Type\Constant;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader;
|
||||
|
||||
/**
|
||||
* This is the class that loads and manages your bundle configuration.
|
||||
*
|
||||
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
|
||||
*/
|
||||
class FairlaneCookieConsentExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$configuration = new Configuration();
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
$container->setParameter('fairlane_cookie_consent', $config);
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Fairlane\CookieConsentBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class FairlaneCookieConsentBundle extends Bundle
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
Symfony 3 Cookie Consent bundle
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Step 1: Install the bundle
|
||||
--------------------------
|
||||
|
||||
The easiest way to install the bundle is by using composer.
|
||||
|
||||
```console
|
||||
$ composer require fairlane/cookie-consent-bundle"
|
||||
```
|
||||
|
||||
This command requires you to have Composer installed globally, as explained
|
||||
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
|
||||
of the Composer documentation.
|
||||
|
||||
Step 2: Enable the Bundle
|
||||
-------------------------
|
||||
|
||||
Then, enable the bundle by adding it to the list of registered bundles
|
||||
in the `app/AppKernel.php` file of your project:
|
||||
|
||||
```php
|
||||
<?php
|
||||
// app/AppKernel.php
|
||||
|
||||
// ...
|
||||
class AppKernel extends Kernel
|
||||
{
|
||||
public function registerBundles()
|
||||
{
|
||||
$bundles = array(
|
||||
// ...
|
||||
new Fairlane\CookieConsentBundle\FairlaneCookieConsentBundle(),
|
||||
);
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
Step 3: Configure bundle
|
||||
------------------------
|
||||
|
||||
This bundle has few simple configurations. To see the list configuration options run following command:
|
||||
|
||||
```console
|
||||
$ bin/console config:dump-reference fairlane_cookie_consent
|
||||
```
|
||||
You must expose the `fairlane_cookie_consent.twig` service globally.
|
||||
```yaml
|
||||
twig:
|
||||
// ...
|
||||
globals:
|
||||
// ...
|
||||
fairlane_cookie_consent: '@fairlane_cookie_consent.twig'
|
||||
```
|
||||
|
||||
Your config should look something like this.
|
||||
|
||||
```yaml
|
||||
# Fairlane Cookie Consent configuration
|
||||
fairlane_cookie_consent:
|
||||
active: true
|
||||
use_bootstrap: true
|
||||
use_jquery: true
|
||||
translate: false
|
||||
cookie_lifetime: 365 # days
|
||||
twig:
|
||||
text_info: 'This site uses cookies for...'
|
||||
text_accept_button: 'OK'
|
||||
text_additional_info_link: 'Read more about our cookie policy from here'
|
||||
url_additional_info: 'https://yourdomain/your-cookie-policy'
|
||||
|
||||
twig:
|
||||
globals:
|
||||
fairlane_cookie_consent: '@fairlane_cookie_consent.twig'
|
||||
```
|
||||
The routes must be imported as well. Add following route to your `routes.yml`
|
||||
|
||||
```yaml
|
||||
fairlane_cookie_consent:
|
||||
resource: "@FairlaneCookieConsentBundle/Resources/config/routing.yml"
|
||||
```
|
||||
|
||||
Finally, include the twig template into your layout file.
|
||||
|
||||
```twig
|
||||
{{ include('FairlaneCookieConsentBundle::cookie-info.html.twig') }}
|
||||
```
|
||||
|
||||
Step 4: Style the cookie notification
|
||||
-------------------------------------
|
||||
The id of the div `fairlane-cookie-consent`. Feel free to style it as you please. If you set the `use_bootsrap` to true
|
||||
the extension will add `navbar navbar-fixed-top` classes to the div and `btn btn-primary` classes to the button.
|
||||
|
||||
If you set `use_jquery` to `true` acceptance of cookies is sent via ajax call & the div fades out. Otherwise you need to
|
||||
handle calling the `Cookie:accept` (route id: `fairlane_cookie_consent_accept`) by yourself. This route only accepts
|
||||
POST requests.
|
||||
|
||||
ToDo
|
||||
====
|
||||
* Improve & enrich the instructions
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fairlane_cookie_consent_accept:
|
||||
path: /fairlane/cookie-consent/accept
|
||||
defaults: { _controller: FairlaneCookieConsentBundle:Cookie:accept}
|
||||
methods: [POST]
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
services:
|
||||
fairlane_cookie_consent.twig:
|
||||
class: Fairlane\CookieConsentBundle\Service\TwigService
|
||||
arguments: ["%fairlane_cookie_consent%"]
|
||||
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
{% if fairlane_cookie_consent.active == true and app.request.cookies.get('fairlane-cookie-consent') != 'ok'%}
|
||||
{% if fairlane_cookie_consent.translate == true %}
|
||||
{% set text_info = fairlane_cookie_consent.twig.text_info | trans %}
|
||||
{% set text_additional_info_link = fairlane_cookie_consent.twig.text_additional_info_link | trans %}
|
||||
{% set text_accept_button = fairlane_cookie_consent.twig.text_accept_button | trans %}
|
||||
{% else %}
|
||||
{% set text_info = fairlane_cookie_consent.twig.text_info %}
|
||||
{% set text_additional_info_link = fairlane_cookie_consent.twig.text_additional_info_link %}
|
||||
{% set text_accept_button = fairlane_cookie_consent.twig.text_accept_button %}
|
||||
{% endif %}
|
||||
<div id="fairlane-cookie-consent" {% if fairlane_cookie_consent.useBootstrap == true %}class="navbar navbar-fixed-top"{% endif %}>
|
||||
<p>
|
||||
{{ text_info }}
|
||||
{% if fairlane_cookie_consent.twig.url_additional_info| length > 1 and text_additional_info_link | length > 1 %}
|
||||
<a href="{{ fairlane_cookie_consent.twig.url_additional_info }}" target="_blank">{{ text_additional_info_link }}</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
<button {% if fairlane_cookie_consent.useBootstrap == true %}class="btn btn-primary"{% endif %}>{{ text_accept_button }}</button>
|
||||
</div>
|
||||
{% if fairlane_cookie_consent.useJquery %}
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function() {
|
||||
jQuery("#fairlane-cookie-consent button").click(function(){
|
||||
jQuery.ajax({
|
||||
async: true,
|
||||
type: 'POST',
|
||||
url: '{{ url('fairlane_cookie_consent_accept') }}',
|
||||
data: JSON.stringify({'cookie-consent': 'ok'}),
|
||||
success: function(data) {
|
||||
jQuery("#fairlane-cookie-consent").fadeOut("fast");
|
||||
},
|
||||
contentType: "application/json",
|
||||
dataType: 'json'
|
||||
});
|
||||
})
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace Fairlane\CookieConsentBundle\Service;
|
||||
|
||||
use Fairlane\CookieConsentBundle\Type\Constant;
|
||||
|
||||
/**
|
||||
* Class TwigService
|
||||
*
|
||||
* @package Auxilia\CoreBundle\Service
|
||||
*/
|
||||
class TwigService
|
||||
{
|
||||
/**
|
||||
* Contains the injected configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* TwigService constructor.
|
||||
*
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTwig()
|
||||
{
|
||||
return $this->config['twig'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getUseBootstrap()
|
||||
{
|
||||
return $this->config[Constant::BUNDLE_CONFIG_BOOTSTRAP];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getActive()
|
||||
{
|
||||
return $this->config[Constant::BUNDLE_CONFIG_ACTIVE];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getTranslate()
|
||||
{
|
||||
return $this->config[Constant::BUNDLE_CONFIG_TRANSLATE];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getUseJquery()
|
||||
{
|
||||
return $this->config[Constant::BUNDLE_CONFIG_JQUERY];
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Fairlane\CookieConsentBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class DefaultControllerTest extends WebTestCase
|
||||
{
|
||||
public function testIndex()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/');
|
||||
|
||||
$this->assertContains('Hello World', $client->getResponse()->getContent());
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Fairlane\CookieConsentBundle\Type;
|
||||
|
||||
/**
|
||||
* This class has constants used by the bundle
|
||||
*
|
||||
*/
|
||||
class Constant
|
||||
{
|
||||
const BUNDLE_CONFIG_ROOT = 'fairlane_cookie_consent';
|
||||
const BUNDLE_CONFIG_BOOTSTRAP = 'use_bootstrap';
|
||||
const BUNDLE_CONFIG_JQUERY = 'use_jquery';
|
||||
const BUNDLE_CONFIG_TRANSLATE = 'translate';
|
||||
const BUNDLE_CONFIG_COOKIE_LIFETIME = 'cookie_lifetime';
|
||||
const BUNDLE_CONFIG_URL_ADDITIONAL_INFO = 'url_additional_info';
|
||||
const BUNDLE_CONFIG_ACTIVE = 'active';
|
||||
const BUNDLE_CONFIG_TWIG = 'twig';
|
||||
const BUNDLE_CONFIG_TEXT_INFO = 'text_info';
|
||||
const BUNDLE_CONFIG_TEXT_ACCEPT_BUTTON = 'text_accept_button';
|
||||
const BUNDLE_CONFIG_TEXT_INFO_LINK = 'text_additional_info_link';
|
||||
|
||||
const BUNDLE_COOKIE_NAME = 'fairlane-cookie-consent';
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "fairlane/cookie-consent-bundle",
|
||||
"type": "symfony-bundle",
|
||||
"description": "EU Cookie Consent Bundle for Symfony",
|
||||
"keywords": ["cookie", "cookie consent"],
|
||||
"license": "WTFPL",
|
||||
"require": {
|
||||
"php": ">=7.0",
|
||||
"twig/twig": ">=1.28",
|
||||
"symfony/framework-bundle": ">=2.7",
|
||||
"symfony/twig-bundle": ">=2.7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Fairlane\\CookieConsentBundle\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
}
|
||||
}
|
||||
+2
@@ -33,6 +33,7 @@ final class Versions
|
||||
'doctrine/orm' => 'dev-master@374e7ace49d864dad8cddbc55346447c8a6a2083',
|
||||
'dunglas/doctrine-json-odm' => 'dev-master@067f38940d6424b272521192a38d69d6af87825a',
|
||||
'evenement/evenement' => 'v1.1.0@e24176d20f6dab44dd4768b32c897f63b6f2b7c3',
|
||||
'fairlane/cookie-consent-bundle' => '1.0.2@db2ca1c40a44e13c090406da6704b428d00dfd84',
|
||||
'friendsofsymfony/elastica-bundle' => 'v4.1.1@b056b39abfe74a56cc79823ab5ddb0121270cec0',
|
||||
'friendsofsymfony/user-bundle' => 'v2.0.2@2fc8a023d7ab482321cf7ec810ed49eab40eb50f',
|
||||
'guzzlehttp/guzzle' => '6.3.0@f4db5a78a5ea468d4831de7f0bf9d9415e348699',
|
||||
@@ -84,6 +85,7 @@ final class Versions
|
||||
'symfony/polyfill-util' => 'v1.6.0@6e719200c8e540e0c0effeb31f96bdb344b94176',
|
||||
'symfony/swiftmailer-bundle' => 'v2.6.7@c4808f5169efc05567be983909d00f00521c53ec',
|
||||
'symfony/symfony' => 'v3.2.14@fc9f9470e81e6fb59bd826d8040b961f7ed30f94',
|
||||
'twig/extensions' => 'v1.5.2@2c1a86526d0044065220d1b51ac08348bea5ca82',
|
||||
'twig/twig' => 'v2.4.4@eddb97148ad779f27e670e1e3f19fb323aedafeb',
|
||||
'vimeo/vimeo-api' => '1.3.0@46820e2d777362849137c1eb14f5cdb657c289ea',
|
||||
'zendframework/zend-code' => '3.3.0@6b1059db5b368db769e4392c6cb6cc139e56640d',
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
phpunit.xml
|
||||
vendor/
|
||||
composer.lock
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
language: php
|
||||
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- vendor
|
||||
- $HOME/.composer/cache/files
|
||||
|
||||
env:
|
||||
- DEPS=no
|
||||
|
||||
before_install:
|
||||
- phpenv config-rm xdebug.ini
|
||||
|
||||
before_script:
|
||||
- if [ "$DEPS" == "low" ]; then composer --prefer-lowest --prefer-stable update; fi;
|
||||
- if [ "$DEPS" == "no" ]; then composer install; fi;
|
||||
|
||||
script: |
|
||||
./vendor/bin/simple-phpunit
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.3
|
||||
dist: precise
|
||||
- php: 5.4
|
||||
- php: 5.5
|
||||
- php: 5.6
|
||||
env: DEPS=low
|
||||
- php: 7.0
|
||||
- php: 7.1
|
||||
- php: 7.2
|
||||
fast_finish: true
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2010-2017 Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,14 @@
|
||||
Twig Extensions Repository
|
||||
==========================
|
||||
|
||||
This repository hosts Twig Extensions that do not belong to the core but can
|
||||
be nonetheless interesting to share with other developers.
|
||||
|
||||
Fork this repository, add your extension, and request a pull.
|
||||
|
||||
More Information
|
||||
----------------
|
||||
|
||||
Read the `documentation`_ for more information.
|
||||
|
||||
.. _documentation: http://twig-extensions.readthedocs.io/
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "twig/extensions",
|
||||
"description": "Common additional features for Twig that do not directly belong in core",
|
||||
"keywords": ["i18n","text"],
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"twig/twig": "^1.27|^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/phpunit-bridge": "^3.4",
|
||||
"symfony/translation": "^2.7|^3.4"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/translation": "Allow the time_diff output to be translated"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Twig_Extensions_": "lib/" },
|
||||
"psr-4": { "Twig\\Extensions\\": "src/" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.5-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
The Array Extension
|
||||
===================
|
||||
|
||||
The Array extensions provides the following filters:
|
||||
|
||||
* ``shuffle``
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
First, :ref:`install the Extensions library<extensions-install>`. Next, add
|
||||
the extension to Twig::
|
||||
|
||||
$twig->addExtension(new Twig_Extensions_Extension_Array());
|
||||
@@ -0,0 +1,41 @@
|
||||
The Date Extension
|
||||
===================
|
||||
|
||||
The *Date* extension provides the ``time_diff`` filter.
|
||||
|
||||
You need to register this extension before using the ``time_diff`` filter::
|
||||
|
||||
$twig->addExtension(new Twig_Extensions_Extension_Date());
|
||||
|
||||
``time_diff``
|
||||
-------------
|
||||
|
||||
Use the ``time_diff`` filter to render the difference between a date and now.
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ post.published_at|time_diff }}
|
||||
|
||||
The example above will output a string like ``4 seconds ago`` or ``in 1 month``,
|
||||
depending on the filtered date.
|
||||
|
||||
.. note::
|
||||
|
||||
Internally, Twig uses the PHP ``DateTime::diff()`` method for calculating the
|
||||
difference between dates, this means that PHP 5.3+ is required.
|
||||
|
||||
Arguments
|
||||
~~~~~~~~~
|
||||
|
||||
* ``date``: The date for calculate the difference from now. Can be a string
|
||||
or a DateTime instance.
|
||||
|
||||
* ``now``: The date that should be used as now. Can be a string or
|
||||
a DateTime instance. Do not set this argument to use current date.
|
||||
|
||||
Translation
|
||||
~~~~~~~~~~~
|
||||
|
||||
To get a translatable output, give a ``Symfony\Component\Translation\TranslatorInterface``
|
||||
as constructor argument. The returned string is formatted as ``diff.ago.XXX``
|
||||
or ``diff.in.XXX`` where ``XXX`` can be any valid unit: second, minute, hour, day, month, year.
|
||||
@@ -0,0 +1,191 @@
|
||||
The i18n Extension
|
||||
==================
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
The ``i18n`` extension adds `gettext`_ support to Twig. It defines one tag,
|
||||
``trans``.
|
||||
|
||||
To use it, first, :ref:`install the Extensions library<extensions-install>`.
|
||||
|
||||
You need to register this extension before using the ``trans`` block::
|
||||
|
||||
$twig->addExtension(new Twig_Extensions_Extension_I18n());
|
||||
|
||||
Note that you must configure the ``gettext`` extension before rendering any
|
||||
internationalized template. Here is a simple configuration example from the
|
||||
PHP `documentation`_::
|
||||
|
||||
// Set language to French
|
||||
putenv('LC_ALL=fr_FR');
|
||||
setlocale(LC_ALL, 'fr_FR');
|
||||
|
||||
// Specify the location of the translation tables
|
||||
bindtextdomain('myAppPhp', 'includes/locale');
|
||||
bind_textdomain_codeset('myAppPhp', 'UTF-8');
|
||||
|
||||
// Choose domain
|
||||
textdomain('myAppPhp');
|
||||
|
||||
.. caution::
|
||||
|
||||
The ``i18n`` extension only works if the PHP `gettext`_ extension is
|
||||
enabled.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Use the ``trans`` block to mark parts in the template as translatable:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% trans "Hello World!" %}
|
||||
|
||||
{% trans string_var %}
|
||||
|
||||
{% trans %}
|
||||
Hello World!
|
||||
{% endtrans %}
|
||||
|
||||
In a translatable string, you can embed variables:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% trans %}
|
||||
Hello {{ name }}!
|
||||
{% endtrans %}
|
||||
|
||||
During the gettext lookup these placeholders are converted. ``{{ name }}`` becomes ``%name%`` so the gettext ``msgid`` for this string would be ``Hello %name%!``.
|
||||
|
||||
.. note::
|
||||
|
||||
``{% trans "Hello {{ name }}!" %}`` is not a valid statement.
|
||||
|
||||
If you need to apply filters to the variables, you first need to assign the
|
||||
result to a variable:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% set name = name|capitalize %}
|
||||
|
||||
{% trans %}
|
||||
Hello {{ name }}!
|
||||
{% endtrans %}
|
||||
|
||||
To pluralize a translatable string, use the ``plural`` block:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% trans %}
|
||||
Hey {{ name }}, I have one apple.
|
||||
{% plural apple_count %}
|
||||
Hey {{ name }}, I have {{ count }} apples.
|
||||
{% endtrans %}
|
||||
|
||||
The ``plural`` tag should provide the ``count`` used to select the right
|
||||
string. Within the translatable string, the special ``count`` variable always
|
||||
contain the count value (here the value of ``apple_count``).
|
||||
|
||||
To add notes for translators, use the ``notes`` block:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% trans %}
|
||||
Hey {{ name }}, I have one apple.
|
||||
{% plural apple_count %}
|
||||
Hey {{ name }}, I have {{ count }} apples.
|
||||
{% notes %}
|
||||
This is shown in the user menu. This string should be shorter than 30 chars
|
||||
{% endtrans %}
|
||||
|
||||
You can use ``notes`` with or without ``plural``. Once you get your templates compiled you should
|
||||
configure the ``gettext`` parser to get something like this: ``xgettext --add-comments=notes``
|
||||
|
||||
Within an expression or in a tag, you can use the ``trans`` filter to translate
|
||||
simple strings or variables:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ var|default(default_value|trans) }}
|
||||
|
||||
Complex Translations within an Expression or Tag
|
||||
------------------------------------------------
|
||||
|
||||
Translations can be done with both the ``trans`` tag and the ``trans`` filter.
|
||||
The filter is less powerful as it only works for simple variables or strings.
|
||||
For more complex scenario, like pluralization, you can use a two-step
|
||||
strategy:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{# assign the translation to a temporary variable #}
|
||||
{% set default_value %}
|
||||
{% trans %}
|
||||
Hey {{ name }}, I have one apple.
|
||||
{% plural apple_count %}
|
||||
Hey {{ name }}, I have {{ count }} apples.
|
||||
{% endtrans %}
|
||||
{% endset %}
|
||||
|
||||
{# use the temporary variable within an expression #}
|
||||
{{ var|default(default_value|trans) }}
|
||||
|
||||
Extracting Template Strings
|
||||
---------------------------
|
||||
|
||||
If you use the Twig I18n extension, you will probably need to extract the
|
||||
template strings at some point.
|
||||
|
||||
Using Poedit 2
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Poedit 2 has native support for extracting from Twig files and no extra
|
||||
setup is necessary (Pro version).
|
||||
|
||||
Using ``xgettext`` or Poedit 1
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Unfortunately, the ``xgettext`` utility does not understand Twig templates
|
||||
natively and neither do tools based on it such as free versions of Poedit.
|
||||
But there is a simple workaround: as Twig converts templates to
|
||||
PHP files, you can use ``xgettext`` on the template cache instead.
|
||||
|
||||
Create a script that forces the generation of the cache for all your
|
||||
templates. Here is a simple example to get you started::
|
||||
|
||||
$tplDir = dirname(__FILE__).'/templates';
|
||||
$tmpDir = '/tmp/cache/';
|
||||
$loader = new Twig_Loader_Filesystem($tplDir);
|
||||
|
||||
// force auto-reload to always have the latest version of the template
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => $tmpDir,
|
||||
'auto_reload' => true
|
||||
));
|
||||
$twig->addExtension(new Twig_Extensions_Extension_I18n());
|
||||
// configure Twig the way you want
|
||||
|
||||
// iterate over all your templates
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)
|
||||
{
|
||||
// force compilation
|
||||
if ($file->isFile()) {
|
||||
$twig->loadTemplate(str_replace($tplDir.'/', '', $file));
|
||||
}
|
||||
}
|
||||
|
||||
Use the standard ``xgettext`` utility as you would have done with plain PHP
|
||||
code:
|
||||
|
||||
.. code-block:: text
|
||||
|
||||
xgettext --default-domain=messages -p ./locale --from-code=UTF-8 -n --omit-header -L PHP /tmp/cache/*.php
|
||||
|
||||
Another workaround is to use `Twig Gettext Extractor`_ and extract the template
|
||||
strings right from `Poedit`_.
|
||||
|
||||
.. _`gettext`: http://www.php.net/gettext
|
||||
.. _`documentation`: http://fr.php.net/manual/en/function.gettext.php
|
||||
.. _`Twig Gettext Extractor`: https://github.com/umpirsky/Twig-Gettext-Extractor
|
||||
.. _`Poedit`: http://www.poedit.net/
|
||||
@@ -0,0 +1,39 @@
|
||||
Twig Extensions
|
||||
===============
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
text
|
||||
i18n
|
||||
intl
|
||||
array
|
||||
date
|
||||
|
||||
The Twig Extensions is a library that provides several useful extensions
|
||||
for Twig. You can find it's code at `GitHub.com/twigphp/Twig-extensions`_.
|
||||
|
||||
.. _extensions-install:
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
This library can be installed via Composer running the following from the
|
||||
command line:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
composer require twig/extensions
|
||||
|
||||
* :doc:`Text <text>`: Provides useful filters for text manipulation;
|
||||
|
||||
* :doc:`I18n <i18n>`: Adds internationalization support via the ``gettext``
|
||||
library;
|
||||
|
||||
* :doc:`Intl <intl>`: Adds a filter for localization of ``DateTime`` objects, numbers and currency;
|
||||
|
||||
* :doc:`Array <array>`: Provides useful filters for array manipulation;
|
||||
|
||||
* :doc:`Date <date>`: Adds a filter for rendering the difference between dates.
|
||||
|
||||
.. _`GitHub.com/twigphp/Twig-extensions`: https://github.com/twigphp/Twig-extensions
|
||||
@@ -0,0 +1,160 @@
|
||||
The Intl Extension
|
||||
==================
|
||||
|
||||
The *Intl* extensions provides the ``localizeddate``, ``localizednumber`` and ``localizedcurrency`` filters.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
First, :ref:`install the Extensions library<extensions-install>`. Next, add
|
||||
the extension to Twig::
|
||||
|
||||
$twig->addExtension(new Twig_Extensions_Extension_Intl());
|
||||
|
||||
``localizeddate``
|
||||
-----------------
|
||||
|
||||
Use the ``localizeddate`` filter to format dates into a localized string
|
||||
representating the date.
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ post.published_at|localizeddate('medium', 'none', locale) }}
|
||||
|
||||
The ``localizeddate`` filter accepts strings (it must be in a format supported
|
||||
by the `strtotime`_ function), `DateTime`_ instances, or `Unix timestamps`_.
|
||||
|
||||
.. note::
|
||||
|
||||
Internally, Twig uses the PHP `IntlDateFormatter::create()`_ function for
|
||||
the date.
|
||||
|
||||
Arguments
|
||||
~~~~~~~~~
|
||||
|
||||
* ``date_format``: The date format. Choose one of these formats:
|
||||
|
||||
* 'none': `IntlDateFormatter::NONE`_
|
||||
* 'short': `IntlDateFormatter::SHORT`_
|
||||
* 'medium': `IntlDateFormatter::MEDIUM`_
|
||||
* 'long': `IntlDateFormatter::LONG`_
|
||||
* 'full': `IntlDateFormatter::FULL`_
|
||||
|
||||
* ``time_format``: The time format. Same formats possible as above.
|
||||
|
||||
* ``locale``: The locale used for the format. If ``NULL`` is given, Twig will
|
||||
use ``Locale::getDefault()``
|
||||
|
||||
* ``timezone``: The date timezone
|
||||
|
||||
* ``format``: Optional pattern to use when formatting or parsing. Possible
|
||||
patterns are documented in the `ICU user guide`_.
|
||||
|
||||
* ``calendar``: Calendar to use for formatting. The default value is 'gregorian',
|
||||
which corresponds to IntlDateFormatter::GREGORIAN. Choose one of these formats:
|
||||
|
||||
* 'gregorian': `IntlDateFormatter::GREGORIAN`_
|
||||
* 'traditional': `IntlDateFormatter::TRADITIONAL`_
|
||||
|
||||
For the following calendars should use 'traditional':
|
||||
* Japanese
|
||||
* Buddhist
|
||||
* Chinese
|
||||
* Persian
|
||||
* Indian
|
||||
* Islamic
|
||||
* Hebrew
|
||||
* Coptic
|
||||
* Ethiopic
|
||||
|
||||
Also for non-Gregorian calendars need to be specified in locale.
|
||||
Examples might include locale="fa_IR@calendar=PERSIAN".
|
||||
|
||||
|
||||
``localizednumber``
|
||||
-------------------
|
||||
|
||||
Use the ``localizednumber`` filter to format numbers into a localized string
|
||||
representating the number.
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ product.quantity|localizednumber }}
|
||||
|
||||
.. note::
|
||||
|
||||
Internally, Twig uses the PHP `NumberFormatter::create()`_ function for
|
||||
the number.
|
||||
|
||||
Arguments
|
||||
~~~~~~~~~
|
||||
|
||||
* ``style``: Optional number format (default: 'decimal'). Choose one of these formats:
|
||||
|
||||
* 'decimal': `NumberFormatter::DECIMAL`_
|
||||
* 'currency': `NumberFormatter::CURRENCY`_
|
||||
* 'percent': `NumberFormatter::PERCENT`_
|
||||
* 'scientific': `NumberFormatter::SCIENTIFIC`_
|
||||
* 'spellout': `NumberFormatter::SPELLOUT`_
|
||||
* 'ordinal': `NumberFormatter::ORDINAL`_
|
||||
* 'duration': `NumberFormatter::DURATION`_
|
||||
|
||||
* ``type``: Optional formatting type to use (default: 'default'). Choose one of these types:
|
||||
|
||||
* 'default': `NumberFormatter::TYPE_DEFAULT`_
|
||||
* 'int32': `NumberFormatter::TYPE_INT32`_
|
||||
* 'int64': `NumberFormatter::TYPE_INT64`_
|
||||
* 'double': `NumberFormatter::TYPE_DOUBLE`_
|
||||
* 'currency': `NumberFormatter::TYPE_CURRENCY`_
|
||||
|
||||
* ``locale``: The locale used for the format. If ``NULL`` is given, Twig will
|
||||
use ``Locale::getDefault()``
|
||||
|
||||
``localizedcurrency``
|
||||
---------------------
|
||||
|
||||
Use the ``localizedcurrency`` filter to format a currency value into a localized string.
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ product.price|localizedcurrency('EUR') }}
|
||||
|
||||
.. note::
|
||||
|
||||
Internally, Twig uses the PHP `NumberFormatter::create()`_ function for
|
||||
the number.
|
||||
|
||||
Arguments
|
||||
~~~~~~~~~
|
||||
|
||||
* ``currency``: The 3-letter ISO 4217 currency code indicating the currency to use.
|
||||
|
||||
* ``locale``: The locale used for the format. If ``NULL`` is given, Twig will
|
||||
use ``Locale::getDefault()``
|
||||
|
||||
|
||||
.. _`strtotime`: http://php.net/strtotime
|
||||
.. _`DateTime`: http://php.net/DateTime
|
||||
.. _`Unix timestamps`: http://en.wikipedia.org/wiki/Unix_time
|
||||
.. _`IntlDateFormatter::create()`: http://php.net/manual/en/intldateformatter.create.php
|
||||
.. _`IntlDateFormatter::NONE`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.none
|
||||
.. _`IntlDateFormatter::SHORT`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.short
|
||||
.. _`IntlDateFormatter::MEDIUM`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.medium
|
||||
.. _`IntlDateFormatter::LONG`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.long
|
||||
.. _`IntlDateFormatter::FULL`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.full
|
||||
.. _`IntlDateFormatter::GREGORIAN`: http://php.net/IntlDateFormatter#intldateformatter.constants.gregorian
|
||||
.. _`IntlDateFormatter::TRADITIONAL`: http://php.net/IntlDateFormatter#intldateformatter.constants.traditional
|
||||
.. _`ICU user guide`: http://userguide.icu-project.org/formatparse/datetime
|
||||
.. _`NumberFormatter::create()`: http://php.net/manual/en/numberformatter.create.php
|
||||
.. _`NumberFormatter::DECIMAL`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.decimal
|
||||
.. _`NumberFormatter::CURRENCY`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.currency
|
||||
.. _`NumberFormatter::PERCENT`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.percent
|
||||
.. _`NumberFormatter::SCIENTIFIC`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.scientific
|
||||
.. _`NumberFormatter::SPELLOUT`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.spellout
|
||||
.. _`NumberFormatter::ORDINAL`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.ordinal
|
||||
.. _`NumberFormatter::DURATION`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.duration
|
||||
.. _`NumberFormatter::TYPE_DEFAULT`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.type-default
|
||||
.. _`NumberFormatter::TYPE_INT32`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.type-int32
|
||||
.. _`NumberFormatter::TYPE_INT64`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.type-int64
|
||||
.. _`NumberFormatter::TYPE_DOUBLE`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.type-double
|
||||
.. _`NumberFormatter::TYPE_CURRENCY`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.type-currency
|
||||
@@ -0,0 +1,76 @@
|
||||
The Text Extension
|
||||
==================
|
||||
|
||||
The Text extension provides the following filters:
|
||||
|
||||
* ``truncate``
|
||||
* ``wordwrap``
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
First, :ref:`install the Extensions library<extensions-install>`. Next, add
|
||||
the extension to Twig::
|
||||
|
||||
$twig->addExtension(new Twig_Extensions_Extension_Text());
|
||||
|
||||
Wrapping Words
|
||||
--------------
|
||||
|
||||
Use the ``wordwrap`` filter to split your text in lines with equal length.
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing"|wordwrap(10) }}
|
||||
|
||||
This example would print::
|
||||
|
||||
Lorem ipsu
|
||||
m dolor si
|
||||
t amet, co
|
||||
nsectetur
|
||||
adipiscing
|
||||
|
||||
The default separator is "\\n", but you can easily change that by providing one:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing"|wordwrap(10, "zz\n") }}
|
||||
|
||||
This would result in::
|
||||
|
||||
Lorem ipsuzz
|
||||
m dolor sizz
|
||||
t amet, cozz
|
||||
nsectetur zz
|
||||
adipiscing
|
||||
|
||||
Truncating Text
|
||||
---------------
|
||||
|
||||
Use the ``truncate`` filter to cut off a string after limit is reached
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ "Hello World!"|truncate(5) }}
|
||||
|
||||
The example would output ``Hello...``, as ``...`` is the default separator.
|
||||
|
||||
You can also tell truncate to preserve whole words by setting the second
|
||||
parameter to ``true``. If the last Word is on the the separator, truncate
|
||||
will print out the whole Word.
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ "Hello World!"|truncate(7, true) }}
|
||||
|
||||
Here ``Hello World!`` would be printed.
|
||||
|
||||
If you want to change the separator, just set the third parameter to
|
||||
your desired separator.
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ "Hello World!"|truncate(7, false, "??") }}
|
||||
|
||||
This example would print ``Hello W??``.
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
@trigger_error('The "Twig_Extensions_Autoloader" class is deprecated since version 1.5. Use Composer instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Autoloads Twig Extensions classes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* @deprecated since version 1.5, use Composer instead.
|
||||
*/
|
||||
class Twig_Extensions_Autoloader
|
||||
{
|
||||
/**
|
||||
* Registers Twig_Extensions_Autoloader as an SPL autoloader.
|
||||
*/
|
||||
public static function register()
|
||||
{
|
||||
spl_autoload_register(array(new self(), 'autoload'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles autoloading of classes.
|
||||
*
|
||||
* @param string $class a class name
|
||||
*
|
||||
* @return bool Returns true if the class has been loaded
|
||||
*/
|
||||
public static function autoload($class)
|
||||
{
|
||||
if (0 !== strpos($class, 'Twig_Extensions')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (file_exists($file = __DIR__.'/../../'.str_replace('_', '/', $class).'.php')) {
|
||||
require $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Ricard Clau <ricard.clau@gmail.com>
|
||||
*/
|
||||
class Twig_Extensions_Extension_Array extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
$filters = array(
|
||||
new Twig_SimpleFilter('shuffle', 'twig_shuffle_filter'),
|
||||
);
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'array';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffles an array.
|
||||
*
|
||||
* @param array|Traversable $array An array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function twig_shuffle_filter($array)
|
||||
{
|
||||
if ($array instanceof Traversable) {
|
||||
$array = iterator_to_array($array, false);
|
||||
}
|
||||
|
||||
shuffle($array);
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
class_alias('Twig_Extensions_Extension_Array', 'Twig\Extensions\ArrayExtension', false);
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2014 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* @author Robin van der Vleuten <robinvdvleuten@gmail.com>
|
||||
*/
|
||||
class Twig_Extensions_Extension_Date extends Twig_Extension
|
||||
{
|
||||
public static $units = array(
|
||||
'y' => 'year',
|
||||
'm' => 'month',
|
||||
'd' => 'day',
|
||||
'h' => 'hour',
|
||||
'i' => 'minute',
|
||||
's' => 'second',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator = null)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
new Twig_SimpleFilter('time_diff', array($this, 'diff'), array('needs_environment' => true)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for converting dates to a time ago string like Facebook and Twitter has.
|
||||
*
|
||||
* @param Twig_Environment $env a Twig_Environment instance
|
||||
* @param string|DateTime $date a string or DateTime object to convert
|
||||
* @param string|DateTime $now A string or DateTime object to compare with. If none given, the current time will be used.
|
||||
*
|
||||
* @return string the converted time
|
||||
*/
|
||||
public function diff(Twig_Environment $env, $date, $now = null)
|
||||
{
|
||||
// Convert both dates to DateTime instances.
|
||||
$date = twig_date_converter($env, $date);
|
||||
$now = twig_date_converter($env, $now);
|
||||
|
||||
// Get the difference between the two DateTime objects.
|
||||
$diff = $date->diff($now);
|
||||
|
||||
// Check for each interval if it appears in the $diff object.
|
||||
foreach (self::$units as $attribute => $unit) {
|
||||
$count = $diff->$attribute;
|
||||
|
||||
if (0 !== $count) {
|
||||
return $this->getPluralizedInterval($count, $diff->invert, $unit);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function getPluralizedInterval($count, $invert, $unit)
|
||||
{
|
||||
if ($this->translator) {
|
||||
$id = sprintf('diff.%s.%s', $invert ? 'in' : 'ago', $unit);
|
||||
|
||||
return $this->translator->transChoice($id, $count, array('%count%' => $count), 'date');
|
||||
}
|
||||
|
||||
if (1 !== $count) {
|
||||
$unit .= 's';
|
||||
}
|
||||
|
||||
return $invert ? "in $count $unit" : "$count $unit ago";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_Extensions_Extension_Date', 'Twig\Extensions\DateExtension', false);
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Extensions_Extension_I18n extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTokenParsers()
|
||||
{
|
||||
return array(new Twig_Extensions_TokenParser_Trans());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
new Twig_SimpleFilter('trans', 'gettext'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'i18n';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_Extensions_Extension_I18n', 'Twig\Extensions\I18nExtension', false);
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Extensions_Extension_Intl extends Twig_Extension
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if (!class_exists('IntlDateFormatter')) {
|
||||
throw new RuntimeException('The native PHP intl extension (http://php.net/manual/en/book.intl.php) is needed to use intl-based filters.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
new Twig_SimpleFilter('localizeddate', 'twig_localized_date_filter', array('needs_environment' => true)),
|
||||
new Twig_SimpleFilter('localizednumber', 'twig_localized_number_filter'),
|
||||
new Twig_SimpleFilter('localizedcurrency', 'twig_localized_currency_filter'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'intl';
|
||||
}
|
||||
}
|
||||
|
||||
function twig_localized_date_filter(Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null, $calendar = 'gregorian')
|
||||
{
|
||||
$date = twig_date_converter($env, $date, $timezone);
|
||||
|
||||
$formatValues = array(
|
||||
'none' => IntlDateFormatter::NONE,
|
||||
'short' => IntlDateFormatter::SHORT,
|
||||
'medium' => IntlDateFormatter::MEDIUM,
|
||||
'long' => IntlDateFormatter::LONG,
|
||||
'full' => IntlDateFormatter::FULL,
|
||||
);
|
||||
|
||||
if (PHP_VERSION_ID < 50500) {
|
||||
$formatter = IntlDateFormatter::create(
|
||||
$locale,
|
||||
$formatValues[$dateFormat],
|
||||
$formatValues[$timeFormat],
|
||||
$date->getTimezone()->getName(),
|
||||
'gregorian' === $calendar ? IntlDateFormatter::GREGORIAN : IntlDateFormatter::TRADITIONAL,
|
||||
$format
|
||||
);
|
||||
|
||||
return $formatter->format($date->getTimestamp());
|
||||
}
|
||||
|
||||
$formatter = IntlDateFormatter::create(
|
||||
$locale,
|
||||
$formatValues[$dateFormat],
|
||||
$formatValues[$timeFormat],
|
||||
IntlTimeZone::createTimeZone($date->getTimezone()->getName()),
|
||||
'gregorian' === $calendar ? IntlDateFormatter::GREGORIAN : IntlDateFormatter::TRADITIONAL,
|
||||
$format
|
||||
);
|
||||
|
||||
return $formatter->format($date->getTimestamp());
|
||||
}
|
||||
|
||||
function twig_localized_number_filter($number, $style = 'decimal', $type = 'default', $locale = null)
|
||||
{
|
||||
static $typeValues = array(
|
||||
'default' => NumberFormatter::TYPE_DEFAULT,
|
||||
'int32' => NumberFormatter::TYPE_INT32,
|
||||
'int64' => NumberFormatter::TYPE_INT64,
|
||||
'double' => NumberFormatter::TYPE_DOUBLE,
|
||||
'currency' => NumberFormatter::TYPE_CURRENCY,
|
||||
);
|
||||
|
||||
$formatter = twig_get_number_formatter($locale, $style);
|
||||
|
||||
if (!isset($typeValues[$type])) {
|
||||
throw new Twig_Error_Syntax(sprintf('The type "%s" does not exist. Known types are: "%s"', $type, implode('", "', array_keys($typeValues))));
|
||||
}
|
||||
|
||||
return $formatter->format($number, $typeValues[$type]);
|
||||
}
|
||||
|
||||
function twig_localized_currency_filter($number, $currency = null, $locale = null)
|
||||
{
|
||||
$formatter = twig_get_number_formatter($locale, 'currency');
|
||||
|
||||
return $formatter->formatCurrency($number, $currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a number formatter instance according to given locale and formatter.
|
||||
*
|
||||
* @param string $locale Locale in which the number would be formatted
|
||||
* @param int $style Style of the formatting
|
||||
*
|
||||
* @return NumberFormatter A NumberFormatter instance
|
||||
*/
|
||||
function twig_get_number_formatter($locale, $style)
|
||||
{
|
||||
static $formatter, $currentStyle;
|
||||
|
||||
$locale = null !== $locale ? $locale : Locale::getDefault();
|
||||
|
||||
if ($formatter && $formatter->getLocale() === $locale && $currentStyle === $style) {
|
||||
// Return same instance of NumberFormatter if parameters are the same
|
||||
// to those in previous call
|
||||
return $formatter;
|
||||
}
|
||||
|
||||
static $styleValues = array(
|
||||
'decimal' => NumberFormatter::DECIMAL,
|
||||
'currency' => NumberFormatter::CURRENCY,
|
||||
'percent' => NumberFormatter::PERCENT,
|
||||
'scientific' => NumberFormatter::SCIENTIFIC,
|
||||
'spellout' => NumberFormatter::SPELLOUT,
|
||||
'ordinal' => NumberFormatter::ORDINAL,
|
||||
'duration' => NumberFormatter::DURATION,
|
||||
);
|
||||
|
||||
if (!isset($styleValues[$style])) {
|
||||
throw new Twig_Error_Syntax(sprintf('The style "%s" does not exist. Known styles are: "%s"', $style, implode('", "', array_keys($styleValues))));
|
||||
}
|
||||
|
||||
$currentStyle = $style;
|
||||
|
||||
$formatter = NumberFormatter::create($locale, $styleValues[$style]);
|
||||
|
||||
return $formatter;
|
||||
}
|
||||
|
||||
class_alias('Twig_Extensions_Extension_Intl', 'Twig\Extensions\IntlExtension', false);
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Henrik Bjornskov <hb@peytz.dk>
|
||||
*/
|
||||
class Twig_Extensions_Extension_Text extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
new Twig_SimpleFilter('truncate', 'twig_truncate_filter', array('needs_environment' => true)),
|
||||
new Twig_SimpleFilter('wordwrap', 'twig_wordwrap_filter', array('needs_environment' => true)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Text';
|
||||
}
|
||||
}
|
||||
|
||||
if (function_exists('mb_get_info')) {
|
||||
function twig_truncate_filter(Twig_Environment $env, $value, $length = 30, $preserve = false, $separator = '...')
|
||||
{
|
||||
if (mb_strlen($value, $env->getCharset()) > $length) {
|
||||
if ($preserve) {
|
||||
// If breakpoint is on the last word, return the value without separator.
|
||||
if (false === ($breakpoint = mb_strpos($value, ' ', $length, $env->getCharset()))) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$length = $breakpoint;
|
||||
}
|
||||
|
||||
return rtrim(mb_substr($value, 0, $length, $env->getCharset())).$separator;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function twig_wordwrap_filter(Twig_Environment $env, $value, $length = 80, $separator = "\n", $preserve = false)
|
||||
{
|
||||
$sentences = array();
|
||||
|
||||
$previous = mb_regex_encoding();
|
||||
mb_regex_encoding($env->getCharset());
|
||||
|
||||
$pieces = mb_split($separator, $value);
|
||||
mb_regex_encoding($previous);
|
||||
|
||||
foreach ($pieces as $piece) {
|
||||
while (!$preserve && mb_strlen($piece, $env->getCharset()) > $length) {
|
||||
$sentences[] = mb_substr($piece, 0, $length, $env->getCharset());
|
||||
$piece = mb_substr($piece, $length, 2048, $env->getCharset());
|
||||
}
|
||||
|
||||
$sentences[] = $piece;
|
||||
}
|
||||
|
||||
return implode($separator, $sentences);
|
||||
}
|
||||
} else {
|
||||
function twig_truncate_filter(Twig_Environment $env, $value, $length = 30, $preserve = false, $separator = '...')
|
||||
{
|
||||
if (strlen($value) > $length) {
|
||||
if ($preserve) {
|
||||
if (false !== ($breakpoint = strpos($value, ' ', $length))) {
|
||||
$length = $breakpoint;
|
||||
}
|
||||
}
|
||||
|
||||
return rtrim(substr($value, 0, $length)).$separator;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function twig_wordwrap_filter(Twig_Environment $env, $value, $length = 80, $separator = "\n", $preserve = false)
|
||||
{
|
||||
return wordwrap($value, $length, $separator, !$preserve);
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_Extensions_Extension_Text', 'Twig\Extensions\TextExtension', false);
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
abstract class Twig_Extensions_Grammar implements Twig_Extensions_GrammarInterface
|
||||
{
|
||||
protected $name;
|
||||
protected $parser;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Twig_Parser $parser
|
||||
*/
|
||||
public function setParser(Twig_Parser $parser)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Arguments extends Twig_Extensions_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:arguments>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
return $this->parser->getExpressionParser()->parseArguments();
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Array extends Twig_Extensions_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:array>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
return $this->parser->getExpressionParser()->parseArrayExpression();
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Body extends Twig_Extensions_Grammar
|
||||
{
|
||||
protected $end;
|
||||
|
||||
public function __construct($name, $end = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->end = null === $end ? 'end'.$name : $end;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:body>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return $this->parser->subparse(array($this, 'decideBlockEnd'), true);
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test($this->end);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Boolean extends Twig_Extensions_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:boolean>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$this->parser->getStream()->expect(Twig_Token::NAME_TYPE, array('true', 'false'));
|
||||
|
||||
return new Twig_Node_Expression_Constant('true' === $token->getValue() ? true : false, $token->getLine());
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Constant extends Twig_Extensions_Grammar
|
||||
{
|
||||
protected $type;
|
||||
|
||||
public function __construct($name, $type = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = null === $type ? Twig_Token::NAME_TYPE : $type;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$this->parser->getStream()->expect($this->type, $this->name);
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Expression extends Twig_Extensions_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
return $this->parser->getExpressionParser()->parseExpression();
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Hash extends Twig_Extensions_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:hash>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
return $this->parser->getExpressionParser()->parseHashExpression();
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Number extends Twig_Extensions_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:number>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$this->parser->getStream()->expect(Twig_Token::NUMBER_TYPE);
|
||||
|
||||
return new Twig_Node_Expression_Constant($token->getValue(), $token->getLine());
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Optional extends Twig_Extensions_Grammar
|
||||
{
|
||||
protected $grammar;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->grammar = array();
|
||||
foreach (func_get_args() as $grammar) {
|
||||
$this->addGrammar($grammar);
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$repr = array();
|
||||
foreach ($this->grammar as $grammar) {
|
||||
$repr[] = (string) $grammar;
|
||||
}
|
||||
|
||||
return sprintf('[%s]', implode(' ', $repr));
|
||||
}
|
||||
|
||||
public function addGrammar(Twig_Extensions_GrammarInterface $grammar)
|
||||
{
|
||||
$this->grammar[] = $grammar;
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
// test if we have the optional element before consuming it
|
||||
if ($this->grammar[0] instanceof Twig_Extensions_Grammar_Constant) {
|
||||
if (!$this->parser->getStream()->test($this->grammar[0]->getType(), $this->grammar[0]->getName())) {
|
||||
return array();
|
||||
}
|
||||
} elseif ($this->grammar[0] instanceof Twig_Extensions_Grammar_Name) {
|
||||
if (!$this->parser->getStream()->test(Twig_Token::NAME_TYPE)) {
|
||||
return array();
|
||||
}
|
||||
} elseif ($this->parser->getStream()->test(Twig_Token::BLOCK_END_TYPE)) {
|
||||
// if this is not a Constant or a Name, it must be the last element of the tag
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
$elements = array();
|
||||
foreach ($this->grammar as $grammar) {
|
||||
$grammar->setParser($this->parser);
|
||||
|
||||
$element = $grammar->parse($token);
|
||||
if (is_array($element)) {
|
||||
$elements = array_merge($elements, $element);
|
||||
} else {
|
||||
$elements[$grammar->getName()] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
return $elements;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Switch extends Twig_Extensions_Grammar
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('<%s:switch>', $this->name);
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$this->parser->getStream()->expect(Twig_Token::NAME_TYPE, $this->name);
|
||||
|
||||
return new Twig_Node_Expression_Constant(true, $token->getLine());
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
class Twig_Extensions_Grammar_Tag extends Twig_Extensions_Grammar
|
||||
{
|
||||
protected $grammar;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->grammar = array();
|
||||
foreach (func_get_args() as $grammar) {
|
||||
$this->addGrammar($grammar);
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$repr = array();
|
||||
foreach ($this->grammar as $grammar) {
|
||||
$repr[] = (string) $grammar;
|
||||
}
|
||||
|
||||
return implode(' ', $repr);
|
||||
}
|
||||
|
||||
public function addGrammar(Twig_Extensions_GrammarInterface $grammar)
|
||||
{
|
||||
$this->grammar[] = $grammar;
|
||||
}
|
||||
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$elements = array();
|
||||
foreach ($this->grammar as $grammar) {
|
||||
$grammar->setParser($this->parser);
|
||||
|
||||
$element = $grammar->parse($token);
|
||||
if (is_array($element)) {
|
||||
$elements = array_merge($elements, $element);
|
||||
} else {
|
||||
$elements[$grammar->getName()] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return $elements;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
interface Twig_Extensions_GrammarInterface
|
||||
{
|
||||
public function setParser(Twig_Parser $parser);
|
||||
|
||||
public function parse(Twig_Token $token);
|
||||
|
||||
public function getName();
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a trans node.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class Twig_Extensions_Node_Trans extends Twig_Node
|
||||
{
|
||||
public function __construct(Twig_Node $body, Twig_Node $plural = null, Twig_Node_Expression $count = null, Twig_Node $notes = null, $lineno, $tag = null)
|
||||
{
|
||||
$nodes = array('body' => $body);
|
||||
if (null !== $count) {
|
||||
$nodes['count'] = $count;
|
||||
}
|
||||
if (null !== $plural) {
|
||||
$nodes['plural'] = $plural;
|
||||
}
|
||||
if (null !== $notes) {
|
||||
$nodes['notes'] = $notes;
|
||||
}
|
||||
|
||||
parent::__construct($nodes, array(), $lineno, $tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compile(Twig_Compiler $compiler)
|
||||
{
|
||||
$compiler->addDebugInfo($this);
|
||||
|
||||
list($msg, $vars) = $this->compileString($this->getNode('body'));
|
||||
|
||||
if ($this->hasNode('plural')) {
|
||||
list($msg1, $vars1) = $this->compileString($this->getNode('plural'));
|
||||
|
||||
$vars = array_merge($vars, $vars1);
|
||||
}
|
||||
|
||||
$function = $this->getTransFunction($this->hasNode('plural'));
|
||||
|
||||
if ($this->hasNode('notes')) {
|
||||
$message = trim($this->getNode('notes')->getAttribute('data'));
|
||||
|
||||
// line breaks are not allowed cause we want a single line comment
|
||||
$message = str_replace(array("\n", "\r"), ' ', $message);
|
||||
$compiler->write("// notes: {$message}\n");
|
||||
}
|
||||
|
||||
if ($vars) {
|
||||
$compiler
|
||||
->write('echo strtr('.$function.'(')
|
||||
->subcompile($msg)
|
||||
;
|
||||
|
||||
if ($this->hasNode('plural')) {
|
||||
$compiler
|
||||
->raw(', ')
|
||||
->subcompile($msg1)
|
||||
->raw(', abs(')
|
||||
->subcompile($this->hasNode('count') ? $this->getNode('count') : null)
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
|
||||
$compiler->raw('), array(');
|
||||
|
||||
foreach ($vars as $var) {
|
||||
if ('count' === $var->getAttribute('name')) {
|
||||
$compiler
|
||||
->string('%count%')
|
||||
->raw(' => abs(')
|
||||
->subcompile($this->hasNode('count') ? $this->getNode('count') : null)
|
||||
->raw('), ')
|
||||
;
|
||||
} else {
|
||||
$compiler
|
||||
->string('%'.$var->getAttribute('name').'%')
|
||||
->raw(' => ')
|
||||
->subcompile($var)
|
||||
->raw(', ')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
$compiler->raw("));\n");
|
||||
} else {
|
||||
$compiler
|
||||
->write('echo '.$function.'(')
|
||||
->subcompile($msg)
|
||||
;
|
||||
|
||||
if ($this->hasNode('plural')) {
|
||||
$compiler
|
||||
->raw(', ')
|
||||
->subcompile($msg1)
|
||||
->raw(', abs(')
|
||||
->subcompile($this->hasNode('count') ? $this->getNode('count') : null)
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
|
||||
$compiler->raw(");\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Twig_Node $body A Twig_Node instance
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function compileString(Twig_Node $body)
|
||||
{
|
||||
if ($body instanceof Twig_Node_Expression_Name || $body instanceof Twig_Node_Expression_Constant || $body instanceof Twig_Node_Expression_TempName) {
|
||||
return array($body, array());
|
||||
}
|
||||
|
||||
$vars = array();
|
||||
if (count($body)) {
|
||||
$msg = '';
|
||||
|
||||
foreach ($body as $node) {
|
||||
if (get_class($node) === 'Twig_Node' && $node->getNode(0) instanceof Twig_Node_SetTemp) {
|
||||
$node = $node->getNode(1);
|
||||
}
|
||||
|
||||
if ($node instanceof Twig_Node_Print) {
|
||||
$n = $node->getNode('expr');
|
||||
while ($n instanceof Twig_Node_Expression_Filter) {
|
||||
$n = $n->getNode('node');
|
||||
}
|
||||
$msg .= sprintf('%%%s%%', $n->getAttribute('name'));
|
||||
$vars[] = new Twig_Node_Expression_Name($n->getAttribute('name'), $n->getTemplateLine());
|
||||
} else {
|
||||
$msg .= $node->getAttribute('data');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$msg = $body->getAttribute('data');
|
||||
}
|
||||
|
||||
return array(new Twig_Node(array(new Twig_Node_Expression_Constant(trim($msg), $body->getTemplateLine()))), $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $plural Return plural or singular function to use
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTransFunction($plural)
|
||||
{
|
||||
return $plural ? 'ngettext' : 'gettext';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_Extensions_Node_Trans', 'Twig\Extensions\Node\TransNode', false);
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
@trigger_error('The grammar feature is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.5
|
||||
*/
|
||||
abstract class Twig_Extensions_SimpleTokenParser extends Twig_TokenParser
|
||||
{
|
||||
/**
|
||||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
*
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$grammar = $this->getGrammar();
|
||||
if (!is_object($grammar)) {
|
||||
$grammar = self::parseGrammar($grammar);
|
||||
}
|
||||
|
||||
$grammar->setParser($this->parser);
|
||||
$values = $grammar->parse($token);
|
||||
|
||||
return $this->getNode($values, $token->getLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the grammar as an object or as a string.
|
||||
*
|
||||
* @return string|Twig_Extensions_Grammar A Twig_Extensions_Grammar instance or a string
|
||||
*/
|
||||
abstract protected function getGrammar();
|
||||
|
||||
/**
|
||||
* Gets the nodes based on the parsed values.
|
||||
*
|
||||
* @param array $values An array of values
|
||||
* @param int $line The parser line
|
||||
*/
|
||||
abstract protected function getNode(array $values, $line);
|
||||
|
||||
protected function getAttribute($node, $attribute, $arguments = array(), $type = Twig_Node_Expression_GetAttr::TYPE_ANY, $line = -1)
|
||||
{
|
||||
return new Twig_Node_Expression_GetAttr(
|
||||
$node instanceof Twig_Node ? $node : new Twig_Node_Expression_Name($node, $line),
|
||||
$attribute instanceof Twig_Node ? $attribute : new Twig_Node_Expression_Constant($attribute, $line),
|
||||
$arguments instanceof Twig_Node ? $arguments : new Twig_Node($arguments),
|
||||
$type,
|
||||
$line
|
||||
);
|
||||
}
|
||||
|
||||
protected function call($node, $attribute, $arguments = array(), $line = -1)
|
||||
{
|
||||
return $this->getAttribute($node, $attribute, $arguments, Twig_Node_Expression_GetAttr::TYPE_METHOD, $line);
|
||||
}
|
||||
|
||||
protected function markAsSafe(Twig_Node $node, $line = -1)
|
||||
{
|
||||
return new Twig_Node_Expression_Filter(
|
||||
$node,
|
||||
new Twig_Node_Expression_Constant('raw', $line),
|
||||
new Twig_Node(),
|
||||
$line
|
||||
);
|
||||
}
|
||||
|
||||
protected function output(Twig_Node $node, $line = -1)
|
||||
{
|
||||
return new Twig_Node_Print($node, $line);
|
||||
}
|
||||
|
||||
protected function getNodeValues(array $values)
|
||||
{
|
||||
$nodes = array();
|
||||
foreach ($values as $value) {
|
||||
if ($value instanceof Twig_Node) {
|
||||
$nodes[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
public static function parseGrammar($str, $main = true)
|
||||
{
|
||||
static $cursor;
|
||||
|
||||
if (true === $main) {
|
||||
$cursor = 0;
|
||||
$grammar = new Twig_Extensions_Grammar_Tag();
|
||||
} else {
|
||||
$grammar = new Twig_Extensions_Grammar_Optional();
|
||||
}
|
||||
|
||||
while ($cursor < strlen($str)) {
|
||||
if (preg_match('/\s+/A', $str, $match, null, $cursor)) {
|
||||
$cursor += strlen($match[0]);
|
||||
} elseif (preg_match('/<(\w+)(?:\:(\w+))?>/A', $str, $match, null, $cursor)) {
|
||||
$class = sprintf('Twig_Extensions_Grammar_%s', ucfirst(isset($match[2]) ? $match[2] : 'Expression'));
|
||||
if (!class_exists($class)) {
|
||||
throw new Twig_Error_Runtime(sprintf('Unable to understand "%s" in grammar (%s class does not exist)', $match[0], $class));
|
||||
}
|
||||
$grammar->addGrammar(new $class($match[1]));
|
||||
$cursor += strlen($match[0]);
|
||||
} elseif (preg_match('/\w+/A', $str, $match, null, $cursor)) {
|
||||
$grammar->addGrammar(new Twig_Extensions_Grammar_Constant($match[0]));
|
||||
$cursor += strlen($match[0]);
|
||||
} elseif (preg_match('/,/A', $str, $match, null, $cursor)) {
|
||||
$grammar->addGrammar(new Twig_Extensions_Grammar_Constant($match[0], Twig_Token::PUNCTUATION_TYPE));
|
||||
$cursor += strlen($match[0]);
|
||||
} elseif (preg_match('/\[/A', $str, $match, null, $cursor)) {
|
||||
$cursor += strlen($match[0]);
|
||||
$grammar->addGrammar(self::parseGrammar($str, false));
|
||||
} elseif (true !== $main && preg_match('/\]/A', $str, $match, null, $cursor)) {
|
||||
$cursor += strlen($match[0]);
|
||||
|
||||
return $grammar;
|
||||
} else {
|
||||
throw new Twig_Error_Runtime(sprintf('Unable to parse grammar "%s" near "...%s..."', $str, substr($str, $cursor, 10)));
|
||||
}
|
||||
}
|
||||
|
||||
return $grammar;
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Extensions_TokenParser_Trans extends Twig_TokenParser
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$count = null;
|
||||
$plural = null;
|
||||
$notes = null;
|
||||
|
||||
if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) {
|
||||
$body = $this->parser->getExpressionParser()->parseExpression();
|
||||
} else {
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideForFork'));
|
||||
$next = $stream->next()->getValue();
|
||||
|
||||
if ('plural' === $next) {
|
||||
$count = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$plural = $this->parser->subparse(array($this, 'decideForFork'));
|
||||
|
||||
if ('notes' === $stream->next()->getValue()) {
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$notes = $this->parser->subparse(array($this, 'decideForEnd'), true);
|
||||
}
|
||||
} elseif ('notes' === $next) {
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$notes = $this->parser->subparse(array($this, 'decideForEnd'), true);
|
||||
}
|
||||
}
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$this->checkTransString($body, $lineno);
|
||||
|
||||
return new Twig_Extensions_Node_Trans($body, $plural, $count, $notes, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideForFork(Twig_Token $token)
|
||||
{
|
||||
return $token->test(array('plural', 'notes', 'endtrans'));
|
||||
}
|
||||
|
||||
public function decideForEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endtrans');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return 'trans';
|
||||
}
|
||||
|
||||
protected function checkTransString(Twig_Node $body, $lineno)
|
||||
{
|
||||
foreach ($body as $i => $node) {
|
||||
if (
|
||||
$node instanceof Twig_Node_Text
|
||||
||
|
||||
($node instanceof Twig_Node_Print && $node->getNode('expr') instanceof Twig_Node_Expression_Name)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new Twig_Error_Syntax(sprintf('The text to be translated with "trans" can only contain references to simple variables'), $lineno);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_Extensions_TokenParser_Trans', 'Twig\Extensions\TokenParser\TransTokenParser', false);
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Twig Extensions Test Suite">
|
||||
<directory>./test/Twig/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./lib/Twig/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Extensions;
|
||||
|
||||
class_exists('Twig_Extensions_Extension_Array');
|
||||
|
||||
if (\false) {
|
||||
class ArrayExtension extends \Twig_Extensions_Extension_Array
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Extensions;
|
||||
|
||||
class_exists('Twig_Extensions_Extension_Date');
|
||||
|
||||
if (\false) {
|
||||
class DateExtension extends \Twig_Extensions_Extension_Date
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Extensions;
|
||||
|
||||
class_exists('Twig_Extensions_Extension_I18n');
|
||||
|
||||
if (\false) {
|
||||
class I18nExtension extends \Twig_Extensions_Extension_I18n
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Extensions;
|
||||
|
||||
class_exists('Twig_Extensions_Extension_Intl');
|
||||
|
||||
if (\false) {
|
||||
class IntlExtension extends \Twig_Extensions_Extension_Intl
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Extensions\Node;
|
||||
|
||||
class_exists('Twig_Extensions_Node_Trans');
|
||||
|
||||
if (\false) {
|
||||
class TransNode extends \Twig_Extensions_Node_Trans
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Extensions;
|
||||
|
||||
class_exists('Twig_Extensions_Extension_Text');
|
||||
|
||||
if (\false) {
|
||||
class TextExtension extends \Twig_Extensions_Extension_Text
|
||||
{
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Extensions\TokenParser;
|
||||
|
||||
class_exists('Twig_Extensions_TokenParser_Trans');
|
||||
|
||||
if (\false) {
|
||||
class TransTokenParser extends \Twig_Extensions_TokenParser_Trans
|
||||
{
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
require_once __DIR__.'/../../../../lib/Twig/Extensions/Extension/Array.php';
|
||||
|
||||
class Twig_Tests_Extension_ArrayTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getShuffleFilterTestData
|
||||
*/
|
||||
public function testShuffleFilter($data, $expectedElements)
|
||||
{
|
||||
foreach ($expectedElements as $element) {
|
||||
$this->assertTrue(in_array($element, twig_shuffle_filter($data), true)); // assertContains() would not consider the type
|
||||
}
|
||||
}
|
||||
|
||||
public function testShuffleFilterOnEmptyArray()
|
||||
{
|
||||
$this->assertEquals(array(), twig_shuffle_filter(array()));
|
||||
}
|
||||
|
||||
public function getShuffleFilterTestData()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(1, 2, 3),
|
||||
array(1, 2, 3),
|
||||
),
|
||||
array(
|
||||
array('a' => 'apple', 'b' => 'orange', 'c' => 'citrus'),
|
||||
array('apple', 'orange', 'citrus'),
|
||||
),
|
||||
array(
|
||||
new ArrayObject(array('apple', 'orange', 'citrus')),
|
||||
array('apple', 'orange', 'citrus'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Robin van der Vleuten <robinvdvleuten@gmail.com>
|
||||
*/
|
||||
class Twig_Tests_Extension_DateTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var TwigEnvironment
|
||||
*/
|
||||
private $env;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getDiffTestData()
|
||||
*/
|
||||
public function testDiffWithStringsFromGivenNow($expected, $translated, $date, $now)
|
||||
{
|
||||
$extension = new Twig_Extensions_Extension_Date();
|
||||
$this->assertEquals($expected, $extension->diff($this->env, $date, $now));
|
||||
}
|
||||
|
||||
public function testDiffWithStringsFromNow()
|
||||
{
|
||||
$extension = new Twig_Extensions_Extension_Date();
|
||||
$this->assertRegExp('/^[0-9]+ (second|minute|hour|day|month|year)s* ago$/', $extension->diff($this->env, '24-07-2014'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getDiffTestData()
|
||||
*/
|
||||
public function testDiffWithDateTimeFromGivenNow($expected, $translated, $date, $now)
|
||||
{
|
||||
$extension = new Twig_Extensions_Extension_Date();
|
||||
$this->assertEquals($expected, $extension->diff($this->env, new DateTime($date), new DateTime($now)));
|
||||
}
|
||||
|
||||
public function testDiffWithDateTimeFromNow()
|
||||
{
|
||||
$extension = new Twig_Extensions_Extension_Date();
|
||||
$this->assertRegExp('/^[0-9]+ (second|minute|hour|day|month|year)s* ago$/', $extension->diff($this->env, new DateTime('24-07-2014')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getDiffTestData()
|
||||
*/
|
||||
public function testDiffCanReturnTranslatableString($expected, $translated, $date, $now)
|
||||
{
|
||||
$translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock();
|
||||
$translator
|
||||
->expects($this->once())
|
||||
->method('transChoice')
|
||||
->with($translated);
|
||||
|
||||
$extension = new Twig_Extensions_Extension_Date($translator);
|
||||
$extension->diff($this->env, $date, $now);
|
||||
}
|
||||
|
||||
public function getDiffTestData()
|
||||
{
|
||||
return array_merge($this->getDiffAgoTestData(), $this->getDiffInTestData());
|
||||
}
|
||||
|
||||
public function getDiffAgoTestData()
|
||||
{
|
||||
return array(
|
||||
array('1 second ago', 'diff.ago.second', '24-07-2014 17:28:01', '24-07-2014 17:28:02'),
|
||||
array('5 seconds ago', 'diff.ago.second', '24-07-2014 17:28:01', '24-07-2014 17:28:06'),
|
||||
array('1 minute ago', 'diff.ago.minute', '24-07-2014 17:28:01', '24-07-2014 17:29:01'),
|
||||
array('5 minutes ago', 'diff.ago.minute', '24-07-2014 17:28:01', '24-07-2014 17:33:03'),
|
||||
array('1 hour ago', 'diff.ago.hour', '24-07-2014 17:28:01', '24-07-2014 18:29:01'),
|
||||
array('9 hours ago', 'diff.ago.hour', '24-07-2014 17:28:01', '25-07-2014 02:33:03'),
|
||||
array('1 day ago', 'diff.ago.day', '23-07-2014', '24-07-2014'),
|
||||
array('5 days ago', 'diff.ago.day', '19-07-2014', '24-07-2014'),
|
||||
array('1 month ago', 'diff.ago.month', '23-07-2014', '24-08-2014'),
|
||||
array('6 months ago', 'diff.ago.month', '19-07-2014', '24-01-2015'),
|
||||
array('1 year ago', 'diff.ago.year', '19-07-2014', '20-08-2015'),
|
||||
array('3 years ago', 'diff.ago.year', '19-07-2014', '20-08-2017'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getDiffInTestData()
|
||||
{
|
||||
return array(
|
||||
array('in 1 second', 'diff.in.second', '24-07-2014 17:28:02', '24-07-2014 17:28:01'),
|
||||
array('in 5 seconds', 'diff.in.second', '24-07-2014 17:28:06', '24-07-2014 17:28:01'),
|
||||
array('in 1 minute', 'diff.in.minute', '24-07-2014 17:29:01', '24-07-2014 17:28:01'),
|
||||
array('in 5 minutes', 'diff.in.minute', '24-07-2014 17:33:03', '24-07-2014 17:28:01'),
|
||||
array('in 1 hour', 'diff.in.hour', '24-07-2014 18:29:01', '24-07-2014 17:28:01'),
|
||||
array('in 9 hours', 'diff.in.hour', '25-07-2014 02:33:03', '24-07-2014 17:28:01'),
|
||||
array('in 1 day', 'diff.in.day', '24-07-2014', '23-07-2014'),
|
||||
array('in 5 days', 'diff.in.day', '24-07-2014', '19-07-2014'),
|
||||
array('in 1 month', 'diff.in.month', '24-08-2014', '23-07-2014'),
|
||||
array('in 6 months', 'diff.in.month', '24-01-2015', '19-07-2014'),
|
||||
array('in 1 year', 'diff.in.year', '20-08-2015', '19-07-2014'),
|
||||
array('in 3 years', 'diff.in.year', '20-08-2017', '19-07-2014'),
|
||||
);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Extension_IntlTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @requires extension intl
|
||||
* @requires PHP 5.5
|
||||
*/
|
||||
public function testLocalizedDateFilterWithDateTimeZone()
|
||||
{
|
||||
class_exists('Twig_Extensions_Extension_Intl');
|
||||
$env = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
|
||||
$date = twig_localized_date_filter($env, new DateTime('2015-01-01T00:00:00', new DateTimeZone('UTC')), 'short', 'long', 'en', '+01:00');
|
||||
$this->assertEquals('1/1/15 1:00:00 AM GMT+01:00', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension intl
|
||||
* @requires PHP 5.5
|
||||
*/
|
||||
public function testLocalizedDateFilterWithDateTimeZoneZ()
|
||||
{
|
||||
class_exists('Twig_Extensions_Extension_Intl');
|
||||
$env = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
|
||||
$date = twig_localized_date_filter($env, new DateTime('2017-11-19T00:00:00Z'), 'short', 'long', 'fr', 'Z');
|
||||
$this->assertEquals('19/11/2017 00:00:00 UTC', $date);
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/../../../../lib/Twig/Extensions/Extension/Text.php';
|
||||
|
||||
class Twig_Tests_Extension_TextTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var TwigEnvironment */
|
||||
private $env;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->env = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
|
||||
$this->env
|
||||
->expects($this->any())
|
||||
->method('getCharset')
|
||||
->will($this->returnValue('utf-8'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTruncateTestData
|
||||
*/
|
||||
public function testTruncate($input, $length, $preserve, $separator, $expectedOutput)
|
||||
{
|
||||
$output = twig_truncate_filter($this->env, $input, $length, $preserve, $separator);
|
||||
$this->assertEquals($expectedOutput, $output);
|
||||
}
|
||||
|
||||
public function getTruncateTestData()
|
||||
{
|
||||
return array(
|
||||
array('This is a very long sentence.', 2, false, '...', 'Th...'),
|
||||
array('This is a very long sentence.', 6, false, '...', 'This i...'),
|
||||
array('This is a very long sentence.', 2, true, '...', 'This...'),
|
||||
array('This is a very long sentence.', 2, true, '[...]', 'This[...]'),
|
||||
array('This is a very long sentence.', 23, false, '...', 'This is a very long sen...'),
|
||||
array('This is a very long sentence.', 23, true, '...', 'This is a very long sentence.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_ArgumentsTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Arguments('foo');
|
||||
$this->assertEquals('<foo:arguments>', (string) $grammar);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_ArrayTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Array('foo');
|
||||
$this->assertEquals('<foo:array>', (string) $grammar);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_BodyTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Body('foo');
|
||||
$this->assertEquals('<foo:body>', (string) $grammar);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_BooleanTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Boolean('foo');
|
||||
$this->assertEquals('<foo:boolean>', (string) $grammar);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_ConstantTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Constant('foo');
|
||||
$this->assertEquals('foo', (string) $grammar);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_ExpressionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Expression('foo');
|
||||
$this->assertEquals('<foo>', (string) $grammar);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_NumberTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Number('foo');
|
||||
$this->assertEquals('<foo:number>', (string) $grammar);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_OptionalTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Optional(new Twig_Extensions_Grammar_Constant('foo'), new Twig_Extensions_Grammar_Number('bar'));
|
||||
$this->assertEquals('[foo <bar:number>]', (string) $grammar);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_TagTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Constant('foo'),
|
||||
new Twig_Extensions_Grammar_Number('bar'),
|
||||
new Twig_Extensions_Grammar_Optional(new Twig_Extensions_Grammar_Constant('foo'), new Twig_Extensions_Grammar_Number('bar'))
|
||||
);
|
||||
$this->assertEquals('foo <bar:number> [foo <bar:number>]', (string) $grammar);
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Node_TransTest extends Twig_Test_NodeTestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Twig_Node_Trans::__construct
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$count = new Twig_Node_Expression_Constant(12, 0);
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Text('Hello', 0),
|
||||
), array(), 0);
|
||||
$plural = new Twig_Node(array(
|
||||
new Twig_Node_Text('Hey ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('name', 0), 0),
|
||||
new Twig_Node_Text(', I have ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('count', 0), 0),
|
||||
new Twig_Node_Text(' apples', 0),
|
||||
), array(), 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, $plural, $count, null, 0);
|
||||
|
||||
$this->assertEquals($body, $node->getNode('body'));
|
||||
$this->assertEquals($count, $node->getNode('count'));
|
||||
$this->assertEquals($plural, $node->getNode('plural'));
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
$tests = array();
|
||||
|
||||
$body = new Twig_Node_Expression_Name('foo', 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, null, 0);
|
||||
$tests[] = array($node, sprintf('echo gettext(%s);', $this->getVariableGetter('foo')));
|
||||
|
||||
$body = new Twig_Node_Expression_Constant('Hello', 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, null, 0);
|
||||
$tests[] = array($node, 'echo gettext("Hello");');
|
||||
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Text('Hello', 0),
|
||||
), array(), 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, null, 0);
|
||||
$tests[] = array($node, 'echo gettext("Hello");');
|
||||
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Text('J\'ai ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 0), 0),
|
||||
new Twig_Node_Text(' pommes', 0),
|
||||
), array(), 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, null, 0);
|
||||
$tests[] = array($node, sprintf('echo strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo')));
|
||||
|
||||
$count = new Twig_Node_Expression_Constant(12, 0);
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Text('Hey ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('name', 0), 0),
|
||||
new Twig_Node_Text(', I have one apple', 0),
|
||||
), array(), 0);
|
||||
$plural = new Twig_Node(array(
|
||||
new Twig_Node_Text('Hey ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('name', 0), 0),
|
||||
new Twig_Node_Text(', I have ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('count', 0), 0),
|
||||
new Twig_Node_Text(' apples', 0),
|
||||
), array(), 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, $plural, $count, null, 0);
|
||||
$tests[] = array($node, sprintf('echo strtr(ngettext("Hey %%name%%, I have one apple", "Hey %%name%%, I have %%count%% apples", abs(12)), array("%%name%%" => %s, "%%name%%" => %s, "%%count%%" => abs(12), ));', $this->getVariableGetter('name'), $this->getVariableGetter('name')));
|
||||
|
||||
// with escaper extension set to on
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Text('J\'ai ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Filter(new Twig_Node_Expression_Name('foo', 0), new Twig_Node_Expression_Constant('escape', 0), new Twig_Node(), 0), 0),
|
||||
new Twig_Node_Text(' pommes', 0),
|
||||
), array(), 0);
|
||||
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, null, 0);
|
||||
$tests[] = array($node, sprintf('echo strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo')));
|
||||
|
||||
// with notes
|
||||
$body = new Twig_Node_Expression_Constant('Hello', 0);
|
||||
$notes = new Twig_Node_Text('Notes for translators', 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, $notes, 0);
|
||||
$tests[] = array($node, "// notes: Notes for translators\necho gettext(\"Hello\");");
|
||||
|
||||
$body = new Twig_Node_Expression_Constant('Hello', 0);
|
||||
$notes = new Twig_Node_Text("Notes for translators\nand line breaks", 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, $notes, 0);
|
||||
$tests[] = array($node, "// notes: Notes for translators and line breaks\necho gettext(\"Hello\");");
|
||||
|
||||
$count = new Twig_Node_Expression_Constant(5, 0);
|
||||
$body = new Twig_Node_Text('There is 1 pending task', 0);
|
||||
$plural = new Twig_Node(array(
|
||||
new Twig_Node_Text('There are ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('count', 0), 0),
|
||||
new Twig_Node_Text(' pending tasks', 0),
|
||||
), array(), 0);
|
||||
$notes = new Twig_Node_Text('Notes for translators', 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, $plural, $count, $notes, 0);
|
||||
$tests[] = array($node, "// notes: Notes for translators\n".'echo strtr(ngettext("There is 1 pending task", "There are %count% pending tasks", abs(5)), array("%count%" => abs(5), ));');
|
||||
|
||||
return $tests;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class SimpleTokenParser extends Twig_Extensions_SimpleTokenParser
|
||||
{
|
||||
protected $tag;
|
||||
protected $grammar;
|
||||
|
||||
public function __construct($tag, $grammar)
|
||||
{
|
||||
$this->tag = $tag;
|
||||
$this->grammar = $grammar;
|
||||
}
|
||||
|
||||
public function getGrammar()
|
||||
{
|
||||
return $this->grammar;
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
public function getNode(array $values, $line)
|
||||
{
|
||||
$nodes = array();
|
||||
$nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant('|', $line), $line);
|
||||
foreach ($values as $value) {
|
||||
if ($value instanceof Twig_Node) {
|
||||
if ($value instanceof Twig_Node_Expression_Array) {
|
||||
$nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Function('dump', $value, $line), $line);
|
||||
} else {
|
||||
$nodes[] = new Twig_Node_Print($value, $line);
|
||||
}
|
||||
} else {
|
||||
$nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant($value, $line), $line);
|
||||
}
|
||||
$nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant('|', $line), $line);
|
||||
}
|
||||
|
||||
return new Twig_Node($nodes);
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class Twig_Tests_SimpleTokenParserTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTests
|
||||
*/
|
||||
public function testParseGrammar($str, $grammar)
|
||||
{
|
||||
$this->assertEquals($grammar, Twig_Extensions_SimpleTokenParser::parseGrammar($str), '::parseGrammar() parses a grammar');
|
||||
}
|
||||
|
||||
public function testParseGrammarExceptions()
|
||||
{
|
||||
try {
|
||||
Twig_Extensions_SimpleTokenParser::parseGrammar('<foo:foo>');
|
||||
$this->fail();
|
||||
} catch (Exception $e) {
|
||||
$this->assertEquals('Twig_Error_Runtime', get_class($e));
|
||||
}
|
||||
|
||||
try {
|
||||
Twig_Extensions_SimpleTokenParser::parseGrammar('<foo:foo');
|
||||
$this->fail();
|
||||
} catch (Exception $e) {
|
||||
$this->assertEquals('Twig_Error_Runtime', get_class($e));
|
||||
}
|
||||
|
||||
try {
|
||||
Twig_Extensions_SimpleTokenParser::parseGrammar('<foo:foo> (with');
|
||||
$this->fail();
|
||||
} catch (Exception $e) {
|
||||
$this->assertEquals('Twig_Error_Runtime', get_class($e));
|
||||
}
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
return array(
|
||||
array('', new Twig_Extensions_Grammar_Tag()),
|
||||
array('const', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Constant('const')
|
||||
)),
|
||||
array(' const ', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Constant('const')
|
||||
)),
|
||||
array('<expr>', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr')
|
||||
)),
|
||||
array('<expr:expression>', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr')
|
||||
)),
|
||||
array(' <expr:expression> ', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr')
|
||||
)),
|
||||
array('<nb:number>', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Number('nb')
|
||||
)),
|
||||
array('<bool:boolean>', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Boolean('bool')
|
||||
)),
|
||||
array('<content:body>', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Body('content')
|
||||
)),
|
||||
array('<expr:expression> [with <arguments:array>]', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant('with'),
|
||||
new Twig_Extensions_Grammar_Array('arguments')
|
||||
)
|
||||
)),
|
||||
array(' <expr:expression> [ with <arguments:array> ] ', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant('with'),
|
||||
new Twig_Extensions_Grammar_Array('arguments')
|
||||
)
|
||||
)),
|
||||
array('<expr:expression> [with <arguments:array> [or <optional:expression>]]', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant('with'),
|
||||
new Twig_Extensions_Grammar_Array('arguments'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant('or'),
|
||||
new Twig_Extensions_Grammar_Expression('optional')
|
||||
)
|
||||
)
|
||||
)),
|
||||
array('<expr:expression> [with <arguments:array> [, <optional:expression>]]', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant('with'),
|
||||
new Twig_Extensions_Grammar_Array('arguments'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant(',', Twig_Token::PUNCTUATION_TYPE),
|
||||
new Twig_Extensions_Grammar_Expression('optional')
|
||||
)
|
||||
)
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class grammarTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
require_once __DIR__.'/SimpleTokenParser.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTests
|
||||
*/
|
||||
public function testGrammar($tag, $grammar, $template, $output, $exception)
|
||||
{
|
||||
$twig = new Twig_Environment(new Twig_Loader_Array(array('template' => $template)), array('cache' => false, 'autoescape' => false, 'debug' => true));
|
||||
$twig->addExtension(new Twig_Extension_Debug());
|
||||
$twig->addTokenParser(new SimpleTokenParser($tag, $grammar));
|
||||
|
||||
$ok = true;
|
||||
try {
|
||||
$template = $twig->loadTemplate('template');
|
||||
} catch (Exception $e) {
|
||||
$ok = false;
|
||||
|
||||
if (false === $exception) {
|
||||
$this->fail('Exception not expected');
|
||||
} else {
|
||||
$this->assertEquals($exception, get_class($e));
|
||||
}
|
||||
}
|
||||
|
||||
if ($ok) {
|
||||
if (false !== $exception) {
|
||||
$this->fail(sprintf('Exception "%s" expected', $exception));
|
||||
}
|
||||
|
||||
$actual = $template->render(array());
|
||||
$this->assertEquals($output, $actual);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
return array(
|
||||
array('foo1', '', '{% foo1 %}', '|', false),
|
||||
array('foo2', '', '{% foo2 "bar" %}', '|', 'Twig_Error_Syntax'),
|
||||
array('foo3', '<foo>', '{% foo3 "bar" %}', '|bar|', false),
|
||||
array('foo4', '<foo>', '{% foo4 1 + 2 %}', '|3|', false),
|
||||
array('foo5', '<foo:expression>', '{% foo5 1 + 2 %}', '|3|', false),
|
||||
array('foo6', '<foo:array>', '{% foo6 1 + 2 %}', '|3|', 'Twig_Error_Syntax'),
|
||||
array('foo7', '<foo>', '{% foo7 %}', '|3|', 'Twig_Error_Syntax'),
|
||||
array('foo8', '<foo:array>', '{% foo8 [1, 2] %}', "|int(0)\nint(1)\nint(1)\nint(2)\n|", false),
|
||||
array('foo9', '<foo> with <bar>', '{% foo9 "bar" with "foobar" %}', '|bar|with|foobar|', false),
|
||||
array('foo10', '<foo> [with <bar>]', '{% foo10 "bar" with "foobar" %}', '|bar|with|foobar|', false),
|
||||
array('foo11', '<foo> [with <bar>]', '{% foo11 "bar" %}', '|bar|', false),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -13271,6 +13271,17 @@ a.link-white-underline {
|
||||
#link-videotheque {
|
||||
font-size: 13px; }
|
||||
|
||||
/* Cookie bar */
|
||||
#fairlane-cookie-consent {
|
||||
z-index: 1000;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
font-size: 12px; }
|
||||
|
||||
/*************************** CONTENU *************************/
|
||||
#homeTeaser {
|
||||
height: calc(100vh);
|
||||
@@ -15910,6 +15921,10 @@ table.highlight > tbody > tr:hover {
|
||||
#page-static {
|
||||
font-size: 14px;
|
||||
/***** OLD STEP *****/ }
|
||||
#page-static h2 {
|
||||
font-size: 22px; }
|
||||
#page-static h3 {
|
||||
font-size: 20px; }
|
||||
#page-static #tarifs .col-tarif {
|
||||
padding: 0 20px;
|
||||
font-size: 12px; }
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -266,4 +266,16 @@
|
||||
|
||||
#link-videotheque{
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Cookie bar */
|
||||
#fairlane-cookie-consent{
|
||||
z-index:1000;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
background: rgba(255,255,255,0.8);
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
font-size:12px;
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
#page-static {
|
||||
h2{
|
||||
font-size: 22px;
|
||||
}
|
||||
h3{
|
||||
font-size: 20px;
|
||||
}
|
||||
#tarifs {
|
||||
.col-tarif {
|
||||
padding: 0 20px;
|
||||
|
||||
Reference in New Issue
Block a user