Passed
Push — master ( 365418...ec127b )
by Aimeos
02:19
created

Factory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 134
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 123 3
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Site;
12
13
14
/**
15
 * Site frontend controller factory.
16
 *
17
 * @package Controller
18
 * @subpackage Frontend
19
 */
20
class Factory
21
	extends \Aimeos\Controller\Frontend\Common\Factory\Base
22
	implements \Aimeos\Controller\Frontend\Common\Factory\Iface
23
{
24
	/**
25
	 * Creates a new site controller object.
26
	 *
27
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context instance with necessary objects
28
	 * @param string|null $name Name of the controller implementaton (default: "Standard")
29
	 * @return \Aimeos\Controller\Frontend\Site\Iface Controller object
30
	 */
31
	public static function create( \Aimeos\MShop\Context\Item\Iface $context, string $name = null ) : \Aimeos\Controller\Frontend\Iface
32
	{
33
		/** controller/frontend/site/name
34
		 * Class name of the used site frontend controller implementation
35
		 *
36
		 * Each default frontend controller can be replace by an alternative imlementation.
37
		 * To use this implementation, you have to set the last part of the class
38
		 * name as configuration value so the controller factory knows which class it
39
		 * has to instantiate.
40
		 *
41
		 * For example, if the name of the default class is
42
		 *
43
		 *  \Aimeos\Controller\Frontend\Site\Standard
44
		 *
45
		 * and you want to replace it with your own version named
46
		 *
47
		 *  \Aimeos\Controller\Frontend\Site\Mysite
48
		 *
49
		 * then you have to set the this configuration option:
50
		 *
51
		 *  controller/jobs/frontend/site/name = Mysite
52
		 *
53
		 * The value is the last part of your own class name and it's case sensitive,
54
		 * so take care that the configuration value is exactly named like the last
55
		 * part of the class name.
56
		 *
57
		 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
58
		 * characters are possible! You should always start the last part of the class
59
		 * name with an upper case character and continue only with lower case characters
60
		 * or numbers. Avoid chamel case names like "MySite"!
61
		 *
62
		 * @param string Last part of the class name
63
		 * @since 2021.04
64
		 * @category Developer
65
		 */
66
		if( $name === null ) {
67
			$name = $context->getConfig()->get( 'controller/frontend/site/name', 'Standard' );
68
		}
69
70
		$iface = '\\Aimeos\\Controller\\Frontend\\Site\\Iface';
71
		$classname = '\\Aimeos\\Controller\\Frontend\\Site\\' . $name;
72
73
		if( ctype_alnum( $name ) === false ) {
74
			throw new \Aimeos\Controller\Frontend\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) );
75
		}
76
77
		$manager = self::createController( $context, $classname, $iface );
78
79
		/** controller/frontend/site/decorators/excludes
80
		 * Excludes decorators added by the "common" option from the site frontend controllers
81
		 *
82
		 * Decorators extend the functionality of a class by adding new aspects
83
		 * (e.g. log what is currently done), executing the methods of the underlying
84
		 * class only in certain conditions (e.g. only for logged in users) or
85
		 * modify what is returned to the caller.
86
		 *
87
		 * This option allows you to remove a decorator added via
88
		 * "controller/frontend/common/decorators/default" before they are wrapped
89
		 * around the frontend controller.
90
		 *
91
		 *  controller/frontend/site/decorators/excludes = array( 'decorator1' )
92
		 *
93
		 * This would remove the decorator named "decorator1" from the list of
94
		 * common decorators ("\Aimeos\Controller\Frontend\Common\Decorator\*") added via
95
		 * "controller/frontend/common/decorators/default" for the site frontend controller.
96
		 *
97
		 * @param array List of decorator names
98
		 * @since 2021.04
99
		 * @category Developers
100
		 * @see controller/frontend/common/decorators/default
101
		 * @see controller/frontend/site/decorators/global
102
		 * @see controller/frontend/site/decorators/local
103
		 */
104
105
		/** controller/frontend/site/decorators/global
106
		 * Adds a list of globally available decorators only to the site frontend controllers
107
		 *
108
		 * Decorators extend the functionality of a class by adding new aspects
109
		 * (e.g. log what is currently done), executing the methods of the underlying
110
		 * class only in certain conditions (e.g. only for logged in users) or
111
		 * modify what is returned to the caller.
112
		 *
113
		 * This option allows you to wrap global decorators
114
		 * ("\Aimeos\Controller\Frontend\Common\Decorator\*") around the frontend controller.
115
		 *
116
		 *  controller/frontend/site/decorators/global = array( 'decorator1' )
117
		 *
118
		 * This would add the decorator named "decorator1" defined by
119
		 * "\Aimeos\Controller\Frontend\Common\Decorator\Decorator1" only to the frontend controller.
120
		 *
121
		 * @param array List of decorator names
122
		 * @since 2021.04
123
		 * @category Developers
124
		 * @see controller/frontend/common/decorators/default
125
		 * @see controller/frontend/site/decorators/excludes
126
		 * @see controller/frontend/site/decorators/local
127
		 */
128
129
		/** controller/frontend/site/decorators/local
130
		 * Adds a list of local decorators only to the site frontend controllers
131
		 *
132
		 * Decorators extend the functionality of a class by adding new aspects
133
		 * (e.g. log what is currently done), executing the methods of the underlying
134
		 * class only in certain conditions (e.g. only for logged in users) or
135
		 * modify what is returned to the caller.
136
		 *
137
		 * This option allows you to wrap local decorators
138
		 * ("\Aimeos\Controller\Frontend\Site\Decorator\*") around the frontend controller.
139
		 *
140
		 *  controller/frontend/site/decorators/local = array( 'decorator2' )
141
		 *
142
		 * This would add the decorator named "decorator2" defined by
143
		 * "\Aimeos\Controller\Frontend\Site\Decorator\Decorator2" only to the frontend
144
		 * controller.
145
		 *
146
		 * @param array List of decorator names
147
		 * @since 2021.04
148
		 * @category Developers
149
		 * @see controller/frontend/common/decorators/default
150
		 * @see controller/frontend/site/decorators/excludes
151
		 * @see controller/frontend/site/decorators/global
152
		 */
153
		return self::addControllerDecorators( $context, $manager, 'site' );
154
	}
155
156
}
157