<commit_before><?php

namespace Jaztec\Service;

use Jaztec\Acl\AclAwareInterface;
use Jaztec\Cache\CacheAwareInterface;
use Jaztec\Acl\Acl as JaztecAcl;

use Zend\Cache\Storage\StorageInterface;

class AclService extends AbstractService implements 
    AclAwareInterface,
    CacheAwareInterface
{
    /** @var \Jaztec\Acl\Acl $acl */
    protected $acl;
    
    /** @var \ZfcUser\Controller\Plugin\ZfcUserAuthentication $userAuth */
    protected $userAuth;
    
    /** @var \Doctrine\ORM\EntityManager $em */
    protected $em;
    
    /** @var \Zend\Cache\Storage\StorageInterface */
    protected $cacheStorage;
    
    /**
     * @param \Zend\Cache\Storage\StorageInterface $storage
     */
    public function setCacheStorage(StorageInterface $storage)
    {
        $this->cacheStorage = $storage;
    }
    
    /**
     * @return \Zend\Cache\Storage\StorageInterface
     */
    public function getCacheStorage()
    {
        return $this->cacheStorage;
    }
    
    /**
     * @return @\Jaztec\Acl\Acl 
     */
    public function getAcl() {
        return $this->acl;
    }

    /**
     * @param \Jaztec\Acl\Acl $acl
     * @return \Jaztec\Acl\Acl 
     */
    public function setAcl(JaztecAcl $acl) {
        $this->acl = $acl;
    }

    /**
     * @return \ZfcUser\Controller\Plugin\ZfcUserAuthentication
     */
    public function getUserAuth() {
        return $this->userAuth;
    }

    /**
     * @param \ZfcUser\Controller\Plugin\ZfcUserAuthentication $userAuth
     * @return \Jaztec\Acl\Acl 
     */
    public function setUserAuth(\ZfcUser\Controller\Plugin\ZfcUserAuthentication $userAuth) {
        $this->userAuth = $userAuth;
        return $this;
    }
    
    /**
     * @return \Doctrine\ORM\EntityManager
     */
    public function getEntityManager() {
        if(null === $this->em) {
            $this->setEntityManager($this->getServiceLocator()->get('doctrine.entitymanager.orm_default'));
        }
        return $this->em;
    }
    
    /**
     * @param \Doctrine\ORM\EntityManager $em 
     */
    public function setEntityManager(\Doctrine\ORM\EntityManager $em) {
        $this->em = $em;
    }
    
    /**
     * @param Zend\Acl\Role\RoleInterface|string $role
     * @param Zend\Acl\Role\RoleInterface|string $resource
     * @param string $privilege
     * 
     * @return bool
     */
    public function isAllowed($role, $resource, $privilege) {
        $acl = $this->getAcl();
        
        if(!$acl->isLoaded()) {
            $cache = $this->getCacheStorage();
            $acl->setupAcl($this->getEntityManager());
            if($cache->hasItem('jaztec_acl'))
                $cache->removeItem('jaztec_acl');
            $cache->addItem('jaztec_acl', $acl); 
        }
        
        // Controleer of de resource bestaat
        if(!$acl->hasResource($resource)) {
            return false;
        }
        
        return $acl->isAllowed($role, $resource, $privilege);
    }
}<commit_msg>Ook in de service zorgen dat cache uitgeschakelt is.<commit_after><?php

namespace Jaztec\Service;

use Jaztec\Acl\AclAwareInterface;
use Jaztec\Cache\CacheAwareInterface;
use Jaztec\Acl\Acl as JaztecAcl;

use Zend\Cache\Storage\StorageInterface;

class AclService extends AbstractService implements 
    AclAwareInterface,
    CacheAwareInterface
{
    /** @var \Jaztec\Acl\Acl $acl */
    protected $acl;
    
    /** @var \ZfcUser\Controller\Plugin\ZfcUserAuthentication $userAuth */
    protected $userAuth;
    
    /** @var \Doctrine\ORM\EntityManager $em */
    protected $em;
    
    /** @var \Zend\Cache\Storage\StorageInterface */
    protected $cacheStorage;
    
    /**
     * @param \Zend\Cache\Storage\StorageInterface $storage
     */
    public function setCacheStorage(StorageInterface $storage)
    {
        $this->cacheStorage = $storage;
    }
    
    /**
     * @return \Zend\Cache\Storage\StorageInterface
     */
    public function getCacheStorage()
    {
        return $this->cacheStorage;
    }
    
    /**
     * @return @\Jaztec\Acl\Acl 
     */
    public function getAcl() {
        return $this->acl;
    }

    /**
     * @param \Jaztec\Acl\Acl $acl
     * @return \Jaztec\Acl\Acl 
     */
    public function setAcl(JaztecAcl $acl) {
        $this->acl = $acl;
    }

    /**
     * @return \ZfcUser\Controller\Plugin\ZfcUserAuthentication
     */
    public function getUserAuth() {
        return $this->userAuth;
    }

    /**
     * @param \ZfcUser\Controller\Plugin\ZfcUserAuthentication $userAuth
     * @return \Jaztec\Acl\Acl 
     */
    public function setUserAuth(\ZfcUser\Controller\Plugin\ZfcUserAuthentication $userAuth) {
        $this->userAuth = $userAuth;
        return $this;
    }
    
    /**
     * @return \Doctrine\ORM\EntityManager
     */
    public function getEntityManager() {
        if(null === $this->em) {
            $this->setEntityManager($this->getServiceLocator()->get('doctrine.entitymanager.orm_default'));
        }
        return $this->em;
    }
    
    /**
     * @param \Doctrine\ORM\EntityManager $em 
     */
    public function setEntityManager(\Doctrine\ORM\EntityManager $em) {
        $this->em = $em;
    }
    
    /**
     * @param Zend\Acl\Role\RoleInterface|string $role
     * @param Zend\Acl\Role\RoleInterface|string $resource
     * @param string $privilege
     * 
     * @return bool
     */
    public function isAllowed($role, $resource, $privilege) {
        $acl = $this->getAcl();
        
        if(!$acl->isLoaded()) {
//            $cache = $this->getCacheStorage();
            $acl->setupAcl($this->getEntityManager());
//            if($cache->hasItem('jaztec_acl'))
//                $cache->removeItem('jaztec_acl');
//            $cache->addItem('jaztec_acl', $acl); 
        }
        
        // Controleer of de resource bestaat
        if(!$acl->hasResource($resource)) {
            return false;
        }
        
        return $acl->isAllowed($role, $resource, $privilege);
    }
}
{'fraction_non_alphanumeric': 0.1381678110869201, 'fraction_numerical': 0.0, 'mean_word_length': 2.143157894736842, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '5266108', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1894, 'n_words': 308}