Completed
Branch BUG-10626-dst-unit-test (8c5dd4)
by
unknown
138:48 queued 126:51
created

OpenCoffeeShop::firstBrew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace EventEspresso\core\services\container;
3
4
if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
	exit( 'No direct script access allowed' );
6
}
7
8
9
10
/**
11
 * Class OpenCoffeeShop
12
 * Initialize and configure the CoffeeSop DI container
13
 *
14
 * @package       Event Espresso
15
 * @author        Brent Christensen
16
 * @since         $VID:$
17
 */
18
class OpenCoffeeShop {
19
20
	/**
21
	 * @var CoffeeShop $CoffeeShop
22
	 */
23
	private $CoffeeShop;
24
25
	/**
26
	 * @var DependencyInjector $DependencyInjector
27
	 */
28
	private $DependencyInjector;
29
30
31
32
	/**
33
	 * OpenCoffeeShop constructor.
34
	 */
35
	public function __construct()
36
    {
37
		// instantiate the container
38
		$this->CoffeeShop = new CoffeeShop();
39
		// create a dependency injector class for resolving class constructor arguments
40
		$this->DependencyInjector = new DependencyInjector(
41
			$this->CoffeeShop,
42
			new \EEH_Array()
43
		);
44
		// and some coffeemakers, one for creating new instances
45
		$this->CoffeeShop->addCoffeeMaker(
46
			new NewCoffeeMaker( $this->CoffeeShop, $this->DependencyInjector ),
47
			CoffeeMaker::BREW_NEW
48
		);
49
		// one for shared services
50
		$this->CoffeeShop->addCoffeeMaker(
51
			new SharedCoffeeMaker( $this->CoffeeShop, $this->DependencyInjector ),
52
			CoffeeMaker::BREW_SHARED
53
		);
54
		// and one for classes that only get loaded
55
		$this->CoffeeShop->addCoffeeMaker(
56
			new LoadOnlyCoffeeMaker( $this->CoffeeShop, $this->DependencyInjector ),
57
			CoffeeMaker::BREW_LOAD_ONLY
58
		);
59
		// add default recipe, which should handle loading for most PSR-4 compatible classes
60
		// as long as they are not type hinting for interfaces
61
		$this->CoffeeShop->addRecipe(
62
			new Recipe(
63
				Recipe::DEFAULT_ID
64
			)
65
		);
66
	}
67
68
69
70
	/**
71
	 * @return \EventEspresso\core\services\container\CoffeeShop
72
	 */
73
	public function CoffeeShop() {
74
		return $this->CoffeeShop;
75
	}
76
77
78
79
	public function addRecipes() {
80
81
		// PSR-4 compatible class with aliases
82
		$this->CoffeeShop->addRecipe(
83
			new Recipe(
84
				'CommandHandlerManager',
85
				'EventEspresso\core\services\commands\CommandHandlerManager',
86
                array(
87
                    'CommandHandlerManagerInterface',
88
                    'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
89
                ),
90
                array(),
91
				CoffeeMaker::BREW_SHARED
92
			)
93
		);
94
		// PSR-4 compatible class with aliases, which dependency on CommandHandlerManager
95
		$this->CoffeeShop->addRecipe(
96
			new Recipe(
97
				'CommandBus',
98
				'EventEspresso\core\services\commands\CommandBus',
99
                array(
100
                    'CommandBusInterface',
101
                    'EventEspresso\core\services\commands\CommandBusInterface',
102
                ),
103
                array(),
104
				CoffeeMaker::BREW_SHARED
105
			)
106
		);
107
		// LEGACY classes that are NOT compatible with PSR-4 autoloading, and so must specify a filepath
108
		// add a wildcard recipe for loading legacy core interfaces
109
		$this->CoffeeShop->addRecipe(
110
			new Recipe(
111
				'EEI_*',
112
				'',
113
                array(),
114
                array(),
115
				CoffeeMaker::BREW_LOAD_ONLY,
116
                array(
117
                    EE_INTERFACES . '*.php',
118
                    EE_INTERFACES . '*.interfaces.php',
119
                )
120
			)
121
		);
122
		// add a wildcard recipe for loading models
123
		$this->CoffeeShop->addRecipe(
124
			new Recipe(
125
				'EEM_*',
126
                '',
127
                array(),
128
                array(),
129
				CoffeeMaker::BREW_SHARED,
130
				EE_MODELS . '*.model.php'
0 ignored issues
show
Documentation introduced by
EE_MODELS . '*.model.php' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
131
			)
132
		);
133
		// add a wildcard recipe for loading core classes
134
		$this->CoffeeShop->addRecipe(
135
			new Recipe(
136
				'EE_*',
137
                '',
138
                array(),
139
                array(),
140
                CoffeeMaker::BREW_SHARED,
141
				array(
142
					EE_CORE . '*.core.php',
143
					EE_ADMIN . '*.core.php',
144
					EE_CPTS . '*.core.php',
145
					EE_CORE . 'data_migration_scripts' . DS . '*.core.php',
146
					EE_CORE . 'request_stack' . DS . '*.core.php',
147
					EE_CORE . 'middleware' . DS . '*.core.php',
148
				)
149
			)
150
		);
151
		// load admin page parent class
152
		$this->CoffeeShop->addRecipe(
153
			new Recipe(
154
				'EE_Admin_Page*',
155
                '',
156
                array(),
157
                array(),
158
                CoffeeMaker::BREW_LOAD_ONLY,
159
				array( EE_ADMIN . '*.core.php' )
160
			)
161
		);
162
		// add a wildcard recipe for loading core classes
163
		// $this->CoffeeShop->addRecipe(
164
		// 	new Recipe(
165
		// 		'*_Admin_Page',
166
        //      '',
167
        //      array(),
168
        // 		array(),
169
        // 		CoffeeMaker::BREW_SHARED,
170
		// 		array(
171
		// 			EE_ADMIN_PAGES . 'transactions' . DS . '*.core.php',
172
		// 		)
173
		// 	)
174
		// );
175
	}
176
177
178
179
180
}
181
// End of file OpenCoffeeShop.php
182
// Location: /OpenCoffeeShop.php
183