本文整理汇总了PHP中Gantry\Framework\Gantry::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Gantry::instance方法的具体用法?PHP Gantry::instance怎么用?PHP Gantry::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gantry\Framework\Gantry
的用法示例。
在下文中一共展示了Gantry::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
protected function __construct()
{
parent::__construct();
$gantry = Gantry::instance();
if (isset($gantry['file.yaml.cache.path'])) {
$this->setCachePath($gantry['file.yaml.cache.path']);
}
}
示例2: save
/**
* Save assignments for the configuration.
*
* @param array $data
*/
public function save(array $data)
{
$data = $data['assignments'];
foreach ($data as $tname => &$type) {
foreach ($type as $gname => &$group) {
foreach ($group as $key => $value) {
if (!$value) {
unset($group[$key]);
} else {
$group[$key] = (bool) $value;
}
}
if (empty($group)) {
unset($type[$gname]);
}
}
if (empty($type)) {
unset($data[$tname]);
}
}
$gantry = Gantry::instance();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
// Save layout into custom directory for the current theme.
$save_dir = $locator->findResource("gantry-config://{$this->configuration}", true, true);
$filename = "{$save_dir}/assignments.yaml";
$file = YamlFile::instance($filename);
$file->save($data);
$file->free();
}
示例3: getThemes
/**
* @return array
*/
public static function getThemes()
{
$gantry = Gantry::instance();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
$files = Folder::all('gantry-themes://', ['recursive' => false, 'files' => false]);
/** @var array|ThemeDetails[] $list */
$list = [];
natsort($files);
foreach ($files as $theme) {
if ($locator('gantry-themes://' . $theme . '/gantry/theme.yaml')) {
$details = new ThemeDetails($theme);
// Stream needs to be valid URL.
$streamName = 'gantry-themes-' . preg_replace('|[^a-z\\d+.-]|ui', '-', $theme);
if (!$locator->schemeExists($streamName)) {
$locator->addPath($streamName, '', $details->getPaths());
}
$details['name'] = $theme;
$details['title'] = $details['details.name'];
$details['preview_url'] = $gantry['platform']->getThemePreviewUrl($theme);
$details['admin_url'] = $gantry['platform']->getThemeAdminUrl($theme);
$details['params'] = [];
$list[$details->name] = $details;
}
}
// Add Thumbnails links after adding all the paths to the locator.
foreach ($list as $details) {
$details['thumbnail'] = $details->getUrl("details.images.thumbnail");
}
return $list;
}
示例4: onThemeInitialized
public function onThemeInitialized()
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$path = $locator('theme://');
$name = $this->name;
if (!class_exists('\\Gantry5\\Loader')) {
if ($this->isAdmin()) {
$messages = $this->grav['messages'];
$messages->add('Please enable Gantry 5 plugin in order to use current theme!', 'error');
return;
} else {
throw new \LogicException('Please install and enable Gantry 5 Framework plugin!');
}
}
// Setup Gantry 5 Framework or throw exception.
\Gantry5\Loader::setup();
// Get Gantry instance.
$gantry = Gantry::instance();
// Set the theme path from Grav variable.
$gantry['theme.path'] = $path;
$gantry['theme.name'] = $name;
// Define the template.
require $locator('theme://includes/theme.php');
// Define Gantry services.
$gantry['theme'] = function ($c) {
return new \Gantry\Theme\Hydrogen($c['theme.path'], $c['theme.name']);
};
}
示例5: init
/**
* @see AbstractTheme::init()
*/
protected function init()
{
parent::init();
$gantry = Gantry::instance();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
\JPluginHelper::importPlugin('gantry5');
// Trigger the onGantryThemeInit event.
$dispatcher = \JEventDispatcher::getInstance();
$dispatcher->trigger('onGantry5ThemeInit', ['theme' => $this]);
$lang = \JFactory::getLanguage();
// FIXME: Do not hardcode this file.
$lang->load('files_gantry5_nucleus', JPATH_SITE);
if (\JFactory::getApplication()->isSite()) {
// Load our custom positions file as frontend requires the strings to be there.
$filename = $locator("gantry-theme://language/en-GB/en-GB.tpl_{$this->name}_positions.ini");
if ($filename) {
$lang->load("tpl_{$this->name}_positions", dirname(dirname(dirname($filename))), 'en-GB');
}
}
$doc = \JFactory::getDocument();
$this->language = $doc->language;
$this->direction = $doc->direction;
$this->url = \JUri::root(true) . '/templates/' . $this->name;
}
示例6: gantry_admin_print_scripts
function gantry_admin_print_scripts()
{
$scripts = \Gantry\Framework\Gantry::instance()->scripts();
if ($scripts) {
echo implode("\n", $scripts) . "\n";
}
}
示例7: gantry
/**
* Get global Gantry instance.
*
* @return Gantry
*/
public static function gantry()
{
// We cannot set variable directly for the trait as it doesn't work in HHVM.
if (!self::$gantry) {
self::$gantry = Gantry::instance();
}
return self::$gantry;
}
示例8: delete
public static function delete($id)
{
$gantry = Gantry::instance();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
$path = $locator->findResource('gantry-config://' . $id, true, true);
if (is_dir($path)) {
Folder::delete($path, true);
}
}
示例9: widgets_init
public function widgets_init()
{
$gantry = Gantry::instance();
$positions = $gantry['configurations']->positions();
foreach ($positions as $name => $title) {
// FIXME
// This should be handled by theme so translation plugins could catch it as part of theme.
// This stuff might also need take Joomla chromes into account for cross-compatibility reasons
register_sidebar(array('name' => __($title, 'gantry5'), 'id' => $name, 'description' => __($title, 'gantry5'), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>'));
}
}
示例10: __construct
public function __construct()
{
$gantry = Gantry::instance();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
$finder = new ConfigFileFinder();
// Generate a flat list of all existing pages containing a list of file paths with timestamps.
$this->items = $finder->listFiles($locator->findResources('gantry-pages://'), '|\\.html\\.twig|');
// And list the pages in alphabetical order.
ksort($this->items);
}
示例11: bodyAttributes
public function bodyAttributes($attributes = [])
{
$gantry = Gantry::instance();
$classes = ['site', "dir-ltr", "outline-{$gantry['configuration']}"];
$baseAttributes = (array) $this->config->get('page.body.attribs', []);
if (!empty($baseAttributes['class'])) {
$baseAttributes['class'] = array_merge((array) $baseAttributes['class'], $classes);
} else {
$baseAttributes['class'] = $classes;
}
return $this->getAttributes($baseAttributes, $attributes);
}
示例12: loadAssignments
public function loadAssignments()
{
$gantry = Gantry::instance();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
// Find all the assignment files.
$paths = $locator->findResources("gantry-config://");
$files = (new ConfigFileFinder())->locateFileInFolder('assignments', $paths);
$cache = $locator->findResource('gantry-cache://theme/compiled/config', true, true);
$config = new CompiledConfig($cache, [$files]);
return $config->load();
}
示例13: add_to_twig
public function add_to_twig(\Twig_Environment $twig, \Twig_Loader_Filesystem $loader = null)
{
$gantry = \Gantry\Framework\Gantry::instance();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
if (!$loader) {
$loader = $twig->getLoader();
}
$loader->setPaths($locator->findResources('gantry-admin://templates'), 'gantry-admin');
$twig->addExtension(new TwigExtension());
return $twig;
}
示例14: onGlobalSave
public function onGlobalSave(Event $event)
{
$gantry = Gantry::instance();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
$filename = 'config://plugins/gantry5.yaml';
$file = YamlFile::instance($locator->findResource($filename, true, true));
$content = $file->content();
$content['production'] = (bool) $event->data['production'];
$file->save($content);
$file->free();
}
示例15: widgets_init
public function widgets_init()
{
$gantry = Gantry::instance();
$positions = (array) $gantry['config']->get('positions');
foreach ($positions as $name => $params) {
$params = (array) $params;
if (!isset($params['name'])) {
$params['name'] = ucfirst($name);
}
register_sidebar(array('name' => __($params['name'], 'gantry5'), 'id' => $name, 'description' => __($params['name'], 'gantry5'), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>'));
}
}