Skip to content

Commit fe3e106

Browse files
committed
Decouple Object Manager from TYPO3
- Make the Object Manager a wrapper around TYPO3's Object Manager instead of a subclass
1 parent 926b94f commit fe3e106

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

Classes/ObjectManager.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
use Cundd\Rest\Exception\InvalidConfigurationException;
1717
use Cundd\Rest\Handler\HandlerInterface;
1818
use Cundd\Rest\Http\RestRequestInterface;
19-
use TYPO3\CMS\Extbase\Object\ObjectManager as BaseObjectManager;
20-
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface as TYPO3ObjectManagerInterface;
19+
use Psr\Container\ContainerInterface;
20+
use TYPO3\CMS\Core\Utility\GeneralUtility;
21+
use TYPO3\CMS\Extbase\Object\ObjectManager as TYPO3ObjectManager;
2122

2223
/**
2324
* Specialized Object Manager
2425
*
25-
* @method mixed get($class)
2626
* @method bool isRegistered($class)
2727
*/
28-
class ObjectManager extends BaseObjectManager implements TYPO3ObjectManagerInterface, ObjectManagerInterface, SingletonInterface
28+
class ObjectManager implements ObjectManagerInterface, SingletonInterface
2929
{
3030
/**
3131
* @var DataProviderInterface
@@ -49,6 +49,26 @@ class ObjectManager extends BaseObjectManager implements TYPO3ObjectManagerInter
4949
*/
5050
protected $accessController;
5151

52+
/**
53+
* @var ContainerInterface|\TYPO3\CMS\Extbase\Object\ObjectManagerInterface
54+
*/
55+
protected $container;
56+
57+
/**
58+
* Object Manager constructor
59+
*
60+
* @param ContainerInterface|\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $container
61+
*/
62+
public function __construct($container = null)
63+
{
64+
$this->container = $container ?: GeneralUtility::makeInstance(TYPO3ObjectManager::class);
65+
}
66+
67+
public function get($class, ...$arguments)
68+
{
69+
return $this->container->get($class, ...$arguments);
70+
}
71+
5272
/**
5373
* Returns the Response Factory
5474
*
@@ -302,4 +322,9 @@ private function getHandlerFromResourceConfiguration(ResourceType $resourceType)
302322

303323
return $this->get($handlerClass);
304324
}
325+
326+
public function __call($name, $arguments)
327+
{
328+
return call_user_func_array([$this->container, $name], $arguments);
329+
}
305330
}

Classes/ObjectManagerInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
*/
1010
interface ObjectManagerInterface
1111
{
12+
/**
13+
* Return an instance of the given class
14+
*
15+
* @param string $class The class name of the object to return an instance of
16+
* @param array $arguments
17+
* @return object The object instance
18+
*/
19+
public function get($class, ...$arguments);
20+
1221
/**
1322
* Returns the configuration provider
1423
*

0 commit comments

Comments
 (0)