<commit_before><?php

namespace ViKon\Auth;

use Illuminate\Routing\Router;

/**
 * Class RouterAuth
 *
 * @package ViKon\Auth
 *
 * @author  <NAME><<EMAIL>>
 */
class RouterAuth
{
    /** @type \Illuminate\Routing\Router */
    protected $router;

    /** @type \ViKon\Auth\Guard */
    protected $guard;

    /**
     * @param \Illuminate\Routing\Router $router
     * @param \ViKon\Auth\Guard          $guard
     */
    public function __construct(Router $router, Guard $guard)
    {
        $this->router = $router;
        $this->guard  = $guard;
    }

    /**
     * Check if current user has access to named route
     *
     * @param string $name named route name
     *
     * @return bool|null NULL if route not found, otherwise TRUE or FALSE depend if user has access to route or not
     */
    public function hasAccess($name)
    {
        if (($permissions = $this->getPermissions($name)) === null) {
            return null;
        }

        return $this->guard->hasPermissions(...$permissions);
    }

    /**
     * Get permissions for named route
     *
     * @param string $name named route named
     *
     * @return null NULL if route not found, otherwise array of permissions
     */
    public function getPermissions($name)
    {
        $route = $this->router->getRoutes()->getByName($name);

        // If route not exists, return NULL
        if ($route === null) {
            return null;
        }

        $permissions = [];

        // Get permission from permission middleware
        foreach ($route->middleware() as $middleware) {
            if (strpos($middleware, 'permission:') === 0) {
                list(, $permission) = explode(':', $middleware, 2);
                $permissions[] = $permission;
            }
        }<commit_msg>hasAccessCourrentRoute method added to RouterAuth service<commit_after><?php

namespace ViKon\Auth;

use Illuminate\Routing\Router;

/**
 * Class RouterAuth
 *
 * @package ViKon\Auth
 *
 * @author  <NAME><<EMAIL>>
 */
class RouterAuth
{
    /** @type \Illuminate\Routing\Router */
    protected $router;

    /** @type \ViKon\Auth\Guard */
    protected $guard;

    /**
     * @param \Illuminate\Routing\Router $router
     * @param \ViKon\Auth\Guard          $guard
     */
    public function __construct(Router $router, Guard $guard)
    {
        $this->router = $router;
        $this->guard  = $guard;
    }

    /**
     * Check if current user has access to named route
     *
     * @param string $name named route name
     *
     * @return bool|null NULL if route not found, otherwise TRUE or FALSE depend if user has access to route or not
     */
    public function hasAccess($name)
    {
        if (($permissions = $this->getPermissions($name)) === null) {
            return null;
        }

        return $this->guard->hasPermissions(...$permissions);
    }

    /**
     * Check if authenticated user has access to current route
     *
     * Note: Route have to have name
     *
     * @return bool|null NULL if route not found, otherwise TRUE or FALSE depend if user has access to route or not
     */
    public function hasAccessToCurrentRoute()
    {
        return $this->hasAccess($this->router->current()->getName());
    }

    /**
     * Get permissions for named route
     *
     * @param string $name named route named
     *
     * @return null NULL if route not found, otherwise array of permissions
     */
    public function getPermissions($name)
    {
        $route = $this->router->getRoutes()->getByName($name);

        // If route not exists, return NULL
        if ($route === null) {
            return null;
        }

        $permissions = [];

        // Get permission from permission middleware
        foreach ($route->middleware() as $middleware) {
            if (strpos($middleware, 'permission:') === 0) {
                list(, $permission) = explode(':', $middleware, 2);
                $permissions[] = $permission;
            }
        }
{'fraction_non_alphanumeric': 0.12628671855385387, 'fraction_numerical': 0.0010042681395932714, 'mean_word_length': 2.08359133126935, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1337120', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1124, 'n_words': 329}