Completed
Push — master ( 8d14cd...aab142 )
by Aimeos
01:56
created

Shop::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2019
6
 * @package laravel
7
 * @subpackage Base
8
 */
9
10
namespace Aimeos\Shop\Base;
11
12
13
/**
14
 * Service providing the shop object
15
 *
16
 * @package laravel
17
 * @subpackage Base
18
 */
19
class Shop
20
{
21
	/**
22
	 * @var \Aimeos\MShop\Context\Item\Iface
23
	 */
24
	private $context;
25
26
	/**
27
	 * @var \Aimeos\MW\View\Iface
28
	 */
29
	private $view;
30
31
	/**
32
	 * @var array
33
	 */
34
	private $objects = [];
35
36
37
	/**
38
	 * Initializes the object
39
	 *
40
	 * @param \Aimeos\Shop\Base\Aimeos $aimeos Aimeos object
41
	 * @param \Aimeos\Shop\Base\Context $context Context object
42
	 * @param \Aimeos\Shop\Base\View $view View object
43
	 */
44
	public function __construct(  \Aimeos\Shop\Base\Aimeos $aimeos,
45
		\Aimeos\Shop\Base\Context $context, \Aimeos\Shop\Base\View $view )
46
	{
47
		$this->context = $context->get();
48
49
		$langid = $this->context->getLocale()->getLanguageId();
50
		$tmplPaths = $aimeos->get()->getCustomPaths( 'client/html/templates' );
51
52
		$this->view = $view->create( $this->context, $tmplPaths, $langid );
53
		$this->context->setView( $this->view );
54
	}
55
56
57
	/**
58
	 * Returns the HTML client for the given name
59
	 *
60
	 * @param string $name Name of the shop component
61
	 * @return \Aimeos\Client\Html\Iface HTML client
62
	 */
63
	public function get( $name )
64
	{
65
		if( !isset( $this->objects[$name] ) )
66
		{
67
			$client = \Aimeos\Client\Html::create( $this->context, $name );
68
			$client->setView( clone $this->view );
69
			$client->process();
70
71
			$this->objects[$name] = $client;
72
		}
73
74
		return $this->objects[$name];
75
	}
76
}