|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Render Ctype menu |
|
4
|
|
|
* |
|
5
|
|
|
* @author Tim Lochmüller |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace FRUIT\Ink\Rendering; |
|
9
|
|
|
|
|
10
|
|
|
use FRUIT\Ink\Configuration; |
|
11
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
|
12
|
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Render Ctype menu |
|
16
|
|
|
*/ |
|
17
|
|
|
class Menu extends AbstractRendering |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Render the given element |
|
22
|
|
|
* |
|
23
|
|
|
* @return array |
|
24
|
|
|
*/ |
|
25
|
|
|
public function renderInternal() |
|
26
|
|
|
{ |
|
27
|
|
|
$str = $this->contentObject->cObjGetSingle($this->configuration['menu'], $this->configuration['menu.']); |
|
28
|
|
|
$str = $this->breakBulletList($this->contentObject, trim(strip_tags(preg_replace('/<br\s*\/?>/i', chr(10), $this->parseBody($str))))); |
|
29
|
|
|
return $str; |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Breaks content lines into a bullet list |
|
34
|
|
|
* |
|
35
|
|
|
* @param ContentObjectRenderer $contentObject |
|
36
|
|
|
* @param string $str Content string to make into a bullet list |
|
37
|
|
|
* |
|
38
|
|
|
* @return string Processed value |
|
39
|
|
|
*/ |
|
40
|
|
|
public function breakBulletList($contentObject, $str) |
|
41
|
|
|
{ |
|
42
|
|
|
$type = $contentObject->data['layout']; |
|
43
|
|
|
$type = MathUtility::forceIntegerInRange($type, 0, 3); |
|
44
|
|
|
|
|
45
|
|
|
$tConf = $this->configuration['bulletlist.'][$type . '.']; |
|
46
|
|
|
|
|
47
|
|
|
$cParts = explode(chr(10), $str); |
|
48
|
|
|
$lines = array(); |
|
49
|
|
|
$c = 0; |
|
50
|
|
|
|
|
51
|
|
|
foreach ($cParts as $substrs) { |
|
52
|
|
|
if (!strlen($substrs)) { |
|
53
|
|
|
continue; |
|
54
|
|
|
} |
|
55
|
|
|
$c++; |
|
56
|
|
|
$bullet = $tConf['bullet'] ? $tConf['bullet'] : ' - '; |
|
57
|
|
|
$bLen = strlen($bullet); |
|
58
|
|
|
$bullet = substr(str_replace('#', $c, $bullet), 0, $bLen); |
|
59
|
|
|
$secondRow = substr($tConf['secondRow'] ? $tConf['secondRow'] : str_pad('', strlen($bullet), ' '), 0, $bLen); |
|
60
|
|
|
|
|
61
|
|
|
$lines[] = $bullet . $this->breakLines($substrs, chr(10) . $secondRow, Configuration::getPlainTextWith() - $bLen); |
|
62
|
|
|
|
|
63
|
|
|
$blanks = MathUtility::forceIntegerInRange($tConf['blanks'], 0, 1000); |
|
64
|
|
|
if ($blanks) { |
|
65
|
|
|
$lines[] = str_pad('', $blanks - 1, chr(10)); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
return implode(chr(10), $lines); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.