Completed
Push — master ( 6a6db8...a58ba8 )
by Aimeos
03:14
created

View::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 48
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 1 Features 3
Metric Value
c 7
b 1
f 3
dl 0
loc 48
rs 9.125
cc 2
eloc 29
nc 2
nop 3
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 * @subpackage Base
8
 */
9
10
namespace Aimeos\Shop\Base;
11
12
13
use Illuminate\Support\Facades\Input;
14
use Illuminate\Support\Facades\Route;
15
use Illuminate\Support\Facades\Request;
16
use Illuminate\Support\Facades\Response;
17
18
19
/**
20
 * Service providing the view objects
21
 *
22
 * @package laravel
23
 * @subpackage Base
24
 */
25
class View
26
{
27
	/**
28
	 * Creates the view object for the HTML client.
29
	 *
30
	 * @param \Aimeos\MW\Config\Iface $config Configuration object
31
	 * @param array $templatePaths List of base path names with relative template paths as key/value pairs
32
	 * @param string|null $locale Code of the current language or null for no translation
33
	 * @return \Aimeos\MW\View\Iface View object
34
	 */
35
	public function create( \Aimeos\MW\Config\Iface $config, array $templatePaths, $locale = null )
36
	{
37
		$params = $fixed = array();
38
39
		if( $locale !== null )
40
		{
41
			$params = Route::current()->parameters() + Input::all();
42
			$fixed = $this->getFixedParams();
43
44
			$i18n = app('\Aimeos\Shop\Base\I18n')->get( array( $locale ) );
45
			$translation = $i18n[$locale];
46
		}
47
		else
48
		{
49
			$translation = new \Aimeos\MW\Translation\None( 'en' );
50
		}
51
52
53
		$view = new \Aimeos\MW\View\Standard( $templatePaths );
54
55
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $translation );
56
		$view->addHelper( 'translate', $helper );
57
58
		$helper = new \Aimeos\MW\View\Helper\Url\Laravel5( $view, app('url'), $fixed );
59
		$view->addHelper( 'url', $helper );
60
61
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $params );
62
		$view->addHelper( 'param', $helper );
63
64
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
65
		$view->addHelper( 'config', $helper );
66
67
		$sepDec = $config->get( 'client/html/common/format/seperatorDecimal', '.' );
68
		$sep1000 = $config->get( 'client/html/common/format/seperator1000', ' ' );
69
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, $sepDec, $sep1000 );
70
		$view->addHelper( 'number', $helper );
71
72
		$helper = new \Aimeos\MW\View\Helper\Request\Laravel5( $view, Request::instance() );
0 ignored issues
show
Bug introduced by
The method instance() does not exist on Illuminate\Support\Facades\Request. Did you maybe mean clearResolvedInstance()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
73
		$view->addHelper( 'request', $helper );
74
75
		$helper = new \Aimeos\MW\View\Helper\Response\Laravel5( $view );
76
		$view->addHelper( 'response', $helper );
77
78
		$helper = new \Aimeos\MW\View\Helper\Csrf\Standard( $view, '_token', csrf_token() );
79
		$view->addHelper( 'csrf', $helper );
80
81
		return $view;
82
	}
83
84
85
	/**
86
	 * Returns the routing parameters passed in the URL
87
	 *
88
	 * @return array Associative list of parameters with "site", "locale" and "currency" if available
89
	 */
90
	protected function getFixedParams()
91
	{
92
		$fixed = array();
93
94
		if( ( $value = Route::input( 'site' ) ) !== null ) {
95
			$fixed['site'] = $value;
96
		}
97
98
		if( ( $value = Route::input( 'locale' ) ) !== null ) {
99
			$fixed['locale'] = $value;
100
		}
101
102
		if( ( $value = Route::input( 'currency' ) ) !== null ) {
103
			$fixed['currency'] = $value;
104
		}
105
106
		return $fixed;
107
	}
108
}