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
22 changes: 5 additions & 17 deletions app/Helpers/activeHelpers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

if (!function_exists('active_class')) {
/**
* Get the active class if the condition is not falsy.
Expand All @@ -15,7 +14,6 @@ function active_class($condition, $activeClass = 'active', $inactiveClass = '')
return app('active')->getClassIf($condition, $activeClass, $inactiveClass);
}
}

if (!function_exists('if_uri')) {
/**
* Check if the URI of the current request matches one of the specific URIs.
Expand All @@ -29,10 +27,9 @@ function if_uri($uris)
return app('active')->checkUri($uris);
}
}

if (!function_exists('if_uri_pattern')) {
/**
* Check if the current URI matches one of specific patterns (using `Str::is`).
* Check if the current URI matches one of specific patterns (using `str_is`).
*
* @param array|string $patterns
*
Expand All @@ -43,7 +40,6 @@ function if_uri_pattern($patterns)
return app('active')->checkUriPattern($patterns);
}
}

if (!function_exists('if_query')) {
/**
* Check if one of the following condition is true:
Expand All @@ -62,7 +58,6 @@ function if_query($key, $value)
return app('active')->checkQuery($key, $value);
}
}

if (!function_exists('if_route')) {
/**
* Check if the name of the current route matches one of specific values.
Expand All @@ -76,7 +71,6 @@ function if_route($routeNames)
return app('active')->checkRoute($routeNames);
}
}

if (!function_exists('if_route_pattern')) {
/**
* Check the current route name with one or some patterns.
Expand All @@ -90,7 +84,6 @@ function if_route_pattern($patterns)
return app('active')->checkRoutePattern($patterns);
}
}

if (!function_exists('if_route_param')) {
/**
* Check if the parameter of the current route has the correct value.
Expand All @@ -105,7 +98,6 @@ function if_route_param($param, $value)
return app('active')->checkRouteParam($param, $value);
}
}

if (!function_exists('if_action')) {
/**
* Return 'active' class if current route action match one of provided action names.
Expand All @@ -119,7 +111,6 @@ function if_action($actions)
return app('active')->checkAction($actions);
}
}

if (!function_exists('if_controller')) {
/**
* Check if the current controller class matches one of specific values.
Expand All @@ -133,10 +124,9 @@ function if_controller($controllers)
return app('active')->checkController($controllers);
}
}

if (!function_exists('current_controller')) {
/**
* Get the current controller class.
* Get the current controller class
*
* @return string
*/
Expand All @@ -145,10 +135,9 @@ function current_controller()
return app('active')->getController();
}
}

if (!function_exists('current_method')) {
/**
* Get the current controller method.
* Get the current controller method
*
* @return string
*/
Expand All @@ -157,15 +146,14 @@ function current_method()
return app('active')->getMethod();
}
}

if (!function_exists('current_action')) {
/**
* Get the current action string.
* Get the current action string
*
* @return string
*/
function current_action()
{
return app('active')->getAction();
}
}
}
47 changes: 9 additions & 38 deletions app/Providers/ActiveServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActiveServiceProvider extends ServiceProvider
public function boot()
{
// Update the instances each time a request is resolved and a route is matched
$instance = new Active(request());
$instance = app('active');

if (version_compare(Application::VERSION, '5.2.0', '>=')) {
app('router')->matched(
Expand All @@ -44,42 +44,13 @@ function ($route, $request) use ($instance) {
*/
public function register()
{
$this->registerActive();
$this->registerFacade();

// $this->app->singleton(
// 'active',
// function ($app) {

// $instance = new Active($app['router']->getCurrentRequest());

// return $instance;
// }
// );
}

/**
* Register the application bindings.
*
* @return void
*/
private function registerActive()
{
$this->app->bind('active', function ($app) {
return new Active($app['router']->getCurrentRequest());
});
}

/**
* Register the vault facade without the user having to add it to the app.php file.
*
* @return void
*/
public function registerFacade()
{
$this->app->booting(function () {
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Active', \App\Services\Access\Facades\Active::class);
});
$this->app->singleton(
'active',
function ($app) {
$instance = new Active($app['router']->getCurrentRequest());

return $instance;
}
);
}
}
Loading