動態 ACL 檢查
建立一個 Security 類來執行 ACL 邏輯。
<?php
namespace Plugins;
use Phalcon\Events\Event;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Acl;
use Phalcon\Acl\Role;
use Phalcon\Acl\Resource;
use Phalcon\Acl\Adapter\Memory as AclList;
class Security extends \Phalcon\Mvc\User\Plugin
{
public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
{
// your acl logic here
}
}
將 Security 類掛鉤到排程程式,以在 beforeExecuteRoute 上執行。
$di = new \Phalcon\DI\FactoryDefault();
$eventsManager = $di['eventsManager'];
$di->setShared('dispatcher', function() use ($eventsManager) {
$eventsManager->attach('dispatch:beforeExecuteRoute', new \Plugins\Security);
$dispatcher = new \Phalcon\Mvc\Dispatcher;
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});