Completed
Pull Request — wip-lisem (#49)
by
unknown
02:42
created

LibrinfoLabelTranslatorStrategy::getAdmin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Blast Project package.
5
 *
6
 * Copyright (C) 2015-2017 Libre Informatique
7
 *
8
 * This file is licenced under the GNU LGPL v3.
9
 * For the full copyright and license information, please view the LICENSE.md
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Blast\CoreBundle\Translator;
14
15
use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface;
16
17
/**
18
 * Class LibrinfoLabelTranslatorStrategy.
19
 *
20
 * Provides a specific label translation strategy for Librinfo.
21
 * It is based on UnderscoreLabelTranslatorStrategy, but without the context,
22
 * and labels are prefixed by "librinfo.label."
23
 *
24
 * i.e. isValid => librinfo.label.is_valid
25
 */
26
class LibrinfoLabelTranslatorStrategy implements LabelTranslatorStrategyInterface
27
{
28
    private $admin;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getLabel($label, $context = '', $type = '')
34
    {
35
        $label = str_replace('.', '_', $label);
36
37
        return sprintf('%s.%s.%s.%s', 'librinfo', $type, strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $this->getAdmin()->getClassnameLabel())), strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label)));
38
    }
39
40
    /**
41
     * @return mixed
42
     */
43
    public function getAdmin()
44
    {
45
        return $this->admin;
46
    }
47
48
    /**
49
     * @param mixed admin
50
     *
51
     * @return self
52
     */
53
    public function setAdmin($admin)
54
    {
55
        $this->admin = $admin;
56
57
        return $this;
58
    }
59
}
60