Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/Helpers/activeHelpers.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

if (!function_exists('active_class')) {
/**
* Get the active class if the condition is not falsy.
Expand Down Expand Up @@ -126,7 +127,7 @@ function if_controller($controllers)
}
if (!function_exists('current_controller')) {
/**
* Get the current controller class
* Get the current controller class.
*
* @return string
*/
Expand All @@ -137,7 +138,7 @@ function current_controller()
}
if (!function_exists('current_method')) {
/**
* Get the current controller method
* Get the current controller method.
*
* @return string
*/
Expand All @@ -148,12 +149,12 @@ function current_method()
}
if (!function_exists('current_action')) {
/**
* Get the current action string
* Get the current action string.
*
* @return string
*/
function current_action()
{
return app('active')->getAction();
}
}
}
29 changes: 24 additions & 5 deletions app/Services/Active/Active.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @author Hieu Le <letrunghieu.cse09@gmail.com>
*
* @version 3.2.0
*
*/
class Active
{
Expand Down Expand Up @@ -61,6 +60,7 @@ class Active
* @var string
*/
protected $uri;

/**
* Active constructor.
*
Expand All @@ -70,6 +70,7 @@ public function __construct($request)
{
$this->updateInstances(null, $request);
}

/**
* Update the route and request instances.
*
Expand All @@ -90,6 +91,7 @@ public function updateInstances($route, $request)
$this->method = last($actionSegments);
}
}

/**
* Get the active class if the condition is not falsy.
*
Expand All @@ -103,6 +105,7 @@ public function getClassIf($condition, $activeClass = 'active', $inactiveClass =
{
return $condition ? $activeClass : $inactiveClass;
}

/**
* Check if the URI of the current request matches one of the specific URIs.
*
Expand All @@ -115,13 +118,15 @@ public function checkUri($uris)
if (!$this->request) {
return false;
}
foreach ((array)$uris as $uri) {
foreach ((array) $uris as $uri) {
if ($this->uri == $uri) {
return true;
}
}

return false;
}

/**
* Check if the current URI matches one of specific patterns (using `Str::is`).
*
Expand Down Expand Up @@ -171,8 +176,10 @@ public function checkQuery($key, $value)
) {
return true;
}

return false;
}

/**
* Check if the name of the current route matches one of specific values.
*
Expand All @@ -189,8 +196,10 @@ public function checkRoute($routeNames)
if (in_array($routeName, (array) $routeNames)) {
return true;
}

return false;
}

/**
* Check the current route name with one or some patterns.
*
Expand All @@ -212,8 +221,10 @@ public function checkRoutePattern($patterns)
return true;
}
}

return false;
}

/**
* Check if the parameter of the current route has the correct value.
*
Expand All @@ -233,8 +244,10 @@ public function checkRouteParam($param, $value)
if (is_a($paramValue, Model::class)) {
return $paramValue->{$paramValue->getKeyName()} == $value;
}

return $paramValue == $value;
}

/**
* Return 'active' class if current route action match one of provided action names.
*
Expand All @@ -247,11 +260,13 @@ public function checkAction($actions)
if (!$this->action) {
return false;
}
if (in_array($this->action, (array)$actions)) {
if (in_array($this->action, (array) $actions)) {
return true;
}

return false;
}

/**
* Check if the current controller class matches one of specific values.
*
Expand All @@ -264,11 +279,13 @@ public function checkController($controllers)
if (!$this->controller) {
return false;
}
if (in_array($this->controller, (array)$controllers)) {
if (in_array($this->controller, (array) $controllers)) {
return true;
}

return false;
}

/**
* Get the current controller method.
*
Expand All @@ -278,6 +295,7 @@ public function getMethod()
{
return $this->method ?: '';
}

/**
* Get the current action string.
*
Expand All @@ -287,6 +305,7 @@ public function getAction()
{
return $this->action ?: '';
}

/**
* Get the current controller class.
*
Expand All @@ -296,4 +315,4 @@ public function getController()
{
return $this->controller ?: '';
}
}
}