本文整理汇总了PHP中Grav\Common\Grav类的典型用法代码示例。如果您正苦于以下问题:PHP Grav类的具体用法?PHP Grav怎么用?PHP Grav使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Grav类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onGetPageTemplates
public function onGetPageTemplates($event)
{
$types = $event->types;
$locator = Grav::instance()['locator'];
$types->scanBlueprints($locator->findResources('plugin://' . $this->name . '/blueprints'));
$types->scanTemplates($locator->findResources('plugin://' . $this->name . '/templates'));
}
示例2: serve
/**
* @return int|null|void
*/
protected function serve()
{
$grav = Grav::instance();
$this->output->writeln('');
$this->output->writeln('<yellow>Current Configuration:</yellow>');
$this->output->writeln('');
dump($grav['config']->get('plugins.email'));
$this->output->writeln('');
require_once __DIR__ . '/../vendor/autoload.php';
$grav['Email'] = new Email();
$email_to = $this->input->getOption('to') ?: $grav['config']->get('plugins.email.to');
$subject = $this->input->getOption('subject');
$body = $this->input->getOption('body');
if (!$subject) {
$subject = 'Testing Grav Email Plugin';
}
if (!$body) {
$configuration = print_r($grav['config']->get('plugins.email'), true);
$body = $grav['language']->translate(['PLUGIN_EMAIL.TEST_EMAIL_BODY', $configuration]);
}
$sent = EmailUtils::sendEmail($subject, $body, $email_to);
if ($sent) {
$this->output->writeln("<green>Message sent successfully!</green>");
} else {
$this->output->writeln("<red>Problem sending email...</red>");
}
}
示例3: __construct
/**
* set some instance variable states
*/
public function __construct()
{
$this->grav = Grav::instance();
$this->shortcode = $this->grav['shortcode'];
$this->config = $this->grav['config'];
$this->twig = $this->grav['twig'];
}
示例4: init
public function init()
{
$grav = Grav::instance();
/** @var Config $config */
$config = $grav['config'];
$mode = $config->get('system.debugger.mode');
TracyDebugger::$logDirectory = $config->get('system.debugger.log.enabled') ? LOG_DIR : null;
TracyDebugger::$maxDepth = $config->get('system.debugger.max_depth');
// Switch debugger into development mode if configured
if ($config->get('system.debugger.enabled')) {
if ($config->get('system.debugger.strict')) {
TracyDebugger::$strictMode = true;
}
if (function_exists('ini_set')) {
ini_set('display_errors', true);
}
if ($mode == strtolower('detect')) {
TracyDebugger::$productionMode = self::DETECT;
} elseif ($mode == strtolower('production')) {
TracyDebugger::$productionMode = self::PRODUCTION;
} else {
TracyDebugger::$productionMode = self::DEVELOPMENT;
}
}
}
示例5: backup
/**
* Backup
*
* @param null $destination
* @param callable|null $messager
*
* @return null|string
*/
public static function backup($destination = null, callable $messager = null)
{
if (!$destination) {
$destination = Grav::instance()['locator']->findResource('backup://', true);
if (!$destination) {
throw new \RuntimeException('The backup folder is missing.');
}
}
$name = substr(strip_tags(Grav::instance()['config']->get('site.title', basename(GRAV_ROOT))), 0, 20);
$inflector = new Inflector();
if (is_dir($destination)) {
$date = date('YmdHis', time());
$filename = trim($inflector->hyphenize($name), '-') . '-' . $date . '.zip';
$destination = rtrim($destination, DS) . DS . $filename;
}
$messager && $messager(['type' => 'message', 'level' => 'info', 'message' => 'Creating new Backup "' . $destination . '"']);
$messager && $messager(['type' => 'message', 'level' => 'info', 'message' => '']);
$zip = new \ZipArchive();
$zip->open($destination, \ZipArchive::CREATE);
$max_execution_time = ini_set('max_execution_time', 600);
static::folderToZip(GRAV_ROOT, $zip, strlen(rtrim(GRAV_ROOT, DS) . DS), $messager);
$messager && $messager(['type' => 'progress', 'percentage' => false, 'complete' => true]);
$messager && $messager(['type' => 'message', 'level' => 'info', 'message' => '']);
$messager && $messager(['type' => 'message', 'level' => 'info', 'message' => 'Saving and compressing archive...']);
$zip->close();
if ($max_execution_time !== false) {
ini_set('max_execution_time', $max_execution_time);
}
return $destination;
}
示例6: fromFile
/**
* Create Medium from a file
*
* @param string $file
* @param array $params
* @return Medium
*/
public static function fromFile($file, array $params = [])
{
if (!file_exists($file)) {
return null;
}
$path = dirname($file);
$filename = basename($file);
$parts = explode('.', $filename);
$ext = array_pop($parts);
$basename = implode('.', $parts);
$config = Grav::instance()['config'];
$media_params = $config->get("media.types." . strtolower($ext));
if (!$media_params) {
return null;
}
$params += $media_params;
// Add default settings for undefined variables.
$params += $config->get('media.types.defaults');
$params += ['type' => 'file', 'thumb' => 'media/thumb.png', 'mime' => 'application/octet-stream', 'filepath' => $file, 'filename' => $filename, 'basename' => $basename, 'extension' => $ext, 'path' => $path, 'modified' => filemtime($file), 'thumbnails' => []];
$locator = Grav::instance()['locator'];
$file = $locator->findResource("image://{$params['thumb']}");
if ($file) {
$params['thumbnails']['default'] = $file;
}
return static::fromArray($params);
}
示例7: __construct
public function __construct(array $items = array(), Grav $grav = null, $environment = null)
{
$this->grav = $grav ?: Grav::instance();
$this->finder = new ConfigFinder();
$this->environment = $environment ?: 'localhost';
$this->messages[] = 'Environment Name: ' . $this->environment;
if (isset($items['@class'])) {
if ($items['@class'] != get_class($this)) {
throw new \InvalidArgumentException('Unrecognized config cache file!');
}
// Loading pre-compiled configuration.
$this->timestamp = (int) $items['timestamp'];
$this->checksum = $items['checksum'];
$this->items = (array) $items['data'];
} else {
// Make sure that
if (!isset($items['streams']['schemes'])) {
$items['streams']['schemes'] = [];
}
$items['streams']['schemes'] += $this->streams;
$items = $this->autoDetectEnvironmentConfig($items);
$this->messages[] = $items['streams']['schemes']['config']['prefixes'][''];
parent::__construct($items);
}
$this->check();
}
示例8: __construct
/**
* Create a RecursiveFilterIterator from a RecursiveIterator
*
* @param RecursiveIterator $iterator
*/
public function __construct(\RecursiveIterator $iterator)
{
parent::__construct($iterator);
if (empty($this::$folder_ignores)) {
$this::$folder_ignores = Grav::instance()['config']->get('system.pages.ignore_folders');
}
}
示例9: getSubscribedEvents
/**
* @return array
*/
public static function getSubscribedEvents()
{
if (!Grav::instance()['config']->get('plugins.admin-pro.enabled')) {
return ['onPluginsInitialized' => [['setup', 100000], ['onPluginsInitialized', 1001]], 'onShutdown' => ['onShutdown', 1000], 'onFormProcessed' => ['onFormProcessed', 0], 'onAdminDashboard' => ['onAdminDashboard', 0]];
}
return [];
}
示例10: loadBlueprint
/**
* Load blueprints.
*/
protected function loadBlueprint()
{
if (!$this->blueprint) {
$grav = Grav::instance();
$themes = $grav['themes'];
$this->blueprint = $themes->get($this->name)->blueprints();
}
}
示例11: url
public function url(array $args = [])
{
$grav = Grav::instance();
$url = $grav['uri']->url;
$parts = Url::parse($url, true);
$parts['vars'] = array_replace($parts['vars'], $args);
return Url::build($parts);
}
示例12: init
public function init()
{
$this->grav = Grav::instance();
if ($this->enabled()) {
$this->debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector((array) $this->grav['config']->get('system')));
}
return $this;
}
示例13: resetHandlers
public function resetHandlers()
{
$grav = Grav::instance();
$config = $grav['config']->get('system.errors');
$jsonRequest = $_SERVER && isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/json';
// Setup Whoops-based error handler
$whoops = new \Whoops\Run();
$verbosity = 1;
if (isset($config['display'])) {
if (is_int($config['display'])) {
$verbosity = $config['display'];
} else {
$verbosity = $config['display'] ? 1 : 0;
}
}
switch ($verbosity) {
case 1:
$error_page = new Whoops\Handler\PrettyPageHandler();
$error_page->setPageTitle('Crikey! There was an error...');
$error_page->addResourcePath(GRAV_ROOT . '/system/assets');
$error_page->addCustomCss('whoops.css');
$whoops->pushHandler($error_page);
break;
case -1:
$whoops->pushHandler(new BareHandler());
break;
default:
$whoops->pushHandler(new SimplePageHandler());
break;
}
if (method_exists('Whoops\\Util\\Misc', 'isAjaxRequest')) {
//Whoops 2.0
if (Whoops\Util\Misc::isAjaxRequest() || $jsonRequest) {
$whoops->pushHandler(new Whoops\Handler\JsonResponseHandler());
}
} elseif (function_exists('Whoops\\isAjaxRequest')) {
//Whoops 2.0.0-alpha
if (Whoops\isAjaxRequest() || $jsonRequest) {
$whoops->pushHandler(new Whoops\Handler\JsonResponseHandler());
}
} else {
//Whoops 1.x
$json_page = new Whoops\Handler\JsonResponseHandler();
$json_page->onlyForAjaxRequests(true);
}
if (isset($config['log']) && $config['log']) {
$logger = $grav['log'];
$whoops->pushHandler(function ($exception, $inspector, $run) use($logger) {
try {
$logger->addCritical($exception->getMessage() . ' - Trace: ' . $exception->getTraceAsString());
} catch (\Exception $e) {
echo $e;
}
}, 'log');
}
$whoops->register();
}
示例14: __construct
/**
* initialize some internal instance variables
*/
public function __construct()
{
$this->grav = Grav::instance();
$this->config = $this->grav['config'];
$this->handlers = new HandlerContainer();
$this->events = new EventContainer();
$this->states = [];
$this->assets = [];
$this->objects = [];
}
示例15: redirect
/**
* Redirects an action
*/
public function redirect()
{
if ($this->redirect) {
$this->grav->redirect($this->redirect, $this->redirectCode);
} else {
if ($redirect = $this->grav['config']->get('plugins.login.redirect')) {
$this->grav->redirect($redirect, $this->redirectCode);
}
}
}