@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | // $options : https://www.php.net/manual/fr/session.configuration.php |
12 | 12 | public function __construct($options) |
13 | 13 | { |
14 | - if(isset($options['session_name'])) |
|
14 | + if (isset($options['session_name'])) |
|
15 | 15 | { |
16 | 16 | session_name($options['session_name']); |
17 | 17 | unset($options['session_name']); |
@@ -32,28 +32,28 @@ discard block |
||
32 | 32 | return isset($_SESSION[$this->index_filter][$filter_name]) && strlen(''.$_SESSION[$this->index_filter][$filter_name]) > 0; |
33 | 33 | } |
34 | 34 | |
35 | - public function filters($filter_name=null, $value=null) |
|
35 | + public function filters($filter_name = null, $value = null) |
|
36 | 36 | { |
37 | - if(is_null($filter_name)) |
|
37 | + if (is_null($filter_name)) |
|
38 | 38 | return $_SESSION[$this->index_filter]; |
39 | 39 | |
40 | - if(!is_null($value)) |
|
40 | + if (!is_null($value)) |
|
41 | 41 | $_SESSION[$this->index_filter][$filter_name] = $value; |
42 | 42 | |
43 | 43 | return $_SESSION[$this->index_filter][$filter_name] ?? null; |
44 | 44 | } |
45 | 45 | |
46 | - public function reset_filters($filter_name=null) |
|
46 | + public function reset_filters($filter_name = null) |
|
47 | 47 | { |
48 | - if(is_null($filter_name)) |
|
49 | - $_SESSION[$this->index_filter]=[]; |
|
48 | + if (is_null($filter_name)) |
|
49 | + $_SESSION[$this->index_filter] = []; |
|
50 | 50 | else |
51 | 51 | unset($_SESSION[$this->index_filter][$filter_name]); |
52 | 52 | } |
53 | 53 | |
54 | 54 | public function operator_id($setter = null) |
55 | 55 | { |
56 | - if(!is_null($setter)) |
|
56 | + if (!is_null($setter)) |
|
57 | 57 | $_SESSION[$this->index_operator] = ['id' => $setter, 'set_on' => time()]; |
58 | 58 | |
59 | 59 | return $_SESSION[$this->index_operator]['id'] ?? null; |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | public function destroy() : bool |
69 | 69 | { |
70 | 70 | |
71 | - if(ini_get("session.use_cookies")) |
|
71 | + if (ini_get("session.use_cookies")) |
|
72 | 72 | { |
73 | 73 | $params = session_get_cookie_params(); |
74 | - setcookie(session_name(), '', time() - 42000, |
|
74 | + setcookie(session_name(), '', time()-42000, |
|
75 | 75 | $params["path"], $params["domain"], |
76 | 76 | $params["secure"], $params["httponly"] |
77 | 77 | ); |
@@ -34,27 +34,31 @@ |
||
34 | 34 | |
35 | 35 | public function filters($filter_name=null, $value=null) |
36 | 36 | { |
37 | - if(is_null($filter_name)) |
|
38 | - return $_SESSION[$this->index_filter]; |
|
37 | + if(is_null($filter_name)) { |
|
38 | + return $_SESSION[$this->index_filter]; |
|
39 | + } |
|
39 | 40 | |
40 | - if(!is_null($value)) |
|
41 | - $_SESSION[$this->index_filter][$filter_name] = $value; |
|
41 | + if(!is_null($value)) { |
|
42 | + $_SESSION[$this->index_filter][$filter_name] = $value; |
|
43 | + } |
|
42 | 44 | |
43 | 45 | return $_SESSION[$this->index_filter][$filter_name] ?? null; |
44 | 46 | } |
45 | 47 | |
46 | 48 | public function reset_filters($filter_name=null) |
47 | 49 | { |
48 | - if(is_null($filter_name)) |
|
49 | - $_SESSION[$this->index_filter]=[]; |
|
50 | - else |
|
51 | - unset($_SESSION[$this->index_filter][$filter_name]); |
|
50 | + if(is_null($filter_name)) { |
|
51 | + $_SESSION[$this->index_filter]=[]; |
|
52 | + } else { |
|
53 | + unset($_SESSION[$this->index_filter][$filter_name]); |
|
54 | + } |
|
52 | 55 | } |
53 | 56 | |
54 | 57 | public function operator_id($setter = null) |
55 | 58 | { |
56 | - if(!is_null($setter)) |
|
57 | - $_SESSION[$this->index_operator] = ['id' => $setter, 'set_on' => time()]; |
|
59 | + if(!is_null($setter)) { |
|
60 | + $_SESSION[$this->index_operator] = ['id' => $setter, 'set_on' => time()]; |
|
61 | + } |
|
58 | 62 | |
59 | 63 | return $_SESSION[$this->index_operator]['id'] ?? null; |
60 | 64 | } |
@@ -8,17 +8,17 @@ discard block |
||
8 | 8 | |
9 | 9 | public function permission_names() |
10 | 10 | { |
11 | - if(property_exists($this, 'permission_names')) |
|
11 | + if (property_exists($this, 'permission_names')) |
|
12 | 12 | { |
13 | 13 | return explode(',', $this->permission_names); |
14 | 14 | } |
15 | - elseif(property_exists($this, 'permission_ids')) |
|
15 | + elseif (property_exists($this, 'permission_ids')) |
|
16 | 16 | { |
17 | 17 | $ids = explode(',', $this->permission_ids); |
18 | 18 | $ret = []; |
19 | 19 | $permissions = Permission::get_many_by_AIPK($ids); |
20 | - foreach($permissions as $id => $p) |
|
21 | - $ret[]="$p"; |
|
20 | + foreach ($permissions as $id => $p) |
|
21 | + $ret[] = "$p"; |
|
22 | 22 | return $ret; |
23 | 23 | } |
24 | 24 | |
@@ -31,16 +31,16 @@ discard block |
||
31 | 31 | public function permissions() |
32 | 32 | { |
33 | 33 | |
34 | - if(!is_null($this->permissions)) |
|
34 | + if (!is_null($this->permissions)) |
|
35 | 35 | return $this->permissions; |
36 | 36 | $permission_unique_keys = null; |
37 | - if(property_exists($this, 'permission_names')) |
|
37 | + if (property_exists($this, 'permission_names')) |
|
38 | 38 | { |
39 | 39 | $permission_unique_keys = explode(',', $this->permission_names); |
40 | 40 | // vd(Permission::table()->select()); |
41 | 41 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_string_in('name', $permission_unique_keys)); |
42 | 42 | } |
43 | - elseif(property_exists($this, 'permission_ids')) |
|
43 | + elseif (property_exists($this, 'permission_ids')) |
|
44 | 44 | { |
45 | 45 | $permission_unique_keys = explode(',', $this->permission_ids); |
46 | 46 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_numeric_in('id', $permission_unique_keys)); |
@@ -56,40 +56,40 @@ discard block |
||
56 | 56 | public function has_permission($p) : bool |
57 | 57 | { |
58 | 58 | // new instances or inactive operators, none shall pass |
59 | - if($this->is_new() === true || $this->is_active() === false) |
|
59 | + if ($this->is_new() === true || $this->is_active() === false) |
|
60 | 60 | return false; |
61 | 61 | |
62 | 62 | $permission_name = $permission_id = null; |
63 | - if(is_subclass_of($p, '\HexMakina\kadro\Auth\Permission')) |
|
63 | + if (is_subclass_of($p, '\HexMakina\kadro\Auth\Permission')) |
|
64 | 64 | { |
65 | 65 | $permission_name = $p->get('name'); |
66 | 66 | $permission_id = $p->get_id(); |
67 | 67 | } |
68 | - elseif(preg_match('/[0-9]+/', $p)) |
|
68 | + elseif (preg_match('/[0-9]+/', $p)) |
|
69 | 69 | $permission_id = $p; |
70 | 70 | else |
71 | 71 | $permission_name = $p; |
72 | 72 | |
73 | 73 | |
74 | - if(!is_null($this->get('permission_names')) && !is_null($permission_name)) |
|
74 | + if (!is_null($this->get('permission_names')) && !is_null($permission_name)) |
|
75 | 75 | { |
76 | 76 | return strpos($this->get('permission_names'), $permission_name) !== false; |
77 | 77 | } |
78 | - elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
78 | + elseif (!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
79 | 79 | { |
80 | 80 | return strpos($this->get('permission_ids'), $permission_id) !== false; |
81 | 81 | } |
82 | - elseif(!is_null($permission_name)) |
|
82 | + elseif (!is_null($permission_name)) |
|
83 | 83 | { |
84 | - if(method_exists($this, $permission_name) && $this->$permission_name() == true) |
|
84 | + if (method_exists($this, $permission_name) && $this->$permission_name() == true) |
|
85 | 85 | { |
86 | 86 | return true; |
87 | 87 | } |
88 | - elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
88 | + elseif (property_exists($this, $permission_name) && $this->$permission_name == true) |
|
89 | 89 | { |
90 | 90 | return true; |
91 | 91 | } |
92 | - elseif(ACL::match($this, $permission_name) === true) |
|
92 | + elseif (ACL::match($this, $permission_name) === true) |
|
93 | 93 | { |
94 | 94 | return true; |
95 | 95 | } |
@@ -11,18 +11,16 @@ discard block |
||
11 | 11 | if(property_exists($this, 'permission_names')) |
12 | 12 | { |
13 | 13 | return explode(',', $this->permission_names); |
14 | - } |
|
15 | - elseif(property_exists($this, 'permission_ids')) |
|
14 | + } elseif(property_exists($this, 'permission_ids')) |
|
16 | 15 | { |
17 | 16 | $ids = explode(',', $this->permission_ids); |
18 | 17 | $ret = []; |
19 | 18 | $permissions = Permission::get_many_by_AIPK($ids); |
20 | - foreach($permissions as $id => $p) |
|
21 | - $ret[]="$p"; |
|
19 | + foreach($permissions as $id => $p) { |
|
20 | + $ret[]="$p"; |
|
21 | + } |
|
22 | 22 | return $ret; |
23 | - } |
|
24 | - |
|
25 | - else |
|
23 | + } else |
|
26 | 24 | { |
27 | 25 | return ACL::permissions_names_for($this); |
28 | 26 | } |
@@ -31,21 +29,20 @@ discard block |
||
31 | 29 | public function permissions() |
32 | 30 | { |
33 | 31 | |
34 | - if(!is_null($this->permissions)) |
|
35 | - return $this->permissions; |
|
32 | + if(!is_null($this->permissions)) { |
|
33 | + return $this->permissions; |
|
34 | + } |
|
36 | 35 | $permission_unique_keys = null; |
37 | 36 | if(property_exists($this, 'permission_names')) |
38 | 37 | { |
39 | 38 | $permission_unique_keys = explode(',', $this->permission_names); |
40 | 39 | // vd(Permission::table()->select()); |
41 | 40 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_string_in('name', $permission_unique_keys)); |
42 | - } |
|
43 | - elseif(property_exists($this, 'permission_ids')) |
|
41 | + } elseif(property_exists($this, 'permission_ids')) |
|
44 | 42 | { |
45 | 43 | $permission_unique_keys = explode(',', $this->permission_ids); |
46 | 44 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_numeric_in('id', $permission_unique_keys)); |
47 | - } |
|
48 | - else |
|
45 | + } else |
|
49 | 46 | { |
50 | 47 | $this->permissions = ACL::permissions_for($this); |
51 | 48 | } |
@@ -56,39 +53,36 @@ discard block |
||
56 | 53 | public function has_permission($p) : bool |
57 | 54 | { |
58 | 55 | // new instances or inactive operators, none shall pass |
59 | - if($this->is_new() === true || $this->is_active() === false) |
|
60 | - return false; |
|
56 | + if($this->is_new() === true || $this->is_active() === false) { |
|
57 | + return false; |
|
58 | + } |
|
61 | 59 | |
62 | 60 | $permission_name = $permission_id = null; |
63 | 61 | if(is_subclass_of($p, '\HexMakina\kadro\Auth\Permission')) |
64 | 62 | { |
65 | 63 | $permission_name = $p->get('name'); |
66 | 64 | $permission_id = $p->get_id(); |
65 | + } elseif(preg_match('/[0-9]+/', $p)) { |
|
66 | + $permission_id = $p; |
|
67 | + } else { |
|
68 | + $permission_name = $p; |
|
67 | 69 | } |
68 | - elseif(preg_match('/[0-9]+/', $p)) |
|
69 | - $permission_id = $p; |
|
70 | - else |
|
71 | - $permission_name = $p; |
|
72 | 70 | |
73 | 71 | if(!is_null($this->get('permission_names')) && !is_null($permission_name)) |
74 | 72 | { |
75 | 73 | return strpos($this->get('permission_names'), $permission_name) !== false; |
76 | - } |
|
77 | - elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
74 | + } elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
78 | 75 | { |
79 | 76 | return strpos($this->get('permission_ids'), $permission_id) !== false; |
80 | - } |
|
81 | - elseif(!is_null($permission_name)) |
|
77 | + } elseif(!is_null($permission_name)) |
|
82 | 78 | { |
83 | 79 | if(method_exists($this, $permission_name) && $this->$permission_name() == true) |
84 | 80 | { |
85 | 81 | return true; |
86 | - } |
|
87 | - elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
82 | + } elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
88 | 83 | { |
89 | 84 | return true; |
90 | - } |
|
91 | - elseif(ACL::match($this, $permission_name) === true) |
|
85 | + } elseif(ACL::match($this, $permission_name) === true) |
|
92 | 86 | { |
93 | 87 | return true; |
94 | 88 | } |
@@ -17,8 +17,10 @@ discard block |
||
17 | 17 | |
18 | 18 | public function load_operator($id = null) |
19 | 19 | { |
20 | - if(!is_null($operator_id = $id ?? $this->get('operator_id'))) // extraction failed but we have an fk |
|
20 | + if(!is_null($operator_id = $id ?? $this->get('operator_id'))) { |
|
21 | + // extraction failed but we have an fk |
|
21 | 22 | $this->operator = Operator::exists($operator_id); |
23 | + } |
|
22 | 24 | } |
23 | 25 | |
24 | 26 | public function operator() : ?OperatorInterface |
@@ -28,9 +30,10 @@ discard block |
||
28 | 30 | $extract_attempt = $this->extract(new Operator(), true); |
29 | 31 | if(!is_null($extract_attempt)) |
30 | 32 | { |
31 | - foreach(['permission_names', 'permission_ids'] as $permission_marker) |
|
32 | - if(property_exists($this, $permission_marker)) |
|
33 | + foreach(['permission_names', 'permission_ids'] as $permission_marker) { |
|
34 | + if(property_exists($this, $permission_marker)) |
|
33 | 35 | $extract_attempt->set($permission_marker, $this->$permission_marker); |
36 | + } |
|
34 | 37 | |
35 | 38 | $this->operator = $extract_attempt; |
36 | 39 | } |
@@ -55,14 +58,17 @@ discard block |
||
55 | 58 | |
56 | 59 | $Query->select_also(['operator.name as operator_name', 'operator.active as operator_active']); |
57 | 60 | |
58 | - if(isset($filters['username'])) |
|
59 | - $Query->aw_eq('username', $filters['username'], 'operator'); |
|
61 | + if(isset($filters['username'])) { |
|
62 | + $Query->aw_eq('username', $filters['username'], 'operator'); |
|
63 | + } |
|
60 | 64 | |
61 | - if(isset($filters['email'])) |
|
62 | - $Query->aw_eq('email', $filters['email'], 'operator'); |
|
65 | + if(isset($filters['email'])) { |
|
66 | + $Query->aw_eq('email', $filters['email'], 'operator'); |
|
67 | + } |
|
63 | 68 | |
64 | - if(isset($filters['active'])) |
|
65 | - $Query->aw_eq('active', $filters['active'], 'operator'); |
|
69 | + if(isset($filters['active'])) { |
|
70 | + $Query->aw_eq('active', $filters['active'], 'operator'); |
|
71 | + } |
|
66 | 72 | |
67 | 73 | return $Query; |
68 | 74 | } |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | |
18 | 18 | public function load_operator($id = null) |
19 | 19 | { |
20 | - if(!is_null($operator_id = $id ?? $this->get('operator_id'))) // extraction failed but we have an fk |
|
20 | + if (!is_null($operator_id = $id ?? $this->get('operator_id'))) // extraction failed but we have an fk |
|
21 | 21 | $this->operator = Operator::exists($operator_id); |
22 | 22 | } |
23 | 23 | |
24 | 24 | public function operator() : ?OperatorInterface |
25 | 25 | { |
26 | - if(is_null($this->operator)) |
|
26 | + if (is_null($this->operator)) |
|
27 | 27 | { |
28 | 28 | $extract_attempt = $this->extract(new Operator(), true); |
29 | - if(!is_null($extract_attempt)) |
|
29 | + if (!is_null($extract_attempt)) |
|
30 | 30 | { |
31 | - foreach(['permission_names', 'permission_ids'] as $permission_marker) |
|
32 | - if(property_exists($this, $permission_marker)) |
|
31 | + foreach (['permission_names', 'permission_ids'] as $permission_marker) |
|
32 | + if (property_exists($this, $permission_marker)) |
|
33 | 33 | $extract_attempt->set($permission_marker, $this->$permission_marker); |
34 | 34 | |
35 | 35 | $this->operator = $extract_attempt; |
@@ -45,23 +45,23 @@ discard block |
||
45 | 45 | |
46 | 46 | public static function enhance_query_retrieve($Query, $filters, $options) |
47 | 47 | { |
48 | - $joined_alias = $Query->auto_join([ACL::table(),'ACL'], null, 'LEFT OUTER'); |
|
48 | + $joined_alias = $Query->auto_join([ACL::table(), 'ACL'], null, 'LEFT OUTER'); |
|
49 | 49 | $joined_alias = $Query->auto_join([Permission::table(), 'permission'], null, 'LEFT OUTER'); |
50 | 50 | |
51 | 51 | $permission_ids_and_names = []; |
52 | - $permission_ids_and_names []= sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'id', $joined_alias.'_ids'); |
|
53 | - $permission_ids_and_names []= sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'name', $joined_alias.'_names'); |
|
52 | + $permission_ids_and_names [] = sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'id', $joined_alias.'_ids'); |
|
53 | + $permission_ids_and_names [] = sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'name', $joined_alias.'_names'); |
|
54 | 54 | $Query->select_also($permission_ids_and_names); |
55 | 55 | |
56 | 56 | $Query->select_also(['operator.name as operator_name', 'operator.active as operator_active']); |
57 | 57 | |
58 | - if(isset($filters['username'])) |
|
58 | + if (isset($filters['username'])) |
|
59 | 59 | $Query->aw_eq('username', $filters['username'], 'operator'); |
60 | 60 | |
61 | - if(isset($filters['email'])) |
|
61 | + if (isset($filters['email'])) |
|
62 | 62 | $Query->aw_eq('email', $filters['email'], 'operator'); |
63 | 63 | |
64 | - if(isset($filters['active'])) |
|
64 | + if (isset($filters['active'])) |
|
65 | 65 | $Query->aw_eq('active', $filters['active'], 'operator'); |
66 | 66 | |
67 | 67 | return $Query; |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | { |
41 | 41 | $dir_content = FileSystem::preg_scandir($base_dir, '/^[A-Z]{1}[A-Za-z]+(?!\.class.\.php)$/'); |
42 | 42 | |
43 | - foreach($dir_content as $res) |
|
43 | + foreach ($dir_content as $res) |
|
44 | 44 | { |
45 | - if(is_dir($fullpath = $base_dir.'/'.$res)) |
|
45 | + if (is_dir($fullpath = $base_dir.'/'.$res)) |
|
46 | 46 | { |
47 | 47 | $this->addNamespace('HexMakina\kadro\\'.$res, $fullpath); |
48 | 48 | $this->addNamespaceTree($fullpath); |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | { |
55 | 55 | |
56 | 56 | // normalize namespace prefix |
57 | - $prefix = trim($prefix, '\\') . '\\'; |
|
57 | + $prefix = trim($prefix, '\\').'\\'; |
|
58 | 58 | |
59 | 59 | // normalize the base directory with a trailing separator |
60 | - $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; |
|
60 | + $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR).'/'; |
|
61 | 61 | |
62 | 62 | // initialize the namespace prefix array |
63 | 63 | if (isset($this->prefixes[$prefix]) === false) { |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | while (false !== $pos = strrpos($prefix, '\\')) |
91 | 91 | { |
92 | 92 | // retain the trailing namespace separator in the prefix |
93 | - $prefix = substr($class, 0, $pos + 1); |
|
93 | + $prefix = substr($class, 0, $pos+1); |
|
94 | 94 | // var_dump("prefix: $prefix"); |
95 | 95 | // the rest is the relative class name |
96 | - $relative_class = substr($class, $pos + 1); |
|
96 | + $relative_class = substr($class, $pos+1); |
|
97 | 97 | // try to load a mapped file for the prefix and relative class |
98 | 98 | |
99 | 99 | $mapped_file = $this->loadMappedFile($prefix, $relative_class); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param string $basePath |
37 | 37 | * @param array $matchTypes |
38 | 38 | */ |
39 | - public function __construct( $routes = array(), $basePath = '', $matchTypes = array() ) { |
|
39 | + public function __construct($routes = array(), $basePath = '', $matchTypes = array()) { |
|
40 | 40 | $this->addRoutes($routes); |
41 | 41 | $this->setBasePath($basePath); |
42 | 42 | $this->addMatchTypes($matchTypes); |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | * @author Koen Punt |
64 | 64 | * @throws Exception |
65 | 65 | */ |
66 | - public function addRoutes($routes){ |
|
67 | - if(!is_array($routes) && !$routes instanceof Traversable) { |
|
66 | + public function addRoutes($routes) { |
|
67 | + if (!is_array($routes) && !$routes instanceof Traversable) { |
|
68 | 68 | throw new \Exception('Routes should be an array or an instance of Traversable'); |
69 | 69 | } |
70 | - foreach($routes as $route) { |
|
70 | + foreach ($routes as $route) { |
|
71 | 71 | call_user_func_array(array($this, 'map'), $route); |
72 | 72 | } |
73 | 73 | } |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | |
103 | 103 | $this->routes[] = array($method, $route, $target, $name); |
104 | 104 | |
105 | - if($name) { |
|
106 | - if(isset($this->namedRoutes[$name])) { |
|
105 | + if ($name) { |
|
106 | + if (isset($this->namedRoutes[$name])) { |
|
107 | 107 | throw new \Exception("Can not redeclare route '{$name}'"); |
108 | 108 | } else { |
109 | 109 | $this->namedRoutes[$name] = $route; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | public function generate($routeName, array $params = array()) { |
128 | 128 | |
129 | 129 | // Check if named route exists |
130 | - if(!isset($this->namedRoutes[$routeName])) { |
|
130 | + if (!isset($this->namedRoutes[$routeName])) { |
|
131 | 131 | throw new \Exception("Route '{$routeName}' does not exist."); |
132 | 132 | } |
133 | 133 | |
@@ -135,21 +135,21 @@ discard block |
||
135 | 135 | $route = $this->namedRoutes[$routeName]; |
136 | 136 | |
137 | 137 | // prepend base path to route url again |
138 | - $url = $this->basePath . $route; |
|
138 | + $url = $this->basePath.$route; |
|
139 | 139 | |
140 | 140 | if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { |
141 | 141 | |
142 | - foreach($matches as $match) { |
|
142 | + foreach ($matches as $match) { |
|
143 | 143 | list($block, $pre, $type, $param, $optional) = $match; |
144 | 144 | |
145 | 145 | if ($pre) { |
146 | 146 | $block = substr($block, 1); |
147 | 147 | } |
148 | 148 | |
149 | - if(isset($params[$param])) { |
|
149 | + if (isset($params[$param])) { |
|
150 | 150 | $url = str_replace($block, $params[$param], $url); |
151 | 151 | } elseif ($optional) { |
152 | - $url = str_replace($pre . $block, '', $url); |
|
152 | + $url = str_replace($pre.$block, '', $url); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $match = false; |
172 | 172 | |
173 | 173 | // set Request Url if it isn't passed as parameter |
174 | - if($requestUrl === null) { |
|
174 | + if ($requestUrl === null) { |
|
175 | 175 | $requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; |
176 | 176 | } |
177 | 177 | |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | // set Request Method if it isn't passed as a parameter |
187 | - if($requestMethod === null) { |
|
187 | + if ($requestMethod === null) { |
|
188 | 188 | $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; |
189 | 189 | } |
190 | 190 | |
191 | - foreach($this->routes as $handler) { |
|
191 | + foreach ($this->routes as $handler) { |
|
192 | 192 | list($methods, $route, $target, $name) = $handler; |
193 | 193 | $method_match = (stripos($methods, $requestMethod) !== false); |
194 | 194 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $match = true; |
201 | 201 | } elseif (isset($route[0]) && $route[0] === '@') { |
202 | 202 | // @ regex delimiter |
203 | - $pattern = '`' . substr($route, 1) . '`u'; |
|
203 | + $pattern = '`'.substr($route, 1).'`u'; |
|
204 | 204 | $match = preg_match($pattern, $requestUrl, $params) === 1; |
205 | 205 | } elseif (($position = strpos($route, '[')) === false) { |
206 | 206 | // No params in url, do string comparison |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | if ($match) { |
218 | 218 | |
219 | 219 | if ($params) { |
220 | - foreach($params as $key => $value) { |
|
221 | - if(is_numeric($key)) unset($params[$key]); |
|
220 | + foreach ($params as $key => $value) { |
|
221 | + if (is_numeric($key)) unset($params[$key]); |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { |
240 | 240 | |
241 | 241 | $matchTypes = $this->matchTypes; |
242 | - foreach($matches as $match) { |
|
242 | + foreach ($matches as $match) { |
|
243 | 243 | list($block, $pre, $type, $param, $optional) = $match; |
244 | 244 | |
245 | 245 | if (isset($matchTypes[$type])) { |
@@ -193,7 +193,9 @@ discard block |
||
193 | 193 | $method_match = (stripos($methods, $requestMethod) !== false); |
194 | 194 | |
195 | 195 | // Method did not match, continue to next route. |
196 | - if (!$method_match) continue; |
|
196 | + if (!$method_match) { |
|
197 | + continue; |
|
198 | + } |
|
197 | 199 | |
198 | 200 | if ($route === '*') { |
199 | 201 | // * wildcard (matches all) |
@@ -218,7 +220,9 @@ discard block |
||
218 | 220 | |
219 | 221 | if ($params) { |
220 | 222 | foreach($params as $key => $value) { |
221 | - if(is_numeric($key)) unset($params[$key]); |
|
223 | + if(is_numeric($key)) { |
|
224 | + unset($params[$key]); |
|
225 | + } |
|
222 | 226 | } |
223 | 227 | } |
224 | 228 |
@@ -11,36 +11,36 @@ |
||
11 | 11 | global $smarty; |
12 | 12 | |
13 | 13 | $pages_max_on_each_side = 3; |
14 | - $pages_max_displayed = $pages_max_on_each_side*2+1; |
|
14 | + $pages_max_displayed = $pages_max_on_each_side * 2+1; |
|
15 | 15 | |
16 | 16 | // are we paginating ? |
17 | 17 | |
18 | - if(is_null($this->box('StateAgent')->filters('results_per_page'))) |
|
18 | + if (is_null($this->box('StateAgent')->filters('results_per_page'))) |
|
19 | 19 | return; |
20 | 20 | |
21 | 21 | $pages_range = intval($this->box('StateAgent')->filters('results_per_page')); |
22 | 22 | $pages_total = $pages_range > 0 ? intval(ceil($records_total / $pages_range)) : 1; |
23 | 23 | $pages_current = intval($this->box('StateAgent')->filters('page')); |
24 | 24 | |
25 | - if($pages_current >= $pages_total) |
|
25 | + if ($pages_current >= $pages_total) |
|
26 | 26 | $pages_current = $pages_total; |
27 | 27 | |
28 | - $pages_first = ($pages_current <= $pages_max_on_each_side)? 1 : $pages_current - $pages_max_on_each_side; |
|
28 | + $pages_first = ($pages_current <= $pages_max_on_each_side) ? 1 : $pages_current-$pages_max_on_each_side; |
|
29 | 29 | |
30 | - $pages_last = $pages_current + $pages_max_on_each_side; |
|
30 | + $pages_last = $pages_current+$pages_max_on_each_side; |
|
31 | 31 | |
32 | - if($pages_last < $pages_max_displayed) // add the missing pages to fullfill $pages_max_displayed |
|
32 | + if ($pages_last < $pages_max_displayed) // add the missing pages to fullfill $pages_max_displayed |
|
33 | 33 | $pages_last += $pages_max_displayed-$pages_last; |
34 | 34 | |
35 | - if($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages |
|
35 | + if ($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages |
|
36 | 36 | $pages_last = $pages_total; |
37 | 37 | |
38 | - $this->viewport("pages_total", $pages_total); |
|
39 | - $this->viewport("pages_first", $pages_first); |
|
40 | - $this->viewport("pages_previous", $pages_current <= 1 ? $pages_total : $pages_current - 1); |
|
41 | - $this->viewport("pages_current", $pages_current); |
|
42 | - $this->viewport("pages_next", $pages_current >= $pages_total ? 1 : $pages_current + 1); |
|
43 | - $this->viewport("pages_last", $pages_last); |
|
38 | + $this->viewport("pages_total", $pages_total); |
|
39 | + $this->viewport("pages_first", $pages_first); |
|
40 | + $this->viewport("pages_previous", $pages_current <= 1 ? $pages_total : $pages_current-1); |
|
41 | + $this->viewport("pages_current", $pages_current); |
|
42 | + $this->viewport("pages_next", $pages_current >= $pages_total ? 1 : $pages_current+1); |
|
43 | + $this->viewport("pages_last", $pages_last); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -15,25 +15,31 @@ |
||
15 | 15 | |
16 | 16 | // are we paginating ? |
17 | 17 | |
18 | - if(is_null($this->box('StateAgent')->filters('results_per_page'))) |
|
19 | - return; |
|
18 | + if(is_null($this->box('StateAgent')->filters('results_per_page'))) { |
|
19 | + return; |
|
20 | + } |
|
20 | 21 | |
21 | 22 | $pages_range = intval($this->box('StateAgent')->filters('results_per_page')); |
22 | 23 | $pages_total = $pages_range > 0 ? intval(ceil($records_total / $pages_range)) : 1; |
23 | 24 | $pages_current = intval($this->box('StateAgent')->filters('page')); |
24 | 25 | |
25 | - if($pages_current >= $pages_total) |
|
26 | - $pages_current = $pages_total; |
|
26 | + if($pages_current >= $pages_total) { |
|
27 | + $pages_current = $pages_total; |
|
28 | + } |
|
27 | 29 | |
28 | 30 | $pages_first = ($pages_current <= $pages_max_on_each_side)? 1 : $pages_current - $pages_max_on_each_side; |
29 | 31 | |
30 | 32 | $pages_last = $pages_current + $pages_max_on_each_side; |
31 | 33 | |
32 | - if($pages_last < $pages_max_displayed) // add the missing pages to fullfill $pages_max_displayed |
|
34 | + if($pages_last < $pages_max_displayed) { |
|
35 | + // add the missing pages to fullfill $pages_max_displayed |
|
33 | 36 | $pages_last += $pages_max_displayed-$pages_last; |
37 | + } |
|
34 | 38 | |
35 | - if($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages |
|
39 | + if($pages_last > $pages_total) { |
|
40 | + // $pages_max_displayed greater than the total of pages |
|
36 | 41 | $pages_last = $pages_total; |
42 | + } |
|
37 | 43 | |
38 | 44 | $this->viewport("pages_total", $pages_total); |
39 | 45 | $this->viewport("pages_first", $pages_first); |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HexMakina\kadro\Controllers; |
4 | 4 | |
5 | -use \Psr\Container\{ContainerInterface,ContainerExceptionInterface,NotFoundExceptionInterface}; |
|
5 | +use \Psr\Container\{ContainerInterface, ContainerExceptionInterface, NotFoundExceptionInterface}; |
|
6 | 6 | |
7 | 7 | use \HexMakina\kadro\Auth\{OperatorInterface, AccessRefusedException}; |
8 | 8 | use \HexMakina\kadro\Router\RouterInterface; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | protected $route_back = null; |
17 | 17 | |
18 | - public function __toString(){ return get_called_class();} |
|
18 | + public function __toString() { return get_called_class(); } |
|
19 | 19 | |
20 | 20 | // -------- Controller Container |
21 | 21 | public function set_container(ContainerInterface $container) |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | // shortcut for (un)boxing |
32 | - public function box($key, $instance=null) |
|
32 | + public function box($key, $instance = null) |
|
33 | 33 | { |
34 | - if(!is_null($instance)) |
|
34 | + if (!is_null($instance)) |
|
35 | 35 | $this->container->register($key, $instance); |
36 | 36 | |
37 | 37 | // dd($this->container->get($key)); |
@@ -61,32 +61,32 @@ discard block |
||
61 | 61 | return true; // security by default |
62 | 62 | } |
63 | 63 | |
64 | - public function authorize($permission=null) |
|
64 | + public function authorize($permission = null) |
|
65 | 65 | { |
66 | 66 | // if(!$this->requires_operator() || is_null($permission)) |
67 | - if(!$this->requires_operator()) |
|
67 | + if (!$this->requires_operator()) |
|
68 | 68 | return true; |
69 | 69 | |
70 | 70 | $operator = $this->operator(); |
71 | - if(is_null($operator) || $operator->is_new() || !$operator->is_active()) |
|
71 | + if (is_null($operator) || $operator->is_new() || !$operator->is_active()) |
|
72 | 72 | throw new AccessRefusedException(); |
73 | 73 | |
74 | - if(!is_null($permission) && !$operator->has_permission($permission)) |
|
74 | + if (!is_null($permission) && !$operator->has_permission($permission)) |
|
75 | 75 | throw new AccessRefusedException(); |
76 | 76 | |
77 | 77 | return true; |
78 | 78 | } |
79 | 79 | |
80 | - public function viewport($key=null, $value=null, $coercion=false) |
|
80 | + public function viewport($key = null, $value = null, $coercion = false) |
|
81 | 81 | { |
82 | 82 | // no key, returns all |
83 | - if(is_null($key)) |
|
83 | + if (is_null($key)) |
|
84 | 84 | return $this->template_variables; |
85 | 85 | |
86 | 86 | // got key, got null value, returns $[$key] |
87 | - if(is_null($value)) |
|
87 | + if (is_null($value)) |
|
88 | 88 | { |
89 | - if($coercion === true) // break rule 1 ? |
|
89 | + if ($coercion === true) // break rule 1 ? |
|
90 | 90 | $this->template_variables[$key] = null; |
91 | 91 | |
92 | 92 | return $this->template_variables[$key] ?? null; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | // got key, got value |
96 | 96 | // sets or coerces $[$key]=$value and returns $[$key] |
97 | - if(!isset($this->template_variables[$key]) || $coercion === true) |
|
97 | + if (!isset($this->template_variables[$key]) || $coercion === true) |
|
98 | 98 | $this->template_variables[$key] = $value; |
99 | 99 | |
100 | 100 | return $this->template_variables[$key] ?? null; |
@@ -106,22 +106,22 @@ discard block |
||
106 | 106 | |
107 | 107 | $custom_template = null; |
108 | 108 | |
109 | - if(method_exists($this, 'prepare')) |
|
109 | + if (method_exists($this, 'prepare')) |
|
110 | 110 | $this->prepare(); |
111 | 111 | |
112 | - if(method_exists($this, $method = $this->router()->target_method())) |
|
112 | + if (method_exists($this, $method = $this->router()->target_method())) |
|
113 | 113 | { |
114 | 114 | $custom_template = $this->$method(); |
115 | 115 | } |
116 | 116 | |
117 | - if(method_exists($this, 'conclude')) |
|
117 | + if (method_exists($this, 'conclude')) |
|
118 | 118 | $this->conclude(); |
119 | 119 | |
120 | - if(method_exists($this, 'display')) |
|
120 | + if (method_exists($this, 'display')) |
|
121 | 121 | $template = $this->display($custom_template); |
122 | 122 | } |
123 | 123 | |
124 | - public function conclude(){} |
|
124 | + public function conclude() {} |
|
125 | 125 | |
126 | 126 | public function prepare() |
127 | 127 | { |
@@ -130,14 +130,14 @@ discard block |
||
130 | 130 | |
131 | 131 | private function trim_request_data() |
132 | 132 | { |
133 | - array_walk_recursive($_GET, function(&$value){$value = trim($value);}); |
|
134 | - array_walk_recursive($_REQUEST, function(&$value){$value = trim($value);}); |
|
133 | + array_walk_recursive($_GET, function(&$value) {$value = trim($value); }); |
|
134 | + array_walk_recursive($_REQUEST, function(&$value) {$value = trim($value); }); |
|
135 | 135 | |
136 | - if($this->router()->submits()) |
|
137 | - array_walk_recursive($_POST, function(&$value){$value = trim($value);}); |
|
136 | + if ($this->router()->submits()) |
|
137 | + array_walk_recursive($_POST, function(&$value) {$value = trim($value); }); |
|
138 | 138 | } |
139 | 139 | |
140 | - public function display($custom_template = null, $standalone=false) |
|
140 | + public function display($custom_template = null, $standalone = false) |
|
141 | 141 | { |
142 | 142 | $smarty = $this->box('template_engine'); |
143 | 143 | |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | |
150 | 150 | |
151 | 151 | $this->viewport('file_root', $this->router()->file_root()); |
152 | - $this->viewport('view_path', $this->router()->file_root() . $this->box('settings.smarty.template_path').'app/'); |
|
152 | + $this->viewport('view_path', $this->router()->file_root().$this->box('settings.smarty.template_path').'app/'); |
|
153 | 153 | $this->viewport('web_root', $this->router()->web_root()); |
154 | - $this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path')); |
|
155 | - $this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/'); |
|
154 | + $this->viewport('view_url', $this->router()->web_root().$this->box('settings.smarty.template_path')); |
|
155 | + $this->viewport('images_url', $this->router()->web_root().$this->box('settings.smarty.template_path').'images/'); |
|
156 | 156 | |
157 | - foreach($this->viewport() as $template_var_name => $value) |
|
157 | + foreach ($this->viewport() as $template_var_name => $value) |
|
158 | 158 | $smarty->assign($template_var_name, $value); |
159 | 159 | |
160 | - if($standalone === false) |
|
160 | + if ($standalone === false) |
|
161 | 161 | { |
162 | 162 | $smarty->display(sprintf('%s|%s', $this->box('settings.smarty.template_inclusion_path'), $template)); |
163 | 163 | } |
@@ -180,32 +180,32 @@ discard block |
||
180 | 180 | $controller_template_path = $this->template_base(); |
181 | 181 | $templates = []; |
182 | 182 | |
183 | - if(!empty($custom_template)) |
|
183 | + if (!empty($custom_template)) |
|
184 | 184 | { |
185 | 185 | // 1. check for custom template in the current controller directory |
186 | - $templates ['custom_3']= sprintf('%s/%s.html', $controller_template_path, $custom_template); |
|
186 | + $templates ['custom_3'] = sprintf('%s/%s.html', $controller_template_path, $custom_template); |
|
187 | 187 | // 2. check for custom template formatted as controller/view |
188 | - $templates ['custom_2']= $custom_template.'.html'; |
|
189 | - $templates ['custom_1']= '_layouts/'.$custom_template.'.html'; |
|
188 | + $templates ['custom_2'] = $custom_template.'.html'; |
|
189 | + $templates ['custom_1'] = '_layouts/'.$custom_template.'.html'; |
|
190 | 190 | } |
191 | 191 | |
192 | - if(!empty($this->router()->target_method())) |
|
192 | + if (!empty($this->router()->target_method())) |
|
193 | 193 | { |
194 | 194 | // 1. check for template in controller-related directory |
195 | - $templates ['target_1']= sprintf('%s/%s.html', $controller_template_path, $this->router()->target_method()); |
|
195 | + $templates ['target_1'] = sprintf('%s/%s.html', $controller_template_path, $this->router()->target_method()); |
|
196 | 196 | // 2. check for template in app-related directory |
197 | - $templates ['target_2']= sprintf('_layouts/%s.html', $this->router()->target_method()); |
|
197 | + $templates ['target_2'] = sprintf('_layouts/%s.html', $this->router()->target_method()); |
|
198 | 198 | // 3. check for template in kadro directory |
199 | - $templates ['target_3']= sprintf('%s.html', $this->router()->target_method()); |
|
199 | + $templates ['target_3'] = sprintf('%s.html', $this->router()->target_method()); |
|
200 | 200 | } |
201 | 201 | |
202 | - $templates ['default_3']= sprintf('%s/edit.html', $controller_template_path); |
|
203 | - $templates ['default_4']= 'edit.tpl'; |
|
202 | + $templates ['default_3'] = sprintf('%s/edit.html', $controller_template_path); |
|
203 | + $templates ['default_4'] = 'edit.tpl'; |
|
204 | 204 | $templates = array_unique($templates); |
205 | 205 | |
206 | - while(!is_null($tpl_path = array_shift($templates))) |
|
206 | + while (!is_null($tpl_path = array_shift($templates))) |
|
207 | 207 | { |
208 | - if($smarty->templateExists($tpl_path)) |
|
208 | + if ($smarty->templateExists($tpl_path)) |
|
209 | 209 | return $tpl_path; |
210 | 210 | } |
211 | 211 | |
@@ -226,21 +226,21 @@ discard block |
||
226 | 226 | * route_back($route_name [,$route_params]), sets $route_back using route_factory() |
227 | 227 | * |
228 | 228 | */ |
229 | - public function route_back($route_name=null, $route_params=[]) : string |
|
229 | + public function route_back($route_name = null, $route_params = []) : string |
|
230 | 230 | { |
231 | - if(is_null($route_name)) |
|
231 | + if (is_null($route_name)) |
|
232 | 232 | return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME); |
233 | 233 | |
234 | 234 | return $this->route_back = $this->route_factory($route_name, $route_params); |
235 | 235 | } |
236 | 236 | |
237 | - public function route_factory($route_name=null, $route_params=[]) : string |
|
237 | + public function route_factory($route_name = null, $route_params = []) : string |
|
238 | 238 | { |
239 | 239 | $route = null; |
240 | 240 | |
241 | - if(is_string($route_name) && !empty($route_name)) |
|
241 | + if (is_string($route_name) && !empty($route_name)) |
|
242 | 242 | { |
243 | - if($this->router()->route_exists($route_name)) |
|
243 | + if ($this->router()->route_exists($route_name)) |
|
244 | 244 | $route = $this->router()->prehop($route_name, $route_params); |
245 | 245 | else |
246 | 246 | $route = $route_name; |
@@ -31,8 +31,9 @@ discard block |
||
31 | 31 | // shortcut for (un)boxing |
32 | 32 | public function box($key, $instance=null) |
33 | 33 | { |
34 | - if(!is_null($instance)) |
|
35 | - $this->container->register($key, $instance); |
|
34 | + if(!is_null($instance)) { |
|
35 | + $this->container->register($key, $instance); |
|
36 | + } |
|
36 | 37 | |
37 | 38 | // dd($this->container->get($key)); |
38 | 39 | return $this->container->get($key); |
@@ -64,15 +65,18 @@ discard block |
||
64 | 65 | public function authorize($permission=null) |
65 | 66 | { |
66 | 67 | // if(!$this->requires_operator() || is_null($permission)) |
67 | - if(!$this->requires_operator()) |
|
68 | - return true; |
|
68 | + if(!$this->requires_operator()) { |
|
69 | + return true; |
|
70 | + } |
|
69 | 71 | |
70 | 72 | $operator = $this->operator(); |
71 | - if(is_null($operator) || $operator->is_new() || !$operator->is_active()) |
|
72 | - throw new AccessRefusedException(); |
|
73 | + if(is_null($operator) || $operator->is_new() || !$operator->is_active()) { |
|
74 | + throw new AccessRefusedException(); |
|
75 | + } |
|
73 | 76 | |
74 | - if(!is_null($permission) && !$operator->has_permission($permission)) |
|
75 | - throw new AccessRefusedException(); |
|
77 | + if(!is_null($permission) && !$operator->has_permission($permission)) { |
|
78 | + throw new AccessRefusedException(); |
|
79 | + } |
|
76 | 80 | |
77 | 81 | return true; |
78 | 82 | } |
@@ -80,22 +84,26 @@ discard block |
||
80 | 84 | public function viewport($key=null, $value=null, $coercion=false) |
81 | 85 | { |
82 | 86 | // no key, returns all |
83 | - if(is_null($key)) |
|
84 | - return $this->template_variables; |
|
87 | + if(is_null($key)) { |
|
88 | + return $this->template_variables; |
|
89 | + } |
|
85 | 90 | |
86 | 91 | // got key, got null value, returns $[$key] |
87 | 92 | if(is_null($value)) |
88 | 93 | { |
89 | - if($coercion === true) // break rule 1 ? |
|
94 | + if($coercion === true) { |
|
95 | + // break rule 1 ? |
|
90 | 96 | $this->template_variables[$key] = null; |
97 | + } |
|
91 | 98 | |
92 | 99 | return $this->template_variables[$key] ?? null; |
93 | 100 | } |
94 | 101 | |
95 | 102 | // got key, got value |
96 | 103 | // sets or coerces $[$key]=$value and returns $[$key] |
97 | - if(!isset($this->template_variables[$key]) || $coercion === true) |
|
98 | - $this->template_variables[$key] = $value; |
|
104 | + if(!isset($this->template_variables[$key]) || $coercion === true) { |
|
105 | + $this->template_variables[$key] = $value; |
|
106 | + } |
|
99 | 107 | |
100 | 108 | return $this->template_variables[$key] ?? null; |
101 | 109 | } |
@@ -106,19 +114,22 @@ discard block |
||
106 | 114 | |
107 | 115 | $custom_template = null; |
108 | 116 | |
109 | - if(method_exists($this, 'prepare')) |
|
110 | - $this->prepare(); |
|
117 | + if(method_exists($this, 'prepare')) { |
|
118 | + $this->prepare(); |
|
119 | + } |
|
111 | 120 | |
112 | 121 | if(method_exists($this, $method = $this->router()->target_method())) |
113 | 122 | { |
114 | 123 | $custom_template = $this->$method(); |
115 | 124 | } |
116 | 125 | |
117 | - if(method_exists($this, 'conclude')) |
|
118 | - $this->conclude(); |
|
126 | + if(method_exists($this, 'conclude')) { |
|
127 | + $this->conclude(); |
|
128 | + } |
|
119 | 129 | |
120 | - if(method_exists($this, 'display')) |
|
121 | - $template = $this->display($custom_template); |
|
130 | + if(method_exists($this, 'display')) { |
|
131 | + $template = $this->display($custom_template); |
|
132 | + } |
|
122 | 133 | } |
123 | 134 | |
124 | 135 | public function conclude(){} |
@@ -133,8 +144,10 @@ discard block |
||
133 | 144 | array_walk_recursive($_GET, function(&$value){$value = trim($value);}); |
134 | 145 | array_walk_recursive($_REQUEST, function(&$value){$value = trim($value);}); |
135 | 146 | |
136 | - if($this->router()->submits()) |
|
137 | - array_walk_recursive($_POST, function(&$value){$value = trim($value);}); |
|
147 | + if($this->router()->submits()) { |
|
148 | + array_walk_recursive($_POST, function(&$value){$value = trim($value); |
|
149 | + } |
|
150 | + }); |
|
138 | 151 | } |
139 | 152 | |
140 | 153 | public function display($custom_template = null, $standalone=false) |
@@ -154,14 +167,14 @@ discard block |
||
154 | 167 | $this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path')); |
155 | 168 | $this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/'); |
156 | 169 | |
157 | - foreach($this->viewport() as $template_var_name => $value) |
|
158 | - $smarty->assign($template_var_name, $value); |
|
170 | + foreach($this->viewport() as $template_var_name => $value) { |
|
171 | + $smarty->assign($template_var_name, $value); |
|
172 | + } |
|
159 | 173 | |
160 | 174 | if($standalone === false) |
161 | 175 | { |
162 | 176 | $smarty->display(sprintf('%s|%s', $this->box('settings.smarty.template_inclusion_path'), $template)); |
163 | - } |
|
164 | - else |
|
177 | + } else |
|
165 | 178 | { |
166 | 179 | $smarty->display($template); |
167 | 180 | } |
@@ -205,8 +218,9 @@ discard block |
||
205 | 218 | |
206 | 219 | while(!is_null($tpl_path = array_shift($templates))) |
207 | 220 | { |
208 | - if($smarty->templateExists($tpl_path)) |
|
209 | - return $tpl_path; |
|
221 | + if($smarty->templateExists($tpl_path)) { |
|
222 | + return $tpl_path; |
|
223 | + } |
|
210 | 224 | } |
211 | 225 | |
212 | 226 | throw new \Exception('KADRO_ERR_NO_TEMPLATE_TO_DISPLAY'); |
@@ -228,8 +242,9 @@ discard block |
||
228 | 242 | */ |
229 | 243 | public function route_back($route_name=null, $route_params=[]) : string |
230 | 244 | { |
231 | - if(is_null($route_name)) |
|
232 | - return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME); |
|
245 | + if(is_null($route_name)) { |
|
246 | + return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME); |
|
247 | + } |
|
233 | 248 | |
234 | 249 | return $this->route_back = $this->route_factory($route_name, $route_params); |
235 | 250 | } |
@@ -240,10 +255,11 @@ discard block |
||
240 | 255 | |
241 | 256 | if(is_string($route_name) && !empty($route_name)) |
242 | 257 | { |
243 | - if($this->router()->route_exists($route_name)) |
|
244 | - $route = $this->router()->prehop($route_name, $route_params); |
|
245 | - else |
|
246 | - $route = $route_name; |
|
258 | + if($this->router()->route_exists($route_name)) { |
|
259 | + $route = $this->router()->prehop($route_name, $route_params); |
|
260 | + } else { |
|
261 | + $route = $route_name; |
|
262 | + } |
|
247 | 263 | |
248 | 264 | return $route; |
249 | 265 | } |
@@ -11,9 +11,9 @@ |
||
11 | 11 | return $this->breadcrumbs; |
12 | 12 | } |
13 | 13 | |
14 | - public function breadcrumb($show, $route=null) |
|
14 | + public function breadcrumb($show, $route = null) |
|
15 | 15 | { |
16 | - $this->breadcrumbs[]= ['show' => $show, 'route' => $route]; |
|
16 | + $this->breadcrumbs[] = ['show' => $show, 'route' => $route]; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function reset_breadcrumbs() : array |
@@ -33,7 +33,7 @@ |
||
33 | 33 | $headers = explode(',', trim($language_data[0])); |
34 | 34 | array_shift($language_data); |
35 | 35 | |
36 | - foreach($language_data as $i => $lang) |
|
36 | + foreach ($language_data as $i => $lang) |
|
37 | 37 | { |
38 | 38 | $data = array_combine($headers, explode(',', $lang)); |
39 | 39 |