UtilTrait::getStash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Jaxon\Di\Traits;
4
5
use Jaxon\App\Stash\Stash;
6
use Jaxon\App\I18n\Translator;
7
use Jaxon\Utils\Config\ConfigReader;
8
use Jaxon\Utils\Http\UriDetector;
9
use Jaxon\Utils\Template\TemplateEngine;
10
11
use function rtrim;
12
use function trim;
13
14
trait UtilTrait
15
{
16
    /**
17
     * Register the values into the container
18
     *
19
     * @return void
20
     */
21
    private function registerUtils()
22
    {
23
        // Translator
24
        $this->set(Translator::class, function($di) {
0 ignored issues
show
Bug introduced by
It seems like set() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $this->/** @scrutinizer ignore-call */ 
25
               set(Translator::class, function($di) {
Loading history...
25
            $xTranslator = new Translator();
26
            $sResourceDir = rtrim(trim($di->g('jaxon.core.dir.translation')), '/\\');
27
            // Load the debug translations
28
            $xTranslator->loadTranslations($sResourceDir . '/en/errors.php', 'en');
29
            $xTranslator->loadTranslations($sResourceDir . '/fr/errors.php', 'fr');
30
            $xTranslator->loadTranslations($sResourceDir . '/es/errors.php', 'es');
31
            // Load the config translations
32
            $xTranslator->loadTranslations($sResourceDir . '/en/config.php', 'en');
33
            $xTranslator->loadTranslations($sResourceDir . '/fr/config.php', 'fr');
34
            $xTranslator->loadTranslations($sResourceDir . '/es/config.php', 'es');
35
            // Load the labels translations
36
            $xTranslator->loadTranslations($sResourceDir . '/en/labels.php', 'en');
37
            $xTranslator->loadTranslations($sResourceDir . '/fr/labels.php', 'fr');
38
            $xTranslator->loadTranslations($sResourceDir . '/es/labels.php', 'es');
39
            return $xTranslator;
40
        });
41
42
        // Config reader
43
        $this->set(ConfigReader::class, function() {
44
            return new ConfigReader();
45
        });
46
        // Template engine
47
        $this->set(TemplateEngine::class, function($di) {
48
            $xTemplateEngine = new TemplateEngine();
49
            $sTemplateDir = rtrim(trim($di->g('jaxon.core.dir.template')), '/\\');
50
            $sPaginationDir = $sTemplateDir . DIRECTORY_SEPARATOR . 'pagination';
51
            $xTemplateEngine->addNamespace('jaxon', $sTemplateDir, '.php');
52
            $xTemplateEngine->addNamespace('pagination', $sPaginationDir, '.php');
53
            $xTemplateEngine->setDefaultNamespace('jaxon');
54
            return $xTemplateEngine;
55
        });
56
        // URI detector
57
        $this->set(UriDetector::class, function() {
58
            return new UriDetector();
59
        });
60
61
        // Temp cache for Jaxon callable classes
62
        $this->set(Stash::class, function() {
63
            return new Stash();
64
        });
65
    }
66
67
    /**
68
     * Get the template engine
69
     *
70
     * @return TemplateEngine
71
     */
72
    public function getTemplateEngine(): TemplateEngine
73
    {
74
        return $this->g(TemplateEngine::class);
0 ignored issues
show
Bug introduced by
It seems like g() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
        return $this->/** @scrutinizer ignore-call */ g(TemplateEngine::class);
Loading history...
75
    }
76
77
    /**
78
     * Get the temp cache for Jaxon callable classes
79
     *
80
     * @return Stash
81
     */
82
    public function getStash(): Stash
83
    {
84
        return $this->g(Stash::class);
85
    }
86
}
87