本文整理匯總了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);
}
});