1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the bootstrap-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\BootstrapBundle\Twig\Extension\Grid; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Abstract grid Twig extension. |
18
|
|
|
* |
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
20
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Grid |
21
|
|
|
* @abstract |
22
|
|
|
*/ |
23
|
|
|
abstract class AbstractGridTwigExtension extends AbstractBootstrapTwigExtension { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Constructor. |
27
|
|
|
*/ |
28
|
|
|
protected function __construct() { |
29
|
|
|
parent::__construct(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Displays a Bootstrap grid. |
34
|
|
|
* |
35
|
|
|
* @param string $lg The large column size. |
36
|
|
|
* @param string $md The medium column size. |
37
|
|
|
* @param string $sm The small column size. |
38
|
|
|
* @param string $xs The extra-small column size. |
39
|
|
|
* @param string $recopy Recopy ? |
40
|
|
|
* @param string $prefix The column prefix. |
41
|
|
|
* @return string Returns the Bootstrap grid. |
42
|
|
|
*/ |
43
|
|
|
final protected function bootstrapGrid($lg, $md, $sm, $xs, $recopy, $prefix) { |
44
|
|
|
|
45
|
|
|
// Recopy. |
46
|
|
|
foreach ([&$lg, &$md, &$sm, &$xs] as &$current) { |
|
|
|
|
47
|
|
|
if (1 <= $current && $current <= 12) { |
48
|
|
|
$found = $current; |
49
|
|
|
} |
50
|
|
|
if (null === $current && true === $recopy && true === (isset($found))) { |
51
|
|
|
$current = $found; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// Initialize the columns. |
56
|
|
|
$columns = []; |
57
|
|
|
|
58
|
|
|
$columns[] = 1 <= $lg && $lg <= 12 ? "col-lg-" . $prefix . $lg : null; |
59
|
|
|
$columns[] = 1 <= $md && $md <= 12 ? "col-md-" . $prefix . $md : null; |
60
|
|
|
$columns[] = 1 <= $sm && $sm <= 12 ? "col-sm-" . $prefix . $sm : null; |
61
|
|
|
$columns[] = 1 <= $xs && $xs <= 12 ? "col-xs-" . $prefix . $xs : null; |
62
|
|
|
|
63
|
|
|
// Return the columns. |
64
|
|
|
return trim(implode(" ", $columns)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
Let?s assume that you have the following
foreach
statement:$itemValue
is assigned by reference. This is possible because the expression (in the example$array
) can be used as a reference target.However, if we were to replace
$array
with something different like the result of a function call as inthen assigning by reference is not possible anymore as there is no target that could be modified.
Available Fixes
1. Do not assign by reference
2. Assign to a local variable first
3. Return a reference