|
| 1 | +<?php |
| 2 | + |
| 3 | +if (!function_exists('active_class')) { |
| 4 | + /** |
| 5 | + * Get the active class if the condition is not falsy. |
| 6 | + * |
| 7 | + * @param $condition |
| 8 | + * @param string $activeClass |
| 9 | + * @param string $inactiveClass |
| 10 | + * |
| 11 | + * @return string |
| 12 | + */ |
| 13 | + function active_class($condition, $activeClass = 'active', $inactiveClass = '') |
| 14 | + { |
| 15 | + return app('active')->getClassIf($condition, $activeClass, $inactiveClass); |
| 16 | + } |
| 17 | +} |
| 18 | +if (!function_exists('if_uri')) { |
| 19 | + /** |
| 20 | + * Check if the URI of the current request matches one of the specific URIs. |
| 21 | + * |
| 22 | + * @param array|string $uris |
| 23 | + * |
| 24 | + * @return bool |
| 25 | + */ |
| 26 | + function if_uri($uris) |
| 27 | + { |
| 28 | + return app('active')->checkUri($uris); |
| 29 | + } |
| 30 | +} |
| 31 | +if (!function_exists('if_uri_pattern')) { |
| 32 | + /** |
| 33 | + * Check if the current URI matches one of specific patterns (using `str_is`). |
| 34 | + * |
| 35 | + * @param array|string $patterns |
| 36 | + * |
| 37 | + * @return bool |
| 38 | + */ |
| 39 | + function if_uri_pattern($patterns) |
| 40 | + { |
| 41 | + return app('active')->checkUriPattern($patterns); |
| 42 | + } |
| 43 | +} |
| 44 | +if (!function_exists('if_query')) { |
| 45 | + /** |
| 46 | + * Check if one of the following condition is true: |
| 47 | + * + the value of $value is `false` and the current querystring contain the key $key |
| 48 | + * + the value of $value is not `false` and the current value of the $key key in the querystring equals to $value |
| 49 | + * + the value of $value is not `false` and the current value of the $key key in the querystring is an array that |
| 50 | + * contains the $value. |
| 51 | + * |
| 52 | + * @param string $key |
| 53 | + * @param mixed $value |
| 54 | + * |
| 55 | + * @return bool |
| 56 | + */ |
| 57 | + function if_query($key, $value) |
| 58 | + { |
| 59 | + return app('active')->checkQuery($key, $value); |
| 60 | + } |
| 61 | +} |
| 62 | +if (!function_exists('if_route')) { |
| 63 | + /** |
| 64 | + * Check if the name of the current route matches one of specific values. |
| 65 | + * |
| 66 | + * @param array|string $routeNames |
| 67 | + * |
| 68 | + * @return bool |
| 69 | + */ |
| 70 | + function if_route($routeNames) |
| 71 | + { |
| 72 | + return app('active')->checkRoute($routeNames); |
| 73 | + } |
| 74 | +} |
| 75 | +if (!function_exists('if_route_pattern')) { |
| 76 | + /** |
| 77 | + * Check the current route name with one or some patterns. |
| 78 | + * |
| 79 | + * @param array|string $patterns |
| 80 | + * |
| 81 | + * @return bool |
| 82 | + */ |
| 83 | + function if_route_pattern($patterns) |
| 84 | + { |
| 85 | + return app('active')->checkRoutePattern($patterns); |
| 86 | + } |
| 87 | +} |
| 88 | +if (!function_exists('if_route_param')) { |
| 89 | + /** |
| 90 | + * Check if the parameter of the current route has the correct value. |
| 91 | + * |
| 92 | + * @param $param |
| 93 | + * @param $value |
| 94 | + * |
| 95 | + * @return bool |
| 96 | + */ |
| 97 | + function if_route_param($param, $value) |
| 98 | + { |
| 99 | + return app('active')->checkRouteParam($param, $value); |
| 100 | + } |
| 101 | +} |
| 102 | +if (!function_exists('if_action')) { |
| 103 | + /** |
| 104 | + * Return 'active' class if current route action match one of provided action names. |
| 105 | + * |
| 106 | + * @param array|string $actions |
| 107 | + * |
| 108 | + * @return bool |
| 109 | + */ |
| 110 | + function if_action($actions) |
| 111 | + { |
| 112 | + return app('active')->checkAction($actions); |
| 113 | + } |
| 114 | +} |
| 115 | +if (!function_exists('if_controller')) { |
| 116 | + /** |
| 117 | + * Check if the current controller class matches one of specific values. |
| 118 | + * |
| 119 | + * @param array|string $controllers |
| 120 | + * |
| 121 | + * @return bool |
| 122 | + */ |
| 123 | + function if_controller($controllers) |
| 124 | + { |
| 125 | + return app('active')->checkController($controllers); |
| 126 | + } |
| 127 | +} |
| 128 | +if (!function_exists('current_controller')) { |
| 129 | + /** |
| 130 | + * Get the current controller class. |
| 131 | + * |
| 132 | + * @return string |
| 133 | + */ |
| 134 | + function current_controller() |
| 135 | + { |
| 136 | + return app('active')->getController(); |
| 137 | + } |
| 138 | +} |
| 139 | +if (!function_exists('current_method')) { |
| 140 | + /** |
| 141 | + * Get the current controller method. |
| 142 | + * |
| 143 | + * @return string |
| 144 | + */ |
| 145 | + function current_method() |
| 146 | + { |
| 147 | + return app('active')->getMethod(); |
| 148 | + } |
| 149 | +} |
| 150 | +if (!function_exists('current_action')) { |
| 151 | + /** |
| 152 | + * Get the current action string. |
| 153 | + * |
| 154 | + * @return string |
| 155 | + */ |
| 156 | + function current_action() |
| 157 | + { |
| 158 | + return app('active')->getAction(); |
| 159 | + } |
| 160 | +} |
0 commit comments