예제 #1
0
파일: HookTest.php 프로젝트: UnionCMS/Core
 /**
  * Test hook components configure.
  *
  * @return void
  */
 public function testHooConfigureComponent()
 {
     $configKey = Hook::HOOK_CONFIG_KEY . '.' . Hook::HOOK_CONFIG_COMPONENT_KEY;
     //  Clear hook configure components.
     Configure::write($configKey, []);
     Hook::component('Simple', ['Pages']);
     $this->assertSame(['Simple' => ['controllers' => ['Pages']]], Configure::read($configKey));
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     Hook::component('Test', '*');
     $expected = ['Simple' => ['controllers' => ['Pages']], 'Test' => ['controllers' => '*']];
     $this->assertSame($expected, Configure::read($configKey));
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     Hook::component('Test', '*');
     $expected = ['Simple' => ['controllers' => ['Pages']], 'Test' => ['controllers' => '*']];
     $this->assertSame($expected, Configure::read($configKey));
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     Hook::component('Test', ['Users', 'Items']);
     $expected = ['Simple' => ['controllers' => ['Pages']], 'Test' => ['controllers' => '*']];
     $this->assertSame($expected, Configure::read($configKey));
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     Hook::component('Time', '*', ['param-1' => 'value-1', 'param-2' => 'value-2']);
     $expected = ['Simple' => ['controllers' => ['Pages']], 'Test' => ['controllers' => '*'], 'Time' => ['controllers' => '*', 'config' => ['param-1' => 'value-1', 'param-2' => 'value-2']]];
     $this->assertSame($expected, Configure::read($configKey));
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     Hook::component('Html', ['Users', 'Favorites', 'Pages'], ['param-1' => 'value-1', 'param-2' => 'value-2', 'param-3' => 'value-3']);
     $expected = ['Simple' => ['controllers' => ['Pages']], 'Test' => ['controllers' => '*'], 'Time' => ['controllers' => '*', 'config' => ['param-1' => 'value-1', 'param-2' => 'value-2']], 'Html' => ['controllers' => ['Users', 'Favorites', 'Pages'], 'config' => ['param-1' => 'value-1', 'param-2' => 'value-2', 'param-3' => 'value-3']]];
     $this->assertSame($expected, Configure::read($configKey));
 }
예제 #2
0
<?php

/**
 * UnionCMS Community
 *
 * This file is part of the of the simple cms based on CakePHP 3.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package   Community
 * @license   MIT
 * @copyright MIT License http://www.opensource.org/licenses/mit-license.php
 * @link      https://github.com/UnionCMS/Community
 * @author    Sergey Kalistratov <*****@*****.**>
 */
use Cake\Cache\Cache;
use Cake\Core\Configure;
use Union\Core\Utility\Hook;
Hook::helper('Union/Community.Acl', ['Permissions']);
Hook::component('Auth', '*', ['className' => 'Union/Community.Auth', 'loginAction' => ['plugin' => 'Union/Community', 'controller' => 'Users', 'action' => 'login'], 'unauthorizedRedirect' => ['plugin' => 'Union/Community', 'controller' => 'Users', 'action' => 'login'], 'logoutRedirect' => ['plugin' => 'Union/Community', 'controller' => 'Users', 'action' => 'login'], 'authenticate' => ['Form' => ['contain' => 'Roles', 'userModel' => 'Union/Community.Users', 'scope' => ['Users.status' => PUBLISH_STATUS]]], 'authorize' => ['Union/Community.Base'], 'authError' => __d('community', 'You are not authorized to access that location.')]);
Hook::component('Acl.Acl', '*');
Hook::component('Union/Community.Community', '*');
Configure::write('Auth', ['loginBackendRedirect' => ['plugin' => 'Union/Community', 'controller' => 'Users', 'action' => 'index'], 'loginFrontendRedirect' => ['plugin' => 'Union/Community', 'controller' => 'Users', 'action' => 'edit']]);
//  Setup cache configuration for permissions.
Cache::config('permissions', array_merge(Configure::read('Cache.defaultConfig'), ['groups' => ['acl'], 'duration' => '+2 hour']));
//  Setup cache configuration for role from aro.
Cache::config('permission_roles', array_merge(Configure::read('Cache.defaultConfig'), ['groups' => ['roles'], 'duration' => '+1 week']));