|
18 | 18 | use Joomla\CMS\MVC\Model\ModelInterface; |
19 | 19 | use Joomla\CMS\Router\SiteRouterAwareInterface; |
20 | 20 | use Joomla\CMS\Router\SiteRouterAwareTrait; |
| 21 | +use Joomla\CMS\User\UserFactoryAwareInterface; |
| 22 | +use Joomla\CMS\User\UserFactoryAwareTrait; |
21 | 23 | use Joomla\Database\DatabaseAwareInterface; |
22 | 24 | use Joomla\Database\DatabaseAwareTrait; |
23 | 25 | use Joomla\Database\DatabaseInterface; |
|
35 | 37 | * |
36 | 38 | * @since 3.10.0 |
37 | 39 | */ |
38 | | -class MVCFactory implements MVCFactoryInterface, FormFactoryAwareInterface, SiteRouterAwareInterface |
| 40 | +class MVCFactory implements MVCFactoryInterface, FormFactoryAwareInterface, SiteRouterAwareInterface, UserFactoryAwareInterface |
39 | 41 | { |
40 | 42 | use FormFactoryAwareTrait; |
41 | 43 | use DispatcherAwareTrait; |
42 | 44 | use DatabaseAwareTrait; |
43 | 45 | use SiteRouterAwareTrait; |
44 | 46 | use CacheControllerFactoryAwareTrait; |
| 47 | + use UserFactoryAwareTrait; |
45 | 48 |
|
46 | 49 | /** |
47 | 50 | * The namespace to create the objects from. |
@@ -95,6 +98,7 @@ public function createController($name, $prefix, array $config, CMSApplicationIn |
95 | 98 | $this->setDispatcherOnObject($controller); |
96 | 99 | $this->setRouterOnObject($controller); |
97 | 100 | $this->setCacheControllerOnObject($controller); |
| 101 | + $this->setUserFactoryOnObject($controller); |
98 | 102 |
|
99 | 103 | return $controller; |
100 | 104 | } |
@@ -140,6 +144,7 @@ public function createModel($name, $prefix = '', array $config = []) |
140 | 144 | $this->setDispatcherOnObject($model); |
141 | 145 | $this->setRouterOnObject($model); |
142 | 146 | $this->setCacheControllerOnObject($model); |
| 147 | + $this->setUserFactoryOnObject($model); |
143 | 148 |
|
144 | 149 | if ($model instanceof DatabaseAwareInterface) { |
145 | 150 | try { |
@@ -196,6 +201,7 @@ public function createView($name, $prefix = '', $type = '', array $config = []) |
196 | 201 | $this->setDispatcherOnObject($view); |
197 | 202 | $this->setRouterOnObject($view); |
198 | 203 | $this->setCacheControllerOnObject($view); |
| 204 | + $this->setUserFactoryOnObject($view); |
199 | 205 |
|
200 | 206 | return $view; |
201 | 207 | } |
@@ -359,4 +365,26 @@ private function setCacheControllerOnObject($object): void |
359 | 365 | // Ignore it |
360 | 366 | } |
361 | 367 | } |
| 368 | + |
| 369 | + /** |
| 370 | + * Sets the internal user factory on the given object. |
| 371 | + * |
| 372 | + * @param object $object The object |
| 373 | + * |
| 374 | + * @return void |
| 375 | + * |
| 376 | + * @since __DEPLOY_VERSION__ |
| 377 | + */ |
| 378 | + private function setUserFactoryOnObject($object): void |
| 379 | + { |
| 380 | + if (!$object instanceof UserFactoryAwareInterface) { |
| 381 | + return; |
| 382 | + } |
| 383 | + |
| 384 | + try { |
| 385 | + $object->setUserFactory($this->getUserFactory()); |
| 386 | + } catch (\UnexpectedValueException $e) { |
| 387 | + // Ignore it |
| 388 | + } |
| 389 | + } |
362 | 390 | } |
0 commit comments