Skip to content

Commit

Permalink
Decouple Object Manager from TYPO3
Browse files Browse the repository at this point in the history
- Make the Object Manager a wrapper around TYPO3's Object Manager instead of a subclass
  • Loading branch information
cundd committed Nov 21, 2018
1 parent 926b94f commit fe3e106
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
33 changes: 29 additions & 4 deletions Classes/ObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
use Cundd\Rest\Exception\InvalidConfigurationException;
use Cundd\Rest\Handler\HandlerInterface;
use Cundd\Rest\Http\RestRequestInterface;
use TYPO3\CMS\Extbase\Object\ObjectManager as BaseObjectManager;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface as TYPO3ObjectManagerInterface;
use Psr\Container\ContainerInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager as TYPO3ObjectManager;

/**
* Specialized Object Manager
*
* @method mixed get($class)
* @method bool isRegistered($class)
*/
class ObjectManager extends BaseObjectManager implements TYPO3ObjectManagerInterface, ObjectManagerInterface, SingletonInterface
class ObjectManager implements ObjectManagerInterface, SingletonInterface
{
/**
* @var DataProviderInterface
Expand All @@ -49,6 +49,26 @@ class ObjectManager extends BaseObjectManager implements TYPO3ObjectManagerInter
*/
protected $accessController;

/**
* @var ContainerInterface|\TYPO3\CMS\Extbase\Object\ObjectManagerInterface
*/
protected $container;

/**
* Object Manager constructor
*
* @param ContainerInterface|\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $container
*/
public function __construct($container = null)
{
$this->container = $container ?: GeneralUtility::makeInstance(TYPO3ObjectManager::class);
}

public function get($class, ...$arguments)
{
return $this->container->get($class, ...$arguments);
}

/**
* Returns the Response Factory
*
Expand Down Expand Up @@ -302,4 +322,9 @@ private function getHandlerFromResourceConfiguration(ResourceType $resourceType)

return $this->get($handlerClass);
}

public function __call($name, $arguments)
{
return call_user_func_array([$this->container, $name], $arguments);
}
}
9 changes: 9 additions & 0 deletions Classes/ObjectManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
*/
interface ObjectManagerInterface
{
/**
* Return an instance of the given class
*
* @param string $class The class name of the object to return an instance of
* @param array $arguments
* @return object The object instance
*/
public function get($class, ...$arguments);

/**
* Returns the configuration provider
*
Expand Down

0 comments on commit fe3e106

Please sign in to comment.