Passed
Push — master ( 456cc4...4a5fe5 )
by Hector Luis
22:19
created

ServiceLocator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Service Locator Class
6
 * @category    Ticaje
7
 * @package     Ticaje_Base
8
 * @author      Hector Luis Barrientos <[email protected]>
9
 */
10
11
namespace Ticaje\Base\Application\Service;
12
13
use Magento\Framework\ObjectManagerInterface as MagentoObjectManagerInterface;
14
15
/**
16
 * Class ServiceLocator
17
 * @package Ticaje\Base\Application\Service
18
 * This class kind of performs gateway pattern design in order to provide consistency to our Model Domain
19
 * According to DI principle it complies to separate the Model Domain from the current framework.
20
 * We're gonna play Magento rules since this is a Gateway, so our Domain does not get touched by Magento's
21
 */
22
class ServiceLocator implements ServiceLocatorInterface
23
{
24
    protected $objectManager;
25
26
    /**
27
     * ServiceLocator constructor.
28
     * @param MagentoObjectManagerInterface $objectManager
29
     * Using composition over inheritance of course
30
     */
31
    public function __construct(
32
        MagentoObjectManagerInterface $objectManager
33
    ) {
34
        $this->objectManager = $objectManager;
35
    }
36
37
    /**
38
     * @param $class
39
     * @return mixed
40
     */
41
    public function get($class)
42
    {
43
        return $this->objectManager->get($class);
44
    }
45
46
    public function create($class, array $arguments = [])
47
    {
48
        return $this->objectManager->create($class, $arguments);
49
    }
50
}
51