Passed
Push — master ( 542bba...4c863a )
by Dev
13:56
created

ShortCodeConverter::do()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace PiedWeb\CMSBundle\Service;
4
5
use Exception;
6
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
7
use Symfony\Component\HttpFoundation\Request;
8
9
class ShortCodeConverter
10
{
11
    public static function do($string, $locale = null)
12
    {
13
        //var_dump($string); exit;
14
        if ($locale) setlocale(LC_TIME, self::convertLocale($locale));
15
16
        //var_dump(self::convertLocale($locale)); exit;
17
        //$string = preg_replace('/date\([\'"]?([a-z% ]+)[\'"]?\)/i', strftime(strpos('\1', '%') ? '\1': '%\1'), $string);
18
        $string = preg_replace('/date\([\'"]?%?Y[\'"]?\)/i', strftime('%Y'), $string);
19
        $string = preg_replace('/date\([\'"]?%?(B|M)[\'"]?\)/i', strftime('%B'), $string);
20
        $string = preg_replace('/date\([\'"]?%?A[\'"]?\)/i', strftime('%A'), $string);
21
        $string = preg_replace('/date\([\'"]?%?e[\'"]?\)/i', strftime('%e'), $string);
22
23
        return $string;
24
    }
25
26
    public static function convertLocale($locale)
27
    {
28
        if ($locale == 'fr')
29
            return 'fr_FR';
30
31
        if ($locale == 'en')
32
            return 'en_UK';
33
34
        return $locale;
35
    }
36
}