Completed
Push — master ( 110887...ff6c7f )
by Aimeos
10:07
created

lib/mshoplib/src/MAdmin/Job/Manager/Factory.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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