dkd-kaehm /
ext-solr
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace ApacheSolrForTypo3\Solr\System\ContentObject; |
||||
| 4 | |||||
| 5 | /*************************************************************** |
||||
| 6 | * Copyright notice |
||||
| 7 | * |
||||
| 8 | * (c) 2010-2017 Timo Hund <[email protected] |
||||
| 9 | * All rights reserved |
||||
| 10 | * |
||||
| 11 | * This script is part of the TYPO3 project. The TYPO3 project is |
||||
| 12 | * free software; you can redistribute it and/or modify |
||||
| 13 | * it under the terms of the GNU General Public License as published by |
||||
| 14 | * the Free Software Foundation; either version 3 of the License, or |
||||
| 15 | * (at your option) any later version. |
||||
| 16 | * |
||||
| 17 | * The GNU General Public License can be found at |
||||
| 18 | * http://www.gnu.org/copyleft/gpl.html. |
||||
| 19 | * |
||||
| 20 | * This script is distributed in the hope that it will be useful, |
||||
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
| 23 | * GNU General Public License for more details. |
||||
| 24 | * |
||||
| 25 | * This copyright notice MUST APPEAR in all copies of the script! |
||||
| 26 | ***************************************************************/ |
||||
| 27 | |||||
| 28 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||||
| 29 | use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; |
||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * StdWrap Service that can be used to apply the ContentObjectRenderer stdWrap functionality on data. |
||||
| 33 | * |
||||
| 34 | * @author Timo Hund <[email protected]> |
||||
| 35 | */ |
||||
| 36 | class ContentObjectService |
||||
| 37 | { |
||||
| 38 | |||||
| 39 | /** |
||||
| 40 | * @var ContentObjectRenderer |
||||
| 41 | */ |
||||
| 42 | protected $contentObjectRenderer; |
||||
| 43 | |||||
| 44 | /** |
||||
| 45 | * StdWrapService constructor. |
||||
| 46 | * @param ContentObjectRenderer|null $contentObject |
||||
| 47 | */ |
||||
| 48 | 309 | public function __construct(ContentObjectRenderer $contentObject = null) |
|||
| 49 | { |
||||
| 50 | 309 | $this->contentObjectRenderer = $contentObject ?? GeneralUtility::makeInstance(ContentObjectRenderer::class); |
|||
| 51 | 309 | } |
|||
| 52 | |||||
| 53 | /** |
||||
| 54 | * This method use $name and $conf and passes it directly to cObjGetSingle. |
||||
| 55 | * |
||||
| 56 | * @param string $name |
||||
| 57 | * @param array $conf |
||||
| 58 | * @return string |
||||
| 59 | */ |
||||
| 60 | 4 | public function renderSingleContentObject($name = '', $conf = []) |
|||
| 61 | { |
||||
| 62 | 4 | return $this->contentObjectRenderer->cObjGetSingle($name, $conf); |
|||
| 63 | } |
||||
| 64 | |||||
| 65 | /** |
||||
| 66 | * Very often cObjGetSingle is used with 'field' as $name and 'field.' as $conf with this |
||||
| 67 | * method you can pass the array and the $key that is used to access $conant and $conf from $array. |
||||
| 68 | * |
||||
| 69 | * @param array $array |
||||
| 70 | * @param string $key |
||||
| 71 | * @return string |
||||
| 72 | */ |
||||
| 73 | 3 | public function renderSingleContentObjectByArrayAndKey($array = [], $key = '') |
|||
| 74 | { |
||||
| 75 | 3 | $name = isset($array[$key]) ? $array[$key] : []; |
|||
| 76 | 3 | $conf = isset($array[$key . '.']) ? $array[$key . '.'] : ''; |
|||
| 77 | |||||
| 78 | 3 | if (!is_array($conf)) { |
|||
| 79 | 2 | return $name; |
|||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
| 80 | } |
||||
| 81 | |||||
| 82 | 2 | return $this->renderSingleContentObject($name, $conf); |
|||
|
0 ignored issues
–
show
It seems like
$name can also be of type array; however, parameter $name of ApacheSolrForTypo3\Solr\...erSingleContentObject() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 83 | } |
||||
| 84 | } |
||||
| 85 |