Shop   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 80
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A template() 0 4 2
A get() 0 12 2
A view() 0 3 1
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2023
6
 */
7
8
namespace Aimeos\Shop\Base;
9
10
11
/**
12
 * Service providing the shop object
13
 */
14
class Shop
15
{
16
	/**
17
	 * @var \Aimeos\MShop\ContextIface
18
	 */
19
	private $context;
20
21
	/**
22
	 * @var \Aimeos\Base\View\Iface
23
	 */
24
	private $view;
25
26
	/**
27
	 * @var array
28
	 */
29
	private $objects = [];
30
31
32
	/**
33
	 * Initializes the object
34
	 *
35
	 * @param \Aimeos\Shop\Base\Aimeos $aimeos Aimeos object
36
	 * @param \Aimeos\Shop\Base\Context $context Context object
37
	 * @param \Aimeos\Shop\Base\View $view View object
38
	 */
39
	public function __construct( \Aimeos\Shop\Base\Aimeos $aimeos,
40
		\Aimeos\Shop\Base\Context $context, \Aimeos\Shop\Base\View $view )
41
	{
42
		$this->context = $context->get();
43
		$locale = $this->context->locale();
44
45
		$tmplPaths = $aimeos->get()->getTemplatePaths( 'client/html/templates', $locale->getSiteItem()->getTheme() );
46
		$langid = $locale->getLanguageId();
47
48
		$this->view = $view->create( $this->context, $tmplPaths, $langid );
49
		$this->context->setView( $this->view );
50
	}
51
52
53
	/**
54
	 * Returns the HTML client for the given name
55
	 *
56
	 * @param string $name Name of the shop component
57
	 * @return \Aimeos\Client\Html\Iface HTML client
58
	 */
59
	public function get( string $name ) : \Aimeos\Client\Html\Iface
60
	{
61
		if( !isset( $this->objects[$name] ) )
62
		{
63
			$client = \Aimeos\Client\Html::create( $this->context, $name );
64
			$client->setView( clone $this->view );
65
			$client->init();
66
67
			$this->objects[$name] = $client;
68
		}
69
70
		return $this->objects[$name];
71
	}
72
73
74
	/** Returns the view template for the given name
75
	 *
76
	 * @param string $name View name, e.g. "account.index"
77
	 * @return string Template name, e.g. "shop::account.indx"
78
	 */
79
	public function template( string $name ) : string
80
	{
81
		$theme = $this->context->locale()->getSiteItem()->getTheme();
82
		return \Illuminate\Support\Facades\View::exists( $theme . '::' . $name ) ? $theme . '::' . $name : 'shop::' . $name;
83
	}
84
85
86
	/**
87
	 * Returns the used view object
88
	 *
89
	 * @return \Aimeos\Base\View\Iface View object
90
	 */
91
	public function view() : \Aimeos\Base\View\Iface
92
	{
93
		return $this->view;
94
	}
95
}
96