Intl::getFilters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace DoS\ResourceBundle\Twig\Extension;
4
5
class Intl extends \Twig_Extensions_Extension_Intl
6
{
7
    protected $traditional = true;
8
9
    public function __construct($traditional = true)
10
    {
11
        parent::__construct();
12
13
        $this->traditional = $traditional;
14
    }
15
16
    public function getFilters()
17
    {
18
        return array(
19
            new \Twig_SimpleFilter('localizeddate', array($this, 'twig_localized_date_filter'), array('needs_environment' => true)),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
20
            new \Twig_SimpleFilter('localizednumber', 'twig_localized_number_filter'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
21
            new \Twig_SimpleFilter('localizedcurrency', 'twig_localized_currency_filter'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
22
        );
23
    }
24
25
    public function twig_localized_date_filter(\Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null)
26
    {
27
        $date = twig_date_converter($env, $date, $timezone);
28
29
        $formatValues = array(
30
            'none' => \IntlDateFormatter::NONE,
31
            'short' => \IntlDateFormatter::SHORT,
32
            'medium' => \IntlDateFormatter::MEDIUM,
33
            'long' => \IntlDateFormatter::LONG,
34
            'full' => \IntlDateFormatter::FULL,
35
        );
36
37
        $formatter = \IntlDateFormatter::create(
38
            $locale,
39
            $formatValues[$dateFormat],
40
            $formatValues[$timeFormat],
41
            $date->getTimezone()->getName(),
42
            $this->traditional ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN,
43
            $format
44
        );
45
46
        return $formatter->format($date->getTimestamp());
47
    }
48
}
49