Completed
Push — master ( c74a72...239795 )
by Olivier
04:51
created

helpers.php ➔ get_patron()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 2
eloc 5
c 2
b 0
f 2
nc 2
nop 0
dl 0
loc 11
rs 9.4285
1
<?php
2
3
/*
4
 * This file is part of the Patron package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
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 Patron;
13
14
/**
15
 * @return MarkupCollection
16
 */
17
function get_markups()
18
{
19
	static $markups;
20
21
	if (!$markups)
22
	{
23
		$markups = new MarkupCollection(require __DIR__ . '/../res' . DIRECTORY_SEPARATOR . 'markups.php');
24
25
		new MarkupCollection\AlterEvent($markups);
26
	}
27
28
	return $markups;
29
}
30
31
/**
32
 * @return FunctionCollection
33
 */
34
function get_functions()
35
{
36
	static $functions;
37
38
	if (!$functions)
39
	{
40
		$functions = new FunctionCollection(require __DIR__ . '/../res' . DIRECTORY_SEPARATOR . 'functions.php');
41
42
		new FunctionCollection\AlterEvent($functions);
43
	}
44
45
	return $functions;
46
}
47
48
/**
49
 * @return Engine
50
 */
51
function get_patron()
52
{
53
	static $patron;
54
55
	if (!$patron)
56
	{
57
		$patron = new Engine(get_markups(), get_functions());
58
	}
59
60
	return clone $patron;
61
}
62
63
/*
64
 *
65
 */
66
67
function tr($str, $from, $to)
68
{
69
	return strtr($str, $from, $to);
70
}
71
72
function by_columns(array $array, $columns)
73
{
74
	$values_by_columns = ceil(count($array) / $columns);
75
76
	$i = 0;
77
	$by_columns = [];
78
79
	foreach ($array as $value)
80
	{
81
		$by_columns[$i++ % $values_by_columns][] = $value;
82
	}
83
84
	return $by_columns;
85
}
86