westdc-zf1/vendor/Sookon/Authentication/AclResource.php

87 lines
1.5 KiB
PHP

<?php
namespace Sookon\Authentication;
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Resource\GenericResource as Resource;
use Sookon\Helpers\View as view;
class AclResource
{
public $acl;
public $config = array(
'Admin\Controller\Index',
'Admin\Controller\Article',
'Admin\Controller\Category',
'Admin\Controller\Metadata',
'Admin\Controller\Users',
//index
'Application\Controller\Index',
//account
'Application\Controller\Account' => array(
'login',
'logout',
'register',
'forgotpassword',
'getpassword',
'captcha',
'index'
),
//service
'Application\Controller\Service' => array(
'upload',
'delatt',
'thumb',
'bigthumb'
),
'Article\Controller\Article' => array(
'index',
'view'
),
'Article\Controller\Category' => array(
'index',
'list'
),
'Metadata\Controller\Index',
);
function __construct(Acl &$acl)
{
$this->acl = $acl;
$this->loadResource();
$acl = $this->acl;
}
public function loadResource()
{
foreach($this->config as $index => $resource)
{
if(!is_array($resource))
{
$this->acl->addResource(new Resource($resource));
continue;
}
$this->acl->addResource(new Resource($index));
foreach($resource as $action)
{
if($this->acl->hasResource($action))
{
continue;
}
$this->acl->addResource(new Resource($action),$index);
}
}
}
}