本文整理汇总了PHP中context函数的典型用法代码示例。如果您正苦于以下问题:PHP context函数的具体用法?PHP context怎么用?PHP context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了context函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: elggadmin_pagesetup
function elggadmin_pagesetup()
{
// first login?
global $CFG;
if (user_flag_get('admin', $_SESSION['userid']) && !isset($CFG->elggadmin_installed)) {
$CFG->elggadmin_installed = true;
set_config('elggadmin_installed', true);
header_redirect(get_url(null, 'elggadmin::config'), __gettext('Welcome to the Elgg configuration manager!'));
}
if (context() == 'admin') {
if (!plugin_is_loaded('pages')) {
elgg_messages_add(__gettext('Error: <code>elggadmin</code> plugin needs <code>pages</code> plugin to run'));
} else {
pages_submenu_add('elggadmin', __gettext('Site administration'), get_url(null, 'elggadmin::'), 10);
}
} elseif (context() == 'elggadmin') {
if (!plugin_is_loaded('pages')) {
elgg_messages_add(__gettext('Error: <code>elggadmin</code> plugin needs <code>pages</code> plugin to run'));
header_redirect(get_url(null, 'admin::'));
}
// submenu options
pages_submenu_add('elggadmin', __gettext('Configuration manager'), get_url(null, 'elggadmin::'));
pages_submenu_add('elggadmin:theme', __gettext('Default theme editor'), get_url(null, 'elggadmin::theme'));
pages_submenu_add('elggadmin:frontpage', __gettext('Frontpage template editor'), get_url(null, 'elggadmin::frontpage'));
pages_submenu_add('elggadmin:logs', __gettext('Error log'), get_url(null, 'elggadmin::logs'));
sidebar_add(50, 'sidebar-' . elggadmin_currentpage(), elggadmin_sidebar());
// clear sidebar
$clear_sidebar[] = 'sidebar-profile';
$clear_sidebar[] = 'sidebar-' . elggadmin_currentpage();
sidebar_remove($clear_sidebar, true);
if (elggadmin_is_404()) {
header('HTTP/1.0 404 Not Found');
}
}
}
示例2: dispatch
private static function dispatch()
{
$route = Utils::get('appDispatch');
if (!$route instanceof Container) {
context()->is404();
$route = container()->getRoute();
}
if (true !== container()->getIsDispatched()) {
if (true !== $route->getCache()) {
context()->dispatch($route);
} else {
$redis = context()->redis();
$key = sha1(serialize($route->assoc())) . '::routeCache';
$cached = $redis->get($key);
if (!strlen($cached)) {
ob_start();
context()->dispatch($route);
$cached = ob_get_contents();
ob_end_clean();
$redis->set($key, $cached);
$ttl = Config::get('application.route.cache', 7200);
$redis->expire($key, $ttl);
}
echo $cached;
}
}
}
示例3: register
/**
* Register options
*/
public function register()
{
if ($this->registered) {
return $this;
}
$hadStack = context()->exists(Stack::class);
if (!$hadStack) {
context()->bind(Stack::class, new Stack());
}
$this->registerAutoloaders($this->autoload());
$this->registerClassMaps($this->classMaps());
$this->registerApps($this->apps());
$this->registerProviders($this->providers());
$this->registerRoutes($this->routes());
$this->registerListeners($this->listeners());
$this->registerMiddlewares($this->middlewares());
$this->registerAfterwares($this->afterwares());
$this->registerPaths($this->paths());
$this->registerViewObjects($this->viewObjects());
$this->registerConsoles($this->consoles());
$this->registerAssets($this->assets());
if (method_exists($this, 'registered')) {
Reflect::method($this, 'registered');
}
$this->registered = true;
/**
* Some actions needs to be executed in reverse direction, for example config initialization.
*/
if (!$hadStack) {
$stack = context()->get(Stack::class);
$stack->execute();
}
return $this;
}
示例4: createEntity
/**
* @return Entity
*/
public function createEntity()
{
$repository = $this->repository ? context()->get(Repository::class . '.' . $this->repository) : null;
$entityClass = $this->framework_entity ? $this->framework_entity : Entity::class;
$entity = new $entityClass($repository);
$entity->setTable($this->table);
return $entity;
}
示例5: douban_login
function douban_login()
{
define('BASEURL', 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/');
$options = array('oauth_as_header' => false);
$tokenResultParams = OAuthRequester::requestRequestToken(DOUBAN_KEY, 0, array(), 'POST', $options);
$_SESSION['oauth_token'] = $tokenResultParams['token'];
context('redirect', DOUBAN_AUTHORIZE_URL . '?oauth_token=' . $tokenResultParams['token'] . '&oauth_callback=' . BASEURL . 'index.php?q=douban_oauth_callback');
}
示例6: executeCron
public function executeCron($cron, $unqueue = true)
{
$date = $cron->getDate();
if ($date <= time()) {
$_REQUEST = unserialize($cron->getData());
context()->dispatch($cron);
return true === $unqueue ? $this->unqueueCron($cron) : $this;
}
}
示例7: elggadmin_page_before
function elggadmin_page_before($c = null, $args = null)
{
require_login('admin');
if (!defined('context')) {
context('elggadmin');
}
$page = isset($args[1]) ? $args[1] : 'config';
elggadmin_currentpage($page);
}
示例8: getCache
/**
* @return Cache
*/
public function getCache()
{
$key = 'pckg.database.repository.cache.' . sha1(Cache::getCachePathByRepository($this));
$context = context();
if (!$context->exists($key)) {
$context->bind($key, $cache = new Cache($this));
}
return $context->get($key);
}
示例9: del
public function del($key)
{
if (is_string($key)) {
$val = isAke($this->data, $key, '__null__');
if ('__null__' != $val) {
unset($this->data[$key]);
}
}
return context('collection');
}
示例10: update
public function update($id = false)
{
$pk = $this->model->pk();
$id = false === $id ? isAke($_POST, $pk, false) : $id;
if (false !== $id && true === context()->isPost()) {
$this->model->post()->save();
return true;
}
return false;
}
示例11: __construct
public function __construct($name = '')
{
$this->tool =& get_clips_tool();
context('app', $this);
context('app_name', $name);
context('smarty', $this->tool->create('Smarty'));
set_error_handler("Clips\\web_error_handler");
$this->name = $name;
$this->router = $this->tool->load_class('Router', true);
$this->router->route();
}
示例12: executeInRepository
protected function executeInRepository()
{
$repositoryName = $this->migration->getRepository();
foreach ($this->sqls as $sql) {
$repository = context()->get($repositoryName);
$prepare = $repository->getConnection()->prepare($sql);
$execute = $prepare->execute();
if (!$execute) {
throw new Exception('Cannot execute query! ' . "\n" . $sql . "\n" . 'Error code ' . $prepare->errorCode() . "\n" . $prepare->errorInfo()[2]);
}
}
}
示例13: init
public static function init()
{
try {
$loader = new \Phalcon\Loader();
$loader->registerDirs([__DIR__ . DS . 'controllers' . DS, __DIR__ . DS . 'views' . DS, __DIR__ . DS . 'models' . DS, __DIR__ . DS . 'lib' . DS])->registerNamespaces(['Phalway' => __DIR__])->register();
context()->set('phalwayLoader', $loader);
$di = new \Phalcon\DI\FactoryDefault();
return new \Phalcon\Mvc\Application($di);
} catch (\Phalcon\Exception $e) {
dd($e);
}
}
示例14: execute
public function execute(callable $next)
{
try {
/**
* First argument is always 'console'.
* Second argument is app name or command.
* If it's command, we leave things as they are.
* Id it's app, we unset it.
*/
$argv = $_SERVER['argv'];
/**
* Remove application name.
*/
if (isset($argv[1]) && !strpos($argv[1], ':')) {
unset($argv[1]);
}
/**
* Remove platform name.
*/
if (isset($argv[2]) && !strpos($argv[2], ':') && false === strpos($argv[2], '-')) {
unset($argv[2]);
}
/**
* Get Symfony Console Application, find available commands and run app.
*/
$application = context()->get(SymfonyConsole::class);
try {
/**
* Apply global middlewares.
*/
if ($middlewares = $this->response->getMiddlewares()) {
chain($middlewares, 'execute');
}
$application->run(new ArgvInput(array_values($argv)));
/**
* Apply global afterwares/decorators.
*/
if ($afterwares = $this->response->getAfterwares()) {
chain($afterwares, 'execute', [$this->response]);
}
} catch (Throwable $e) {
die("EXCEPTION: " . exception($e));
}
/**
* This is here just for better readability. =)
*/
echo "\n";
} catch (Throwable $e) {
}
return $next();
}
示例15: build
public function build($slug, $repository = null)
{
if ($repository) {
$this->menus->setRepository(context()->get(Repository::class . ($repository ? '.' . $repository : '')));
}
$menu = $this->menus->withMenuItems(function (HasMany $relation) {
$relation->joinTranslation();
// $relation->joinPermissionTo('read');
})->where('slug', $slug)->one();
if (!$menu) {
return '<!-- no menu ' . $slug . ' -->';
}
return view('Pckg\\Generic:menu\\' . $menu->template, ['menu' => $menu, 'menuItems' => $this->buildTree($menu->menuItems)]);
}