1 | <?php |
||
32 | class CoreLoader implements LoaderDecoratorInterface |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * @var EE_Registry|CoffeeShop $generator |
||
37 | */ |
||
38 | private $generator; |
||
39 | |||
40 | |||
41 | |||
42 | /** |
||
43 | * CoreLoader constructor. |
||
44 | * |
||
45 | * @param EE_Registry|CoffeeShop $generator |
||
46 | * @throws InvalidArgumentException |
||
47 | */ |
||
48 | public function __construct($generator) |
||
60 | |||
61 | |||
62 | |||
63 | /** |
||
64 | * Calls the appropriate loading method from the installed generator; |
||
65 | * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method |
||
66 | * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(), |
||
67 | * but NOT to the class being instantiated. |
||
68 | * This is done by adding the parameters to the $arguments array as follows: |
||
69 | * array( |
||
70 | * 'EE_Registry::create(from_db)' => true, // boolean value, default = false |
||
71 | * 'EE_Registry::create(load_only)' => true, // boolean value, default = false |
||
72 | * 'EE_Registry::create(addon)' => true, // boolean value, default = false |
||
73 | * ) |
||
74 | * |
||
75 | * @param string $fqcn |
||
76 | * @param array $arguments |
||
77 | * @param bool $shared |
||
78 | * @return mixed |
||
79 | * @throws OutOfBoundsException |
||
80 | * @throws ServiceExistsException |
||
81 | * @throws InstantiationException |
||
82 | * @throws InvalidIdentifierException |
||
83 | * @throws InvalidDataTypeException |
||
84 | * @throws InvalidClassException |
||
85 | * @throws EE_Error |
||
86 | * @throws ServiceNotFoundException |
||
87 | * @throws ReflectionException |
||
88 | */ |
||
89 | public function load($fqcn, $arguments = array(), $shared = true) |
||
90 | { |
||
91 | $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN); |
||
92 | if($this->generator instanceof EE_Registry) { |
||
93 | // check if additional EE_Registry::create() arguments have been passed |
||
94 | // from_db |
||
95 | $from_db = isset($arguments['EE_Registry::create(from_db)']) |
||
96 | ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN) |
||
97 | : false; |
||
98 | // load_only |
||
99 | $load_only = isset($arguments['EE_Registry::create(load_only)']) |
||
100 | ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN) |
||
101 | : false; |
||
102 | // addon |
||
103 | $addon = isset($arguments['EE_Registry::create(addon)']) |
||
104 | ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN) |
||
105 | : false; |
||
106 | unset( |
||
107 | $arguments['EE_Registry::create(from_db)'], |
||
108 | $arguments['EE_Registry::create(load_only)'], |
||
109 | $arguments['EE_Registry::create(addon)'] |
||
110 | ); |
||
111 | // addons need to be cached on EE_Registry |
||
112 | $shared = $addon ? true : $shared; |
||
113 | return $this->generator->create( |
||
114 | $fqcn, |
||
115 | $arguments, |
||
116 | $shared, |
||
117 | $from_db, |
||
118 | $load_only, |
||
119 | $addon |
||
120 | ); |
||
121 | } |
||
122 | return $this->generator->brew( |
||
123 | $fqcn, |
||
124 | $arguments, |
||
125 | $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
||
126 | ); |
||
127 | |||
128 | } |
||
129 | |||
130 | |||
131 | |||
132 | /** |
||
133 | * calls reset() on generator if method exists |
||
134 | * |
||
135 | * @throws EE_Error |
||
136 | * @throws ReflectionException |
||
137 | */ |
||
138 | public function reset() |
||
144 | |||
145 | } |
||
146 | // End of file CoreLoader.php |
||
148 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: