本文整理汇总了PHP中Hook::AddHook方法的典型用法代码示例。如果您正苦于以下问题:PHP Hook::AddHook方法的具体用法?PHP Hook::AddHook怎么用?PHP Hook::AddHook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hook
的用法示例。
在下文中一共展示了Hook::AddHook方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: try_mkdir
}
$cache_dir = CACHE_DIR . DIRECTORY_SEPARATOR . 'github_repo';
try_mkdir($cache_dir);
Hook::AddHook(Hook::FIND_POST_LIST, function (&$list) use($setting, $cache_dir) {
$files = array();
if (isset($setting['repos'])) {
foreach ($setting['repos'] as $repostring) {
$repo = new Repo($repostring);
$helper = new RepoHelper($repo);
$helper->setFileCacheDir($cache_dir);
try {
$tree = $helper->getTreeInPath();
$tree = array_filter($tree, function ($item) {
return $item['type'] === 'blob' && ParserFactory::CanParse($item['path']);
});
$files = array_merge($files, $helper->getAllLocalBlob($tree));
} catch (GitHubException $ex) {
throw $ex;
}
}
}
$list = array_merge($list, $files);
// 删除其余文件
$all = glob($cache_dir . DIRECTORY_SEPARATOR . '*');
$remove = array_diff($all, $files);
array_walk($remove, function ($fn) {
unlink($fn);
});
//var_dump($files,$all,$remove);
});
});
示例2: rssOratomAction
<?php
use FeedWriter\Atom;
use FeedWriter\RSS2;
Hook::AddHook(Hook::RESOLVE_REQUEST, 'rssOratomAction');
Hook::AddHook(Hook::RESOLVE_POST, 'basic_post_resolver');
Hook::AddHook(Hook::FIND_POST_LIST, 'posts_in_post_dir');
Hook::AddHook(Hook::RESOLVE_REQUEST, 'update_action');
Hook::AddHook(Hook::GENERATE_HEADER, 'generate_default_header');
Hook::AddHook(Hook::GENERATE_HEADER, 'generate_default_footer');
/**
* @param Request $request
*/
function rssOratomAction($request)
{
if (false == $request->isAction()) {
return;
}
$action = $request->getAction();
if (false == ($action == 'rss' || $action == 'atom')) {
return;
}
global $config, $postHelper;
$action == 'rss' ? $feed = new RSS2() : ($feed = new Atom());
$feed->setTitle(BLOG_TITLE);
$feed->setLink(BLOG_URL);
$feed->setEncoding('utf-8');
if ($action == 'rss') {
$feed->setDescription($config['meta_description']);
$feed->setChannelElement('language', $config['language']);
$feed->setChannelElement('pubDate', date(DATE_RSS, time()));
示例3: function
<?php
namespace github_helper;
include_once __DIR__ . '/github_helper.php';
\Hook::AddHook(\Hook::BOOTSTRAP, function () {
global $config;
// 可能不存在,抑制该错误
$setting = @$config[\Config::NS_PLUGINS][__NAMESPACE__];
if (is_null($setting)) {
$setting['auth'] = '';
$config->addDefault(__NAMESPACE__, $setting, <<<EOT
github_helper 辅助插件:
设置:
\tauth 作为访问 github 的授权,使用 BasicAuth
\t\t 格式为 username:password
repo格式为 user/repo[:branch][/path][;auth=username:password][;readmeonly]
EOT
, \Config::NS_PLUGINS);
}
});