Passed
Push — master ( 48f748...8ce03c )
by Nathan
06:40 queued 03:18
created

Container::getPageRepository()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Service;
18
19
use CuyZ\Notiz\Service\Traits\ExtendedSelfInstantiateTrait;
20
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21
use TYPO3\CMS\Core\SingletonInterface;
22
use TYPO3\CMS\Extbase\Object\ObjectManager;
23
use TYPO3\CMS\Frontend\Page\PageRepository;
24
25
class Container implements SingletonInterface
26
{
27
    use ExtendedSelfInstantiateTrait {
28
        get as getInstance;
29
    }
30
31
    /**
32
     * @var ObjectManager
33
     */
34
    protected $objectManager;
35
36
    /**
37
     * @var PageRepository
38
     */
39
    protected $pageRepository;
40
41
    /**
42
     * @param ObjectManager $objectManager
43
     */
44
    public function __construct(ObjectManager $objectManager)
45
    {
46
        $this->objectManager = $objectManager;
47
    }
48
49
    /**
50
     * @param string $className
51
     * @param mixed ...$arguments
52
     * @return object
53
     */
54
    public static function get($className, ...$arguments)
55
    {
56
        return static::getInstance()->objectManager->get($className, ...$arguments);
57
    }
58
59
    /**
60
     * @return BackendUserAuthentication
61
     */
62
    public static function getBackendUser()
63
    {
64
        return $GLOBALS['BE_USER'];
65
    }
66
67
    /**
68
     * @return PageRepository
69
     */
70
    public static function getPageRepository()
71
    {
72
        $instance = self::getInstance();
73
74
        if (null === $instance->pageRepository) {
75
            $instance->pageRepository = $instance->get(PageRepository::class);
76
        }
77
78
        return $instance->pageRepository;
79
    }
80
}
81