protected function createAcl()
    {

        if (!$this->getDI()->has('cache')) {
            throw new Exception('Please initialize the cache service!');
        }

        $cache = $this->getDI()->get('cache');
        if ($cache->get('acl') === null) {

            $roles = $this->roleEntity->find();


            \FhpPhalconHelper\Config::checkRequiredConfig($this->getDI(), ['authentication' => ['guestRole']]);
            $aclRole = new Acl\Role($this->config->authentication->guestRole);
            $this->acl->addRole($aclRole);

            //public routes
            $routesResult = \FhpPhalconAuth\Entity\Route::find('version IN("'.implode('","',\FhpPhalconAuth\Service\Route::$public).'")');
            foreach ($routesResult as $route) {
                $this->acl->addResource(new Resource($route->getController(), $route->getName()), $route->getAction());
                $this->acl->allow('*', $route->getController(), $route->getAction());
            }

            /** @var Role $role */
            foreach ($roles as $role) {

                $aclRole = new Acl\Role($role->getName(), $role->getDescription());
                $this->acl->addRole($aclRole);

                foreach ($role->getRoutes() as $route) {
                    $route = $route->getRoute();
                    $this->acl->addResource(new Resource($route->getController(), $route->getName()), $route->getAction());
                    $this->acl->allow($role->getName(), $route->getController(), $route->getAction());
                }
            }

            foreach ($roles as $role) {
                foreach ($role->getChildren() as $child) {
                    $this->acl->addInherit($role->getName(), $child->getChild()->getName());
                }
            }

            $cache->save('acl', serialize($this->acl));
        } else {
            $this->acl = unserialize($cache->get('acl'));
        }

        $this->getDI()->setShared('acl', $this->acl);
    }