‪TYPO3CMS  ‪main
ContentObjectFactory.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Container\ContainerInterface;
21 use Psr\Http\Message\ServerRequestInterface;
23 
29 {
30  public function ‪__construct(private ContainerInterface $contentObjectLocator) {}
31 
32  public function ‪getContentObject(string $name, ServerRequestInterface $request, ‪ContentObjectRenderer $contentObjectRenderer): ?‪AbstractContentObject
33  {
34  if (!$this->contentObjectLocator->has($name)) {
35  return null;
36  }
37 
38  $contentObject = $this->contentObjectLocator->get($name);
39  if (!($contentObject instanceof ‪AbstractContentObject)) {
40  throw new ‪ContentRenderingException(sprintf('Registered content object class name "%s" must be an instance of AbstractContentObject, but is not!', get_class($contentObject)), 1422564295);
41  }
42 
43  $contentObject->setRequest($request);
44  $contentObject->setContentObjectRenderer($contentObjectRenderer);
45 
46  return $contentObject;
47  }
48 }
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectFactory\__construct
‪__construct(private ContainerInterface $contentObjectLocator)
Definition: ContentObjectFactory.php:30
‪TYPO3\CMS\Frontend\ContentObject
Definition: AbstractContentObject.php:18
‪TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException
Definition: ContentRenderingException.php:24
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject
Definition: AbstractContentObject.php:31
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectFactory
Definition: ContentObjectFactory.php:29
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectFactory\getContentObject
‪getContentObject(string $name, ServerRequestInterface $request, ContentObjectRenderer $contentObjectRenderer)
Definition: ContentObjectFactory.php:32