本文整理汇总了PHP中Hook::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Hook::init方法的具体用法?PHP Hook::init怎么用?PHP Hook::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hook
的用法示例。
在下文中一共展示了Hook::init方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* 运行框架
*/
public static function run()
{
try {
self::init();
Hook::init(BASE_PATH);
Hook::listen('appBegin');
Hook::listen('routeParseUrl', array(Config::get('REWRITE_RULE'), Config::get('REWRITE_ON')));
//default route
if (!defined('APP_NAME') || !defined('CONTROLLER_NAME') || !defined('ACTION_NAME')) {
Route::parseUrl(Config::get('REWRITE_RULE'), Config::get('REWRITE_ON'));
}
//execute action
$controller = '\\app\\' . APP_NAME . '\\controller\\' . CONTROLLER_NAME . 'Controller';
$action = ACTION_NAME;
if (!class_exists($controller)) {
throw new \Exception("Controller '{$controller}' not found", 404);
}
$obj = new $controller();
if (!method_exists($obj, $action)) {
throw new \Exception("Action '{$controller}::{$action}()' not found", 404);
}
Hook::listen('actionBefore', array($obj, $action));
$obj->{$action}();
Hook::listen('actionAfter', array($obj, $action));
} catch (\Exception $e) {
Hook::listen('appError', array($e));
}
Hook::listen('appEnd');
}
示例2: getenv
/* config */
$dbUrl = getenv('DB_URL');
if ($dbUrl) {
$config->parse($dbUrl);
} else {
$config->set('dbType', 'sqlite');
$config->set('dbHost', ':memory:');
}
/* database */
Db::construct($config);
Db::init();
/* installer */
$installer = new Installer($config);
$installer->init();
$installer->rawDrop();
$installer->rawCreate();
$installer->insertData(['adminName' => 'Test', 'adminUser' => 'test', 'adminPassword' => 'test', 'adminEmail' => 'test@test.com']);
/* test user */
Db::forTablePrefix('users')->whereIdIs(1)->findOne()->set(['password' => 'test', 'description' => 'test', 'language' => 'en'])->save();
/* test module */
if (is_dir('modules/TestDummy')) {
$testDummy = new Modules\TestDummy\TestDummy();
$testDummy->install();
}
/* language */
$language = Language::getInstance();
$language->init();
/* hook */
Hook::construct($registry);
Hook::init();
示例3:
<?php
namespace Redaxscript;
/* include as needed */
include_once 'includes/Autoloader.php';
include_once 'stubs/hook_function.php';
include_once 'stubs/hook_method.php';
include_once 'TestCase.php';
/* init */
Autoloader::init();
Request::init();
/* set config */
Config::set('type', 'mysql');
Config::set('host', 'redaxscript.com');
Config::set('name', 'd01ae38a');
Config::set('user', 'd01ae38a');
Config::set('password', 'travis');
/* registry and config */
$registry = Registry::getInstance();
$config = Config::getInstance();
/* database and hook */
Db::init($config);
Hook::init($registry);
/* language */
$language = Language::getInstance();
$language::init('en');
示例4: function
Hook::init('init[].node_content', function () {
if (!cache('node__content_field')) {
Yii::import("application.modules.node.models.NodeContent");
Yii::import("application.modules.node.models.NodeField");
$rows = NodeContent::model()->findAll(array('order' => 'sort desc,id desc'));
if ($rows) {
foreach ($rows as $v) {
$data[$v->id] = $v->name;
$data2[$v->id] = array($v->name, $v->discription);
$id = $v->id;
foreach ($v->fields as $f) {
$field[$id]['id'] = $f->id;
$field[$id]['name'] = $f->name;
$field[$id]['type'] = $f->type;
$field[$id]['widget'] = $f->widget;
$field_table[$v->name][$f->name] = $f;
$d[$v->name]['id'] = 'id';
$d[$v->name]['vid'] = 'vid';
$d[$v->name]['display'] = 'display';
$d[$v->name]['uid'] = 'uid';
$d[$v->name]['uuid'] = 'uuid';
$d[$v->name]['language_id'] = 'language_id';
$d[$v->name]['created'] = 'created';
$d[$v->name]['updated'] = 'updated';
$d[$v->name][$f->name] = $f->name;
}
}
cache('node__content', $data);
cache('node__contentfull', $data2);
cache('node__field', $field);
cache('node__content_field', $d);
cache('node__field_table', $field_table);
}
}
});
示例5: hook
/**
* 对字段加载HOOK,改变relation 的值
*/
function hook()
{
Hook::init('model.NodeField_afterSave', function ($model) {
CDB()->update('node_field', array('relation' => "attachments." . $model->name), 'id=:id', array(':id' => $model->id));
});
}