本文整理汇总了PHP中Kohana::modules方法的典型用法代码示例。如果您正苦于以下问题:PHP Kohana::modules方法的具体用法?PHP Kohana::modules怎么用?PHP Kohana::modules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kohana
的用法示例。
在下文中一共展示了Kohana::modules方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cache
/**
* More feature-rich caching using the optional cache library if available. The default
* Kohana cache doesn't support all the use cases below as expected. The default cache checks lifetime
* when getting based on the file modified time.
*
* Simplified usage for both internal Kohana cache and cache module:
* - cache() - Get/set.
* - cache(true, 60) - Get/set.
* - cache(true, 0) - Delete.
* - cache(false) - Refresh.
* - cache(false, 60) - Refresh.
* - cache(false, 0) - Delete.
*
* Specific usage for cache module:
* - cache() - Get or set cache. Get cache. If empty, set cache using default lifetime.
* - cache(true, 60) - Get or set cache. Same as above cache() but using specified lifetime.
* - cache(true, 0) - Delete cache. Check and return cache if it exists, but also delete cache.
* for this query. If a cached result doesn't exist, then same effect as not using cache().
* - cache(false) - Refresh cache. Don't check cache, but cache the new results using the default lifetime.
* - cache(false, 60) - Refresh cache. Same as above cache(false) but using specified lifetime.
* - cache(false, 0) - Delete cache. Don't check cache and delete cache for this query if it was previously cached.
*
* Specific usage if no cache module. Note that lifetime is meaningless when setting cache:
* - cache() - 1) Get cache. If cache exists and is younger than default lifetime, then get cache.
* If older than default time, delete cache.
* 2) Else set cache. Lifetime not used when setting.
* - cache(true, 60) - Same as above cache(), but use specified lifetime instead of default lifetime.
* - cache(true, 0) - Delete cache. Doesn't get or set cache.
* - cache(false) - Refresh cache. Don't check cache, but cache the new results ignoring lifetime.
* - cache(false, 60) - Refresh cache. Same as above cache(false).
* - cache(false, 0) - Delete cache. Same as cache(true, 0);
*
* @param boolean $check [optional] Check cache and return cached result if available.
* @param integer $specific_lifetime [optional] Set cache lifetime. If null, use default. If "0", delete.
* @param string $type [optional] Cache type name if using cache module. If null use default.
* @return object $this
*/
public function cache($check = TRUE, $specific_lifetime = NULL, $type = NULL)
{
if (!isset($this->_cache)) {
// TODO: is this the best way to check for the "cache" module?
$modules = Kohana::modules();
if (isset($modules['cache'])) {
// Use the "unofficial" Kohana cache module.
$this->_cache = Cache::instance($type);
} else {
// Default internal Kohana cache.
$this->_cache = true;
}
}
if ($specific_lifetime === NULL) {
if (is_object($this->_cache)) {
// Use the default internal Kohana cache lifetime which is 60 seconds.
$this->_cache_lifetime = 60;
} else {
// Use the default lifetime from the Cache module.
$this->_cache_lifetime = Kohana::config('cache.default-expire');
}
} else {
$this->_cache_lifetime = $specific_lifetime;
}
$this->_cache_check = $check;
return $this;
}
示例2: setUp
public function setUp()
{
parent::setUp();
$this->environment()->backup_and_set(array('Request::$client_ip' => '127.0.0.1', 'Request::$user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19', 'functest.modules' => array('functest', 'test'), 'functest.apptests' => FALSE));
$this->modpath = Arr::get(Kohana::modules(), 'functest');
$this->test_folder = 'tests' . DIRECTORY_SEPARATOR . 'test_data' . DIRECTORY_SEPARATOR . 'test_folder' . DIRECTORY_SEPARATOR;
}
示例3: init
/**
* Application initialization
* - Loads the plugins
* - Sets the cookie configuration
*/
public static function init()
{
// Set defaule cache configuration
Cache::$default = Kohana::$config->load('site')->get('default_cache');
try {
$cache = Cache::instance()->get('dummy' . rand(0, 99));
} catch (Exception $e) {
// Use the dummy driver
Cache::$default = 'dummy';
}
// Load the plugins
Swiftriver_Plugins::load();
// Add the current default theme to the list of modules
$theme = Swiftriver::get_setting('site_theme');
if (isset($theme) and $theme != "default") {
Kohana::modules(array_merge(array('themes/' . $theme->value => THEMEPATH . $theme->value), Kohana::modules()));
}
// Clean up
unset($active_plugins, $theme);
// Load the cookie configuration
$cookie_config = Kohana::$config->load('cookie');
Cookie::$httponly = TRUE;
Cookie::$salt = $cookie_config->get('salt', Swiftriver::DEFAULT_COOKIE_SALT);
Cookie::$domain = $cookie_config->get('domain') or '';
Cookie::$secure = $cookie_config->get('secure') or FALSE;
Cookie::$expiration = $cookie_config->get('expiration') or 0;
// Set the default site locale
I18n::$lang = Swiftriver::get_setting('site_locale');
}
示例4: instance
/**
* @return Kohana_Twig
*/
public static function instance()
{
if (!static::$instance) {
static::$instance = new self();
// Load Twig configuration
static::$instance->config = Kohana::$config->load('twig');
// Array of template locations in cascading filesystem
$templatesDir = static::$instance->config->templates_dir;
$templatePaths = [APPPATH . $templatesDir];
foreach (Kohana::modules() as $modulePath) {
$tempPath = $modulePath . $templatesDir;
if (is_dir($tempPath)) {
$templatePaths[] = $tempPath;
}
}
// Create the the loader
$loader = new Twig_Loader_Filesystem($templatePaths);
// Set up Twig
static::$instance->twig = new Twig_Environment($loader, static::$instance->config->environment);
foreach (static::config('extensions', []) as $extension) {
// Load extensions
static::$instance->twig->addExtension(new $extension());
}
}
return static::$instance;
}
示例5: before
public function before()
{
// We need to load all theme modules
foreach (scandir(MODPATH) as $modulePath) {
if (substr($modulePath, 0, 5) == 'theme') {
Kohana::modules(array($modulePath => MODPATH . $modulePath) + Kohana::modules());
}
}
}
示例6: _fetch_controllers
private static function _fetch_controllers()
{
$paths = Kohana::modules() + array(APPPATH);
$paths = array_values($paths);
foreach ($paths as $index => $path) {
$paths[$index] = rtrim($path, '/') . '/';
}
$paths = Kohana::list_files('classes/controller', $paths);
return self::_path_to_controller($paths);
}
示例7: init
/**
* Инициализация модуля.
*
* При инициализации активированные плагины подключаются через
* Kohana::modules
*
*/
public static function init()
{
self::$_activated = self::_load_from_db();
$plugins = array();
foreach (self::$_activated as $plugin_id => $tmp) {
if (is_dir(PLUGPATH . $plugin_id)) {
$plugins['plugin_' . $plugin_id] = PLUGPATH . $plugin_id;
}
}
Kohana::modules($plugins + Kohana::modules());
}
示例8: get_modules
public static function get_modules()
{
if (self::$modules === null) {
foreach (Kohana::modules() as $module => $path) {
if (stripos($module, 'cms_') === 0) {
self::$modules[$module] = $path;
}
}
}
return self::$modules;
}
示例9: _execute
protected function _execute(array $options)
{
$db = $this->db_params(Kohana::TESTING);
Minion_Task::factory(array('task' => 'db:structure:load', 'database' => Kohana::TESTING, 'force' => NULL, 'file' => NULL))->execute();
$structure_files = array_filter(array_map(function ($dir) use($db) {
$file = $dir . 'tests' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'structure' . DIRECTORY_SEPARATOR . strtolower($db['type']) . '.sql';
return is_file($file) ? $file : NULL;
}, Kohana::modules()));
foreach ($structure_files as $schema) {
Minion_Task::factory(array('task' => 'db:structure:load', 'database' => Kohana::TESTING, 'force' => NULL, 'file' => $schema))->execute();
}
}
示例10: __toString
public function __toString()
{
// $attr = $this->_html_attr;
// $attr['class'] = $this->css_class();
// $attr['type'] = $this->field_type();
// return Form::checkbox($this->name(), null, (bool)$this->value(), $attr);
if (array_key_exists('recaptcha', Kohana::modules())) {
$recap = Recaptcha::instance();
return $recap->get_html();
} else {
return "";
}
}
示例11: on
public static function on($name)
{
if (isset(self::$modules[$name])) {
return;
}
foreach (self::$paths as $path) {
if (is_dir($path . $name)) {
self::$modules[$name] = $path . DS . $name;
Kohana::modules(self::$modules);
break;
}
}
}
示例12: generateJS
private function generateJS($cacheFileName = 'leaflet-package.js')
{
$modulePath = Arr::get(Kohana::modules(), 'kohana-leaflet');
$dir = $modulePath . 'media/js/';
$jsContent = '/* Created :' . date('Y-m-d H:i:s') . ' */';
foreach ($this->_jsFiles as $jsFile) {
$fJSFile = $modulePath . $jsFile;
if (file_exists($fJSFile)) {
$jsFileContent = preg_replace('/\\s+/', ' ', file_get_contents($fJSFile));
$jsContent .= "\n\n" . '/* JS from: ' . basename($fJSFile) . ' */' . "\n" . $jsFileContent;
}
}
file_put_contents($dir . $cacheFileName, $jsContent);
}
示例13: install
/**
* Run Plugin Installer Script if Available
*
* @param string plugin namespace
* @return bool
*/
public static function install($plugin)
{
// Dynamically load the new module into the system
Kohana::modules(array_merge(array(PLUGINPATH . $plugin), Kohana::modules()));
// Does the plugin have an installer script?
if (isset(self::$_installers[$plugin])) {
try {
call_user_func(self::$_installers[$plugin]);
return TRUE;
} catch (Exception $e) {
Kohana::$log->add(Log::ERROR, "Could not execute plugin installer callback function :callback", array(':callback' => self::$_installers[$plugin]));
return FALSE;
}
}
return FALSE;
}
示例14: _execute
protected function _execute(array $options)
{
$module_name = $options['module'];
$module_dir = Arr::get(Kohana::modules(), $module_name);
$author = $options['author'];
switch ($options['type']) {
case 'number':
$parent = 'Stats_Widget_Number';
break;
case 'chart':
$parent = 'Stats_Widget_Chart';
break;
default:
$parent = 'Stats_Widget';
}
$name = $options['name'];
$title = Jam::capitalize_class_name(str_replace('_', ' ', $name));
$path = str_replace('_', DIRECTORY_SEPARATOR, $title);
$dir = $module_dir . 'classes' . DIRECTORY_SEPARATOR . 'Stats' . DIRECTORY_SEPARATOR . 'Widget';
$file = $dir . DIRECTORY_SEPARATOR . $path . EXT;
$class = 'Stats_Widget_' . str_replace(' ', '_', $title);
if (!is_dir(dirname($file))) {
mkdir(dirname($file), 0777, TRUE);
}
$widget_content = <<<WIDGET
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Stats Widget: {$title}
*
* @package {$module_name}
* @author {$author}
* @copyright (c) 2011-2013 Despark Ltd.
*/
class {$class} extends {$parent} {
\tprotected \$_title = '{$title}';
\tpublic function retrieve(\$start_date, \$end_date)
\t{
\t\t// return 0;
\t}
}
WIDGET;
Minion_Jam_Generate::modify_file($file, $widget_content, $options['force'] !== FALSE);
}
示例15: set_theme
/**
* Sets active theme if none supplied or uses the supplied one
*
* @param boolean|string $theme Theme name [Optional]
*/
public static function set_theme($theme = FALSE)
{
if (!empty($theme)) {
Theme::$active = $theme;
}
$modules = Kohana::modules();
// Check if the active theme is not loaded already
if (!empty(Theme::$active) and !in_array(Theme::$active, array_keys($modules))) {
// Make sure the theme is available
if ($theme = self::getTheme()) {
//set absolute theme path and load the request theme as kohana module
Kohana::modules(array('theme' => $theme->path) + $modules);
} else {
Log::error('Missing site theme: :theme', array(':theme' => Theme::$active));
}
}
unset($modules);
}