<?php require_once 'Zend/Tool/Project/Provider/Abstract.php'; require_once 'Zend/Tool/Project/Provider/Exception.php'; class AuthProvider extends Zend_Tool_Project_Provider_Abstract { public function init() { defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); require_once 'Zend/Application.php'; $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap('db'); } public function allowActionAccess( $action = 'index', $controller = 'index', $module = 'default' ) { $this->init(); $ActionTable = new Application_Model_DbTable_Action(); $select = $ActionTable->select() ->where('module = ?', $module) ->where('controller = ?', $controller) ->where('action = ?', $action); $objAction = $ActionTable->fetchRow($select); if (!$objAction) { $dane = array( 'module' => $module, 'controller' => $controller, 'action' => $action, 'is_secure' => 0 ); $ActionTable->insert($dane); } $objAction['is_secure'] = 0; $objAction->save(); } public function disallowActionAccess( $action = 'index', $controller = 'index', $module = 'default' ) { $this->init(); $ActionTable = new Application_Model_DbTable_Action(); $select = $ActionTable->select() ->where('module = ?', $module) ->where('controller = ?', $controller) ->where('action = ?', $action); $objAction = $ActionTable->fetchRow($select); if (!$objAction) { $dane = array( 'module' => $module, 'controller' => $controller, 'action' => $action, 'is_secure' => 1 ); $ActionTable->insert($dane); } $objAction['is_secure'] = 1; $objAction->save(); } ... }
Listing 38.6. Zarys klasy AuthProvider
Rozdział 38. Ograniczanie uprawnień użytkowników