本文整理匯總了PHP中think\Hook::import方法的典型用法代碼示例。如果您正苦於以下問題:PHP Hook::import方法的具體用法?PHP Hook::import怎麽用?PHP Hook::import使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類think\Hook
的用法示例。
在下文中一共展示了Hook::import方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: run
/**
* @param mixed $content
*/
public function run(&$content)
{
/**
* //真不知道說什麽好。。。
* 這裏 原因是tp 不能把tag放在項目配置中,隻能放在common中,而common模塊先於install 初始化
* so。。。。。
*
*/
if (C('DB_TYPE') == 'GreenCMS_DB_TYPE') {
} else {
if (isset($_GET['m']) && strtolower($_GET['m']) == 'install') {
return;
}
$data = S('hooks');
if (!$data) {
$hooks = M('Hooks')->getField('name,addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = M('Addons')->where($map)->getField('id,name');
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, $addons);
}
}
}
S('hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
}
示例2: run
public function run(&$parms)
{
//安裝時不執行
if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
return;
}
$data = S('global_hooks');
if (!$data) {
$hooks = M('Hooks', "common_")->getField('name,addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = M('Addons', "common_")->where($map)->getField('id,name');
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, array_map('get_addon_class', $addons));
}
}
}
S('global_hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
示例3: run
public function run(&$content)
{
if (isset($_GET['m']) && $_GET['m'] === 'Install') {
return;
}
$data = S('hooks');
if (!$data) {
$hooks = M('Hooks')->getField('name,addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = M('Addons')->where($map)->getField('id,name');
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, array_map('get_addon_class', $addons));
}
}
}
S('hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
示例4: run
public function run(&$content)
{
if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
return;
}
$data = S('hooks');
if (!$data) {
$hooks = M('hooks')->getField('name,addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = (array) M('addons')->where($map)->getField('id,name');
$data_plugin = (array) M('plugin')->where($map)->getField('id,name');
$data = array_merge($data, $data_plugin);
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, array_map('get_addon_class', $addons));
}
}
}
S('hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
示例5: run
public function run(&$content)
{
if (!file_exist(UPLOAD_PATH . 'install.lock')) {
return true;
}
$data = S('common_behavior_hooks');
if (!$data) {
$hooks = M('hooks')->where(array('status' => 1))->getField('name, addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = M('addons')->where($map)->getField('id, name');
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, array_map('get_addon_class', $addons));
}
}
}
S('common_behavior_hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
示例6: run
/**
* 行為擴展的執行入口必須是run
* @author jry <598821125@qq.com>
*/
public function run(&$content)
{
// 安裝模式下直接返回
if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
return;
}
// 添加插件配置
$addon_config['ADDON_PATH'] = './Addons/';
$addon_config['AUTOLOAD_NAMESPACE'] = C('AUTOLOAD_NAMESPACE');
$addon_config['AUTOLOAD_NAMESPACE']['Addons'] = $addon_config['ADDON_PATH'];
C($addon_config);
$data = S('hooks');
if (!$data || APP_DEBUG === true) {
$hooks = D('Admin/Hook')->getField('name,addons');
foreach ($hooks as $key => $value) {
if ($value) {
$map['status'] = 1;
$names = explode(',', $value);
$map['name'] = array('IN', $names);
$data = D('Admin/Addon')->where($map)->getField('id,name');
if ($data) {
$addons = array_intersect($names, $data);
Hook::add($key, array_map('get_addon_class', $addons));
}
}
}
S('hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
示例7: testImport
public function testImport()
{
Hook::import(['my_pos' => ['\\tests\\thinkphp\\library\\think\\behavior\\One', '\\tests\\thinkphp\\library\\think\\behavior\\Three']]);
Hook::import(['my_pos' => ['\\tests\\thinkphp\\library\\think\\behavior\\Two']], false);
Hook::import(['my_pos' => ['\\tests\\thinkphp\\library\\think\\behavior\\Three', '_overlay' => true]]);
$data['id'] = 0;
$data['name'] = 'thinkphp';
Hook::listen('my_pos', $data);
$this->assertEquals(3, $data['id']);
}
示例8: init
private static function init()
{
// 加載初始化文件
if (is_file(APP_PATH . 'init' . EXT)) {
include APP_PATH . 'init' . EXT;
// 加載模塊配置
$config = Config::get();
} else {
// 加載模塊配置
$config = Config::load(APP_PATH . 'config' . EXT);
// 加載應用狀態配置
if ($config['app_status']) {
$config = Config::load(APP_PATH . $config['app_status'] . EXT);
}
// 讀取擴展配置文件
if ($config['extra_config_list']) {
foreach ($config['extra_config_list'] as $name => $file) {
$filename = APP_PATH . $file . EXT;
Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
}
}
// 加載別名文件
if (is_file(APP_PATH . 'alias' . EXT)) {
Loader::addMap(include APP_PATH . 'alias' . EXT);
}
// 加載行為擴展文件
if (APP_HOOK && is_file(APP_PATH . 'tags' . EXT)) {
Hook::import(include APP_PATH . 'tags' . EXT);
}
// 加載公共文件
if (is_file(APP_PATH . 'common' . EXT)) {
include APP_PATH . 'common' . EXT;
}
}
// 注冊根命名空間
if (!empty($config['root_namespace'])) {
Loader::addNamespace($config['root_namespace']);
}
// 加載額外文件
if (!empty($config['extra_file_list'])) {
foreach ($config['extra_file_list'] as $file) {
$file = strpos($file, '.') ? $file : APP_PATH . $file . EXT;
if (is_file($file)) {
include_once $file;
}
}
}
// 設置係統時區
date_default_timezone_set($config['default_timezone']);
// 監聽app_init
APP_HOOK && Hook::listen('app_init');
}
示例9: run
public function run(&$content)
{
if (isset($_GET['g']) && strtolower($_GET['g']) === 'install') {
return;
}
$data = S('hooks');
if (!$data) {
is_array($plugins = M('Plugins')->where("status=1")->getField("name,hooks")) ? null : ($plugins = array());
foreach ($plugins as $plugin => $hooks) {
if ($hooks) {
$hooks = explode(",", $hooks);
foreach ($hooks as $hook) {
Hook::add($hook, $plugin);
}
}
}
S('hooks', Hook::get());
} else {
Hook::import($data, false);
}
}
示例10: initModule
private static function initModule($module, $config)
{
// 定位模塊目錄
$module = COMMON_MODULE == $module || !APP_MULTI_MODULE ? '' : $module . DS;
// 加載初始化文件
if (is_file(APP_PATH . $module . 'init' . EXT)) {
include APP_PATH . $module . 'init' . EXT;
} else {
$path = APP_PATH . $module;
// 加載模塊配置
$config = Config::load(APP_PATH . $module . 'config' . CONF_EXT);
// 加載應用狀態配置
if ($config['app_status']) {
$config = Config::load(APP_PATH . $module . $config['app_status'] . CONF_EXT);
}
// 讀取擴展配置文件
if ($config['extra_config_list']) {
foreach ($config['extra_config_list'] as $name => $file) {
$filename = $path . $file . CONF_EXT;
Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
}
}
// 加載別名文件
if (is_file($path . 'alias' . EXT)) {
Loader::addMap(include $path . 'alias' . EXT);
}
// 加載行為擴展文件
if (APP_HOOK && is_file($path . 'tags' . EXT)) {
Hook::import(include $path . 'tags' . EXT);
}
// 加載公共文件
if (is_file($path . 'common' . EXT)) {
include $path . 'common' . EXT;
}
// 加載當前模塊語言包
if ($config['lang_switch_on'] && $module) {
Lang::load($path . 'lang' . DS . LANG_SET . EXT);
}
}
}
示例11: init
/**
* 初始化應用或模塊
* @access public
* @param string $module 模塊名
* @return array
*/
private static function init($module = '')
{
// 定位模塊目錄
$module = $module ? $module . DS : '';
// 加載初始化文件
if (is_file(APP_PATH . $module . 'init' . EXT)) {
include APP_PATH . $module . 'init' . EXT;
} else {
$path = APP_PATH . $module;
// 加載模塊配置
$config = Config::load(CONF_PATH . $module . 'config' . CONF_EXT);
// 加載應用狀態配置
if ($config['app_status']) {
$config = Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
}
// 讀取擴展配置文件
if ($config['extra_config_list']) {
foreach ($config['extra_config_list'] as $name => $file) {
$filename = CONF_PATH . $module . $file . CONF_EXT;
Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
}
}
// 加載別名文件
if (is_file(CONF_PATH . $module . 'alias' . EXT)) {
Loader::addClassMap(include CONF_PATH . $module . 'alias' . EXT);
}
// 加載行為擴展文件
if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
Hook::import(include CONF_PATH . $module . 'tags' . EXT);
}
// 加載公共文件
if (is_file($path . 'common' . EXT)) {
include $path . 'common' . EXT;
}
// 加載當前模塊語言包
if ($config['lang_switch_on'] && $module) {
Lang::load($path . 'lang' . DS . Request::instance()->langset() . EXT);
}
}
return Config::get();
}
示例12: __construct
public function __construct()
{
//支持方法
if (!$this->allowMethod) {
$this->allowMethod = explode(",", strtolower(SUPPORTED_METHOD));
}
//session token
if (I('server.HTTP_TOKEN')) {
session(array('id' => I("server.HTTP_TOKEN"), 'expire' => 1800));
session('[start]');
$this->user = I("session.user");
$this->is_super_user = $this->user['is_super_user'];
if (isset($_SESSION['user']) && (!get_current_company_id() || !get_current_user_id())) {
return $this->login_required();
}
}
tag('before_controller_construct');
parent::__construct();
// 當前請求 =》 auth_node
$this->current_action_all = sprintf("%s.%s.%s.%s", lcfirst(MODULE_NAME), lcfirst(CONTROLLER_NAME), lcfirst(ACTION_NAME), $this->_method);
//當前用戶所屬公司
if ($this->user or true) {
$this->company = D("Account/Company")->relation(true)->find(get_current_company_id());
}
//當前公司啟用應用
$this->activeApps = $this->baseApps;
if ($this->company) {
$this->activeApps = array_merge($this->activeApps, get_array_by_field($this->company['apps'], "alias"));
}
//啟用應用
AppService::active($this->activeApps, $this->baseApps);
//當前模塊前端別名
$this->module_alias = __(sprintf('%s.%s', lcfirst(MODULE_NAME), lcfirst(CONTROLLER_NAME)));
//導入非當前應用的插件及函數等信息
foreach ($this->activeApps as $app) {
$app = ucfirst($app);
if ($app == APP_NAME or $app == "common") {
continue;
}
// 插件
if (is_file(APPLICATION_PATH . $app . '/Conf/tags.php')) {
\Think\Hook::import(require APPLICATION_PATH . $app . '/Conf/tags.php');
}
// 函數
if (is_file(APPLICATION_PATH . $app . '/Common/function.php')) {
require_once APPLICATION_PATH . $app . '/Common/function.php';
}
}
//基本運行配置
$this->bootstrapConfigs = parse_yml(ENTRY_PATH . '/config.yaml');
//當前接口版本
if (I('server.HTTP_API_VERSION')) {
define('API_VERSION', I('server.HTTP_API_VERSION'));
} else {
define('API_VERSION', false);
}
//當前語言
$this->currentLanguage = $this->bootstrapConfigs["default_language"] ? $this->bootstrapConfigs["default_language"] : 'zh-cn';
if (I("server.HTTP_CLIENT_LANGUAGE")) {
$this->currentLanguage = I("server.HTTP_CLIENT_LANGUAGE");
}
if (I('get.lang')) {
$this->currentLanguage = I('get.lang');
}
define('CURRENT_LANGUAGE', $this->currentLanguage);
/*
* 解析應用配置
* * */
$cachedAppConfig = S("configs/app/all");
if (DEBUG or !$cachedAppConfig) {
foreach (new RecursiveFileFilterIterator(APP_PATH, "config.yml") as $item) {
$app = lcfirst(basename(dirname($item)));
$this->appConfigs[$app] = parse_yml($item);
}
S("configs/app/all", $this->appConfigs);
} else {
if (!DEBUG && $cachedAppConfig) {
$this->appConfigs = $cachedAppConfig;
}
}
AppService::$allAppConfigs = $this->appConfigs;
foreach ($this->appConfigs as $app => $config) {
$this->bootstrapConfigs['auth_dont_need_login'] = array_merge_recursive($this->bootstrapConfigs['auth_dont_need_login'], (array) $config['auth_dont_need_login']);
$this->bootstrapConfigs['auth_dont_need_check'] = array_merge_recursive($this->bootstrapConfigs['auth_dont_need_check'], (array) $config['auth_dont_need_check']);
}
// 當前表名
if (!$this->model_name) {
$this->model_name = ucfirst(CONTROLLER_NAME);
}
// 獲得用戶已授權節點
$authed_nodes = session('authed_nodes');
if (DEBUG || !$authed_nodes) {
$authed_nodes = D('Account/Authorize')->get_authed_nodes();
session('authed_nodes', $authed_nodes);
}
self::$authed_nodes = $authed_nodes;
AuthorizeService::set_authed_nodes($authed_nodes);
//當前動作權限檢測
// @todo event, event_get
$current_node_auth_flag = DEBUG ? 1 : $this->check_permission();
//.........這裏部分代碼省略.........
示例13: initModule
/**
* 初始化模塊
* @access private
* @return void
*/
private static function initModule($path, &$config)
{
// 加載初始化文件
if (is_file($path . 'init' . EXT)) {
include $path . 'init' . EXT;
} else {
// 檢測配置文件
if (is_file($path . 'config' . EXT)) {
$config = Config::set(include $path . 'config' . EXT);
}
// 檢測額外配置
if ($config['extra_config_list']) {
foreach ($config['extra_config_list'] as $conf) {
if (is_file($path . $conf . EXT)) {
$config = Config::set(include $path . $conf . EXT);
}
}
}
// 加載應用狀態配置文件
if ($config['app_status'] && is_file($path . $config['app_status'] . EXT)) {
$config = Config::set(include $path . $config['app_status'] . EXT);
}
// 加載別名文件
if (is_file($path . 'alias' . EXT)) {
Loader::addMap(include $path . 'alias' . EXT);
}
// 加載公共文件
if (is_file($path . 'common' . EXT)) {
include $path . 'common' . EXT;
}
// 加載行為擴展文件
if (is_file($path . 'tags' . EXT)) {
Hook::import(include $path . 'tags' . EXT);
}
}
}
示例14: init
/**
* 初始化應用或模塊
* @access public
* @param string $module 模塊名
* @return array
*/
private static function init($module = '')
{
// 定位模塊目錄
$module = $module ? $module . DS : '';
// 加載初始化文件
if (is_file(APP_PATH . $module . 'init' . EXT)) {
include APP_PATH . $module . 'init' . EXT;
} elseif (is_file(RUNTIME_PATH . $module . 'init' . EXT)) {
include RUNTIME_PATH . $module . 'init' . EXT;
} else {
$path = APP_PATH . $module;
// 加載模塊配置
$config = Config::load(CONF_PATH . $module . 'config' . CONF_EXT);
// 讀取數據庫配置文件
$filename = CONF_PATH . $module . 'database' . CONF_EXT;
Config::load($filename, 'database');
// 讀取擴展配置文件
if (is_dir(CONF_PATH . $module . 'extra')) {
$dir = CONF_PATH . $module . 'extra';
$files = scandir($dir);
foreach ($files as $file) {
if (strpos($file, CONF_EXT)) {
$filename = $dir . DS . $file;
Config::load($filename, pathinfo($file, PATHINFO_FILENAME));
}
}
}
// 加載應用狀態配置
if ($config['app_status']) {
$config = Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
}
// 加載行為擴展文件
if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
Hook::import(include CONF_PATH . $module . 'tags' . EXT);
}
// 加載公共文件
if (is_file($path . 'common' . EXT)) {
include $path . 'common' . EXT;
}
// 加載當前模塊語言包
if ($module) {
Lang::load($path . 'lang' . DS . Request::instance()->langset() . EXT);
}
}
return Config::get();
}
示例15: start
/**
* 啟動模擬應用
*/
public function start()
{
spl_autoload_register('\\Think\\PhpunitHelper::autoload');
register_shutdown_function('\\Think\\PhpunitHelper::fatalError');
Storage::connect(STORAGE_TYPE);
$mode = (include is_file(CONF_PATH . 'core.php') ? CONF_PATH . 'core.php' : MODE_PATH . APP_MODE . '.php');
// 加載核心文件
foreach ($mode['core'] as $file) {
if (is_file($file)) {
if (strpos($file, 'Think/Controller.class.php') !== false || strpos($file, 'Think\\Controller.class.php') !== false || strpos($file, 'Think/View.class.php') !== false || strpos($file, 'Think\\View.class.php') !== false) {
// not include
} else {
include_once $file;
}
}
}
// 加載應用模式配置文件
foreach ($mode['config'] as $key => $file) {
is_numeric($key) ? C(load_config($file)) : C($key, load_config($file));
}
// 讀取當前應用模式對應的配置文件
if ('common' != APP_MODE && is_file(CONF_PATH . 'config_' . APP_MODE . CONF_EXT)) {
C(load_config(CONF_PATH . 'config_' . APP_MODE . CONF_EXT));
}
// 加載模式別名定義
if (isset($mode['alias'])) {
self::addMap(is_array($mode['alias']) ? $mode['alias'] : (include $mode['alias']));
}
// 加載應用別名定義文件
if (is_file(CONF_PATH . 'alias.php')) {
self::addMap(include CONF_PATH . 'alias.php');
}
// 加載模式行為定義
if (isset($mode['tags'])) {
\Think\Hook::import(is_array($mode['tags']) ? $mode['tags'] : (include $mode['tags']));
}
// 加載應用行為定義
if (is_file(CONF_PATH . 'tags.php')) {
// 允許應用增加開發模式配置定義
\Think\Hook::import(include CONF_PATH . 'tags.php');
}
// 加載框架底層語言包
L(include THINK_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php');
// 調試模式加載係統默認的配置文件
C(include THINK_PATH . 'Conf/debug.php');
// 讀取應用調試配置文件
if (is_file(CONF_PATH . 'debug' . CONF_EXT)) {
C(include CONF_PATH . 'debug' . CONF_EXT);
}
C('HTML_CACHE_ON', false);
C('LIMIT_ROBOT_VISIT', false);
C('LIMIT_PROXY_VISIT', false);
$this->run();
}