Standard::getSubClient()   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
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2015-2025
7
 * @package Client
8
 * @subpackage Html
9
 */
10
11
12
namespace Aimeos\Client\Html\Basket\Mini;
13
14
15
/**
16
 * Default implementation of mini basket HTML client.
17
 *
18
 * @package Client
19
 * @subpackage Html
20
 */
21
class Standard
22
	extends \Aimeos\Client\Html\Basket\Base
23
	implements \Aimeos\Client\Html\Common\Client\Factory\Iface
24
{
25
	/** client/html/basket/mini/name
26
	 * Class name of the used basket mini client implementation
27
	 *
28
	 * Each default HTML client can be replace by an alternative imlementation.
29
	 * To use this implementation, you have to set the last part of the class
30
	 * name as configuration value so the client factory knows which class it
31
	 * has to instantiate.
32
	 *
33
	 * For example, if the name of the default class is
34
	 *
35
	 *  \Aimeos\Client\Html\Basket\Mini\Standard
36
	 *
37
	 * and you want to replace it with your own version named
38
	 *
39
	 *  \Aimeos\Client\Html\Basket\Mini\Mybasket
40
	 *
41
	 * then you have to set the this configuration option:
42
	 *
43
	 *  client/html/basket/mini/name = Mybasket
44
	 *
45
	 * The value is the last part of your own class name and it's case sensitive,
46
	 * so take care that the configuration value is exactly named like the last
47
	 * part of the class name.
48
	 *
49
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
50
	 * characters are possible! You should always start the last part of the class
51
	 * name with an upper case character and continue only with lower case characters
52
	 * or numbers. Avoid chamel case names like "MyBasket"!
53
	 *
54
	 * @param string Last part of the class name
55
	 * @since 2014.03
56
	 */
57
58
59
	/** client/html/basket/mini/subparts
60
	 * List of HTML sub-clients rendered within the basket mini section
61
	 *
62
	 * The output of the frontend is composed of the code generated by the HTML
63
	 * clients. Each HTML client can consist of serveral (or none) sub-clients
64
	 * that are responsible for rendering certain sub-parts of the output. The
65
	 * sub-clients can contain HTML clients themselves and therefore a
66
	 * hierarchical tree of HTML clients is composed. Each HTML client creates
67
	 * the output that is placed inside the container of its parent.
68
	 *
69
	 * At first, always the HTML code generated by the parent is printed, then
70
	 * the HTML code of its sub-clients. The order of the HTML sub-clients
71
	 * determines the order of the output of these sub-clients inside the parent
72
	 * container. If the configured list of clients is
73
	 *
74
	 *  array( "subclient1", "subclient2" )
75
	 *
76
	 * you can easily change the order of the output by reordering the subparts:
77
	 *
78
	 *  client/html/<clients>/subparts = array( "subclient1", "subclient2" )
79
	 *
80
	 * You can also remove one or more parts if they shouldn't be rendered:
81
	 *
82
	 *  client/html/<clients>/subparts = array( "subclient1" )
83
	 *
84
	 * As the clients only generates structural HTML, the layout defined via CSS
85
	 * should support adding, removing or reordering content by a fluid like
86
	 * design.
87
	 *
88
	 * @param array List of sub-client names
89
	 * @since 2014.03
90
	 */
91
	private string $subPartPath = 'client/html/basket/mini/subparts';
92
93
	private ?\Aimeos\Base\View\Iface $view = null;
94
	private array $subPartNames = [];
95
96
97
	/**
98
	 * Returns the HTML code for insertion into the body.
99
	 *
100
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
101
	 * @return string HTML code
102
	 */
103
	public function body( string $uid = '' ) : string
104
	{
105
		$context = $this->context();
106
		$site = $context->locale()->getSiteId();
107
108
		/** client/html/basket/mini
109
		 * All parameters defined for the small basket component and its subparts
110
		 *
111
		 * This returns all settings related to the small basket component.
112
		 * Please refer to the single settings for details.
113
		 *
114
		 * @param array Associative list of name/value settings
115
		 * @see client/html/basket#mini
116
		 */
117
		$config = $context->config()->get( 'client/html/basket/mini', [] );
118
		$key = $this->getParamHash( [], $uid . $site . ':basket:mini-body', $config );
119
120
		if( $html = $this->getBasketCached( $key ) ) {
121
			return $this->modify( $html, $uid );
122
		}
123
124
		/** client/html/basket/mini/template-body
125
		 * Relative path to the HTML body template of the basket mini client.
126
		 *
127
		 * The template file contains the HTML code and processing instructions
128
		 * to generate the result shown in the body of the frontend. The
129
		 * configuration string is the path to the template file relative
130
		 * to the templates directory (usually in templates/client/html).
131
		 *
132
		 * You can overwrite the template file configuration in extensions and
133
		 * provide alternative templates. These alternative templates should be
134
		 * named like the default one but suffixed by
135
		 * an unique name. You may use the name of your project for this. If
136
		 * you've implemented an alternative client class as well, it
137
		 * should be suffixed by the name of the new class.
138
		 *
139
		 * @param string Relative path to the template creating code for the HTML page body
140
		 * @since 2014.03
141
		 * @see client/html/basket/mini/template-header
142
		 */
143
		$template = $this->context()->config()->get( 'client/html/basket/mini/template-body', 'basket/mini/body' );
144
145
		$view = $this->view = $this->view ?? $this->object()->data( $this->view() );
146
		$html = $this->modify( $view->render( $template ), $uid );
147
148
		return (string) $this->setBasketCached( $key, $html );
149
	}
150
151
152
	/**
153
	 * Returns the HTML string for insertion into the header.
154
	 *
155
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
156
	 * @return string|null String including HTML tags for the header on error
157
	 */
158
	public function header( string $uid = '' ) : ?string
159
	{
160
		$context = $this->context();
161
		$site = $context->locale()->getSiteId();
162
163
		$config = $context->config()->get( 'client/html/basket/mini', [] );
164
		$key = $this->getParamHash( [], $uid . $site . ':basket:mini-header', $config );
165
166
		if( $html = $this->getBasketCached( $key ) ) {
167
			return $this->modify( $html, $uid );
168
		}
169
170
		/** client/html/basket/mini/template-header
171
		 * Relative path to the HTML header template of the basket mini client.
172
		 *
173
		 * The template file contains the HTML code and processing instructions
174
		 * to generate the HTML code that is inserted into the HTML page header
175
		 * of the rendered page in the frontend. The configuration string is the
176
		 * path to the template file relative to the templates directory (usually
177
		 * in templates/client/html).
178
		 *
179
		 * You can overwrite the template file configuration in extensions and
180
		 * provide alternative templates. These alternative templates should be
181
		 * named like the default one but suffixed by
182
		 * an unique name. You may use the name of your project for this. If
183
		 * you've implemented an alternative client class as well, it
184
		 * should be suffixed by the name of the new class.
185
		 *
186
		 * @param string Relative path to the template creating code for the HTML page head
187
		 * @since 2014.03
188
		 * @see client/html/basket/mini/template-body
189
		 */
190
		$template = $this->context()->config()->get( 'client/html/basket/mini/template-header', 'basket/mini/header' );
191
192
		$view = $this->view = $this->view ?? $this->object()->data( $this->view() );
193
		$html = $this->modify( $view->render( $template ), $uid );
194
195
		return $this->setBasketCached( $key, $html );
196
	}
197
198
199
	/**
200
	 * Returns the sub-client given by its name.
201
	 *
202
	 * @param string $type Name of the client type
203
	 * @param string|null $name Name of the sub-client (Default if null)
204
	 * @return \Aimeos\Client\Html\Iface Sub-client object
205
	 */
206
	public function getSubClient( string $type, ?string $name = null ) : \Aimeos\Client\Html\Iface
207
	{
208
		return $this->createSubClient( 'basket/mini/' . $type, $name );
209
	}
210
211
212
	/**
213
	 * Returns the list of sub-client names configured for the client.
214
	 *
215
	 * @return array List of HTML client names
216
	 */
217
	protected function getSubClientNames() : array
218
	{
219
		return $this->context()->config()->get( $this->subPartPath, $this->subPartNames );
220
	}
221
222
223
	/**
224
	 * Sets the necessary parameter values in the view.
225
	 *
226
	 * @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output
227
	 * @param array &$tags Result array for the list of tags that are associated to the output
228
	 * @param string|null &$expire Result variable for the expiration date of the output (null for no expiry)
229
	 * @return \Aimeos\Base\View\Iface Modified view object
230
	 */
231
	public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], ?string &$expire = null ) : \Aimeos\Base\View\Iface
232
	{
233
		$controller = \Aimeos\Controller\Frontend::create( $this->context(), 'basket' );
234
		$view->miniBasket = $controller->get();
235
236
		return parent::data( $view, $tags, $expire );
237
	}
238
239
240
	/** client/html/basket/mini/decorators/excludes
241
	 * Excludes decorators added by the "common" option from the basket mini html client
242
	 *
243
	 * Decorators extend the functionality of a class by adding new aspects
244
	 * (e.g. log what is currently done), executing the methods of the underlying
245
	 * class only in certain conditions (e.g. only for logged in users) or
246
	 * modify what is returned to the caller.
247
	 *
248
	 * This option allows you to remove a decorator added via
249
	 * "client/html/common/decorators/default" before they are wrapped
250
	 * around the html client.
251
	 *
252
	 *  client/html/basket/mini/decorators/excludes = array( 'decorator1' )
253
	 *
254
	 * This would remove the decorator named "decorator1" from the list of
255
	 * common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via
256
	 * "client/html/common/decorators/default" to the html client.
257
	 *
258
	 * @param array List of decorator names
259
	 * @since 2014.05
260
	 * @see client/html/common/decorators/default
261
	 * @see client/html/basket/mini/decorators/global
262
	 * @see client/html/basket/mini/decorators/local
263
	 */
264
265
	/** client/html/basket/mini/decorators/global
266
	 * Adds a list of globally available decorators only to the basket mini html client
267
	 *
268
	 * Decorators extend the functionality of a class by adding new aspects
269
	 * (e.g. log what is currently done), executing the methods of the underlying
270
	 * class only in certain conditions (e.g. only for logged in users) or
271
	 * modify what is returned to the caller.
272
	 *
273
	 * This option allows you to wrap global decorators
274
	 * ("\Aimeos\Client\Html\Common\Decorator\*") around the html client.
275
	 *
276
	 *  client/html/basket/mini/decorators/global = array( 'decorator1' )
277
	 *
278
	 * This would add the decorator named "decorator1" defined by
279
	 * "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client.
280
	 *
281
	 * @param array List of decorator names
282
	 * @since 2014.05
283
	 * @see client/html/common/decorators/default
284
	 * @see client/html/basket/mini/decorators/excludes
285
	 * @see client/html/basket/mini/decorators/local
286
	 */
287
288
	/** client/html/basket/mini/decorators/local
289
	 * Adds a list of local decorators only to the basket mini html client
290
	 *
291
	 * Decorators extend the functionality of a class by adding new aspects
292
	 * (e.g. log what is currently done), executing the methods of the underlying
293
	 * class only in certain conditions (e.g. only for logged in users) or
294
	 * modify what is returned to the caller.
295
	 *
296
	 * This option allows you to wrap local decorators
297
	 * ("\Aimeos\Client\Html\Basket\Decorator\*") around the html client.
298
	 *
299
	 *  client/html/basket/mini/decorators/local = array( 'decorator2' )
300
	 *
301
	 * This would add the decorator named "decorator2" defined by
302
	 * "\Aimeos\Client\Html\Basket\Decorator\Decorator2" only to the html client.
303
	 *
304
	 * @param array List of decorator names
305
	 * @since 2014.05
306
	 * @see client/html/common/decorators/default
307
	 * @see client/html/basket/mini/decorators/excludes
308
	 * @see client/html/basket/mini/decorators/global
309
	 */
310
}
311