<commit_before><?php

namespace UghAuthorization\Guards;

use UghAuthorization\Authorization\AuthorizationService;

class ControllerGuard implements Guard
{

    /** @var AuthorizationService */
    private $authorizationService;
    private $rules;

    public function __construct(AuthorizationService $authorizationService, array $rules)
    {
        $this->authorizationService = $authorizationService;
        $this->rules = $rules;
    }

    public function isGranted($permission)
    {
        $controllerName = $permission['controller'];
        $actionName = $permission['action'];

        $allowedRoles = $this->getAllowedRolesByControllerAction($controllerName, $actionName);

        return $this->authorizationService->matchIdentityRoles($allowedRoles);
    }

    public function getAllowedRolesByControllerAction($controllerName, $actionName)
    {
        $allowedRoles = array();

        foreach ($this->rules as $controller) {
            if (fnmatch($controller['controller'], $controllerName) &&
                    in_array($actionName, $controller['actions'])) {
                $allowedRoles = array_merge($allowedRoles, $controller['roles']);
            }
        }

        return $allowedRoles;
    }
}<commit_msg>fixed fnmatch bug<commit_after><?php

namespace UghAuthorization\Guards;

use UghAuthorization\Authorization\AuthorizationService;

class ControllerGuard implements Guard
{

    /** @var AuthorizationService */
    private $authorizationService;
    private $rules;

    public function __construct(AuthorizationService $authorizationService, array $rules)
    {
        $this->authorizationService = $authorizationService;
        $this->rules = $rules;
    }

    public function isGranted($permission)
    {
        $controllerName = $permission['controller'];
        $actionName = $permission['action'];

        $allowedRoles = $this->getAllowedRolesByControllerAction($controllerName, $actionName);

        return $this->authorizationService->matchIdentityRoles($allowedRoles);
    }

    public function getAllowedRolesByControllerAction($controllerName, $actionName)
    {
        $allowedRoles = array();

        foreach ($this->rules as $controller) {
            if ($controller['controller'] == $controllerName &&
                    in_array($actionName, $controller['actions'])) {
                $allowedRoles = array_merge($allowedRoles, $controller['roles']);
            }
        }

        return $allowedRoles;
    }
}
{'fraction_non_alphanumeric': 0.11218335343787696, 'fraction_numerical': 0.0, 'mean_word_length': 3.2896551724137932, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '6431835', 'n_tokens_mistral': 637, 'n_tokens_neox': 629, 'n_words': 116}