<commit_before><?php

class Kebab_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{

    private $_acl;

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $identity = $auth->getIdentity();
            $role = strtolower($identity->role);
        } else {
            //KBBTODO Don't like it' Hardcoding is bad!
            $role = 'guest';
        }

        // Create mvcResource
        $module = ucfirst($request->getModuleName());
        $controller = ucfirst($request->getControllerName());
        $mvcResource = $module . '_' . $controller;
        $action = $request->getActionName();

        self::_setAcl();
        
        if (!$this->_acl->isAllowed($role, $mvcResource, $action)) {
            $request->setModuleName('default');
            $request->setControllerName('auth');
            $request->setActionName('login');
        }
    }

    private function _setAcl()
    {
        $acl = new Zend_Acl();

        //Add Role
        $acl->addRole(new Zend_Acl_Role('guest'));
        $acl->addRole(new Zend_Acl_Role('member'), 'guest');
        $acl->addRole(new Zend_Acl_Role('admin'), 'member');
        $acl->addRole(new Zend_Acl_Role('owner'), 'admin');

        //Add Resource
        $acl->add(new Zend_Acl_Resource('Default_Index'));
        $acl->add(new Zend_Acl_Resource('Default_Auth'));
        $acl->add(new Zend_Acl_Resource('Default_Error'));
        $acl->add(new Zend_Acl_Resource('Default_Main'));

        // Rules
        $acl->allow('guest', 'Default_Auth', array('login', 'logout'));
        $acl->allow('guest', 'Default_Error');
        $acl->allow('member', 'Default_Main');

        $this->_acl = $acl;
    }

}<commit_msg>Move ACL Rules to Kebab_Acl object<commit_after><?php

class Kebab_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{

    private $_acl;
    private $_roles = array();

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $identity = $auth->getIdentity();
            $this->_roles = $identity->roles;
            $this->_acl = $identity->acl;
        } else {
            //KBBTODO Don't like it' Hardcoding is bad!
            $this->_roles = array('guest');
            $this->_acl = new Kebab_Acl();
        }

        // Create mvcResource
        $module = ucfirst($request->getModuleName());
        $controller = ucfirst($request->getControllerName());
        $mvcResource = $module . '_' . $controller;
        $action = $request->getActionName();

        //Check Rules
        $isAllowed = FALSE;
        while (!$isAllowed && list(, $role) = each($this->_roles)) {
            $isAllowed = $this->_acl->isAllowed($role, $mvcResource, $action);
        }

        if (!$isAllowed) {
            $request->setModuleName('default');
            $request->setControllerName('auth');
            $request->setActionName('login');
        }
    }

}
{'fraction_non_alphanumeric': 0.15615906886517944, 'fraction_numerical': 0.0, 'mean_word_length': 2.441601779755284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '3826220', 'n_tokens_mistral': 937, 'n_tokens_neox': 911, 'n_words': 159}