Completed
Push — master ( def7d9...4bce11 )
by Aimeos
01:54
created

Shop::get()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 3
nc 2
nop 4
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package Slim
7
 * @subpackage Base
8
 */
9
10
namespace Aimeos\Slim\Base;
11
12
use Interop\Container\ContainerInterface;
13
use Psr\Http\Message\ServerRequestInterface;
14
use Psr\Http\Message\ResponseInterface;
15
16
17
/**
18
 * Service providing the shop object
19
 *
20
 * @package Slim
21
 * @subpackage Base
22
 */
23
class Shop
24
{
25
	private $container;
26
27
28
	/**
29
	 * Initializes the object
30
	 *
31
	 * @param ContainerInterface $container Dependency container
32
	 */
33
	public function __construct( ContainerInterface $container )
34
	{
35
		$this->container = $container;
36
	}
37
38
39
	/**
40
	 * Returns the body and header sections created by the clients configured for the given page name.
41
	 *
42
	 * @param string $pageName Name of the configured page
43
	 * @param ServerRequestInterface $request Request object
44
	 * @param ResponseInterface $response Response object
45
	 * @param array Associative list of URI attributes
46
	 * @return array Associative list with body and header output separated by client name
47
	 */
48
	public function get( $pageName, ServerRequestInterface $request, ResponseInterface $response, array $attr )
49
	{
50
		$tmplPaths = $this->container->get( 'aimeos' )->getCustomPaths( 'client/html/templates' );
51
		$context = $this->container->get( 'aimeos.context' )->get( true, $attr );
52
		$langid = $context->getLocale()->getLanguageId();
53
54
		$view = $this->container->get( 'aimeos.view' )->create( $context, $request, $response, $attr, $tmplPaths, $langid );
55
		$context->setView( $view );
56
57
		$pagesConfig = $this->container->get( 'aimeos.config' )->get()->get( 'page', array() );
58
		$result = array( 'aibody' => array(), 'aiheader' => array() );
59
60
		if( isset( $pagesConfig[$pageName] ) )
61
		{
62
			foreach( (array) $pagesConfig[$pageName] as $clientName )
63
			{
64
				$client = \Aimeos\Client\Html::create( $context, $clientName );
65
				$client->setView( clone $view );
66
				$client->process();
67
68
				$result['aibody'][$clientName] = $client->getBody();
69
				$result['aiheader'][$clientName] = $client->getHeader();
70
			}
71
		}
72
73
		return $result;
74
	}
75
}
76