Completed
Pull Request — master (#878)
by Timo
33:19 queued 29:07
created

ContentObjectService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 44
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A renderSingleContentObject() 0 4 1
A renderSingleContentObjectByArrayAndKey() 0 6 3
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 2 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 199
    public function __construct(ContentObjectRenderer $contentObject = null)
49
    {
50 199
        $this->contentObjectRenderer = is_null($contentObject) ? GeneralUtility::makeInstance(ContentObjectRenderer::class) : $contentObject;
51 199
    }
52
53
    /**
54
     * This method use $content and $conf and passes it directly to stdWrap.
55
     *
56
     * @param string $content
57
     * @param array $conf
58
     * @return string
59
     */
60 3
    public function renderSingleContentObject($content = '', $conf = [])
61
    {
62 3
        return $this->contentObjectRenderer->cObjGetSingle($content, $conf);
63
    }
64
65
    /**
66
     * Very object stdWrap is used with 'field' as $content 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 1
    public function renderSingleContentObjectByArrayAndKey($array = [], $key = '')
74
    {
75 1
        $content = isset($array[$key]) ? $array[$key] : [];
76 1
        $conf = isset($array[$key . '.']) ? $array[$key . '.'] : '';
77 1
        return $this->renderSingleContentObject($content, $conf);
78
    }
79
}
80