本文整理汇总了PHP中Kohana::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Kohana::load方法的具体用法?PHP Kohana::load怎么用?PHP Kohana::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kohana
的用法示例。
在下文中一共展示了Kohana::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(array $config)
{
parent::__construct($config);
Kohana::load(Kohana::find_file('vendors', 'sphinxapi'));
$this->_client = new SphinxClient();
$this->_client->SetServer($this->config('host'), $this->config('port'));
}
示例2: load
/**
* Returns the translation table for a given language.
*
* @param string language to load
* @return array
*/
public static function load($lang)
{
if (isset(I18n::$_cache[$lang])) {
return I18n::$_cache[$lang];
}
// New translation table
$table = array();
// Split the language: language, region, locale, etc
$parts = explode('-', $lang);
do {
// Create a path for this set of parts
$path = implode(DIRECTORY_SEPARATOR, $parts);
if ($files = Kohana::find_file('i18n', $path)) {
$t = array();
foreach ($files as $file) {
// Merge the language strings into the sub table
$t = array_merge($t, Kohana::load($file));
}
// Append the sub table, preventing less specific language
// files from overloading more specific files
$table += $t;
}
// Remove the last part
array_pop($parts);
} while ($parts);
// Cache the translation table locally
return I18n::$_cache[$lang] = $table;
}
示例3: load
/**
* Returns the translation table for a given language.
*
* @param string language to load
* @return array
*/
public static function load($lang)
{
if (!isset(I18n::$_cache[$lang])) {
// Separate the language and locale
list($language, $locale) = explode('-', strtolower($lang), 2);
// Start a new translation table
$table = array();
// Add the locale-specific language strings
if ($files = Kohana::find_file('i18n', $language . '/' . $locale)) {
foreach ($files as $file) {
// Merge the locale strings into the translation table
$table += Kohana::load($file);
}
}
// Add the non-specific language strings
if ($files = Kohana::find_file('i18n', $language)) {
foreach ($files as $file) {
// Merge the language strings into the translation table
$table += Kohana::load($file);
}
}
// Cache the translation table locally
I18n::$_cache[$lang] = $table;
}
return I18n::$_cache[$lang];
}
示例4: load
/**
* Load modules config
*
* @param $group
* @param $module
* @return mixed
* @throws Kohana_Exception
*/
public function load($group, $module)
{
if (empty($group) || empty($module)) {
throw new Twig_Exception("Need to specify a config group and module name");
}
if (!is_string($group) || !is_string($module)) {
throw new Twig_Exception("Config group and module name must be a string");
}
if (strpos($group, '.') !== FALSE) {
// Split the config group and path
list($group, $path) = explode('.', $group, 2);
}
if (isset($this->_config_groups[$group])) {
if (isset($path)) {
return Arr::path($this->_config_groups[$group], $path, NULL, '.');
}
return $this->_config_groups[$group];
}
$config = array();
$file = $this->_get_config_file($group, $module);
if (is_file($file)) {
$config = Arr::merge($config, Kohana::load($file));
}
$this->_config_groups[$group] = new Config_Group(Kohana::$config, $group, $config);
if (isset($path)) {
return Arr::path($config, $path, NULL, '.');
}
return $this->_config_groups[$group];
}
示例5: load
/**
* Loads the translation table for a given language.
*
* @param string language to load
* @return array
*/
protected static function load($lang)
{
if (!isset(i18n::$_cache[$lang])) {
// Separate the language and locale
list($language, $locale) = explode('_', strtolower($lang));
// Start a new translation table
$table = array();
if ($files = Kohana::find_file('i18n', $language)) {
foreach ($files as $file) {
// Load the strings that are in this file
$strings = Kohana::load($file);
// Merge the language strings into the translation table
$table = array_merge($table, $strings);
}
}
if ($files = Kohana::find_file('i18n', $language . '/' . $locale)) {
foreach ($files as $file) {
// Load the strings that are in this file
$strings = Kohana::load($file);
// Merge the locale strings into the translation table
$table = array_merge($table, $strings);
}
}
// Cache the translation table locally
i18n::$_cache[$lang] = $table;
}
return i18n::$_cache[$lang];
}
示例6: load
/**
* Load and merge all of the configuration files in this group.
*
* $config->load($name);
*
* @param string $group configuration group name
* @return $this current object
* @uses Kohana::load
*/
public function load($group)
{
$config = array();
if ($files = Kohana::find_file($this->_directory, $group, NULL, TRUE)) {
foreach ($files as $file) {
// Merge each file to the configuration array
$config = Arr::merge($config, Kohana::load($file));
}
}
return $config;
}
示例7: load
/**
* Load and merge all of the configuration files in this group.
*
* $config->load($name);
*
* @param string configuration group name
* @param array configuration array
* @return $this clone of the current object
* @uses Kohana::load
*/
public function load($group, array $config = NULL)
{
if ($files = Kohana::find_file($this->_directory, $group, NULL, TRUE)) {
// Initialize the config array
$config = array();
foreach ($files as $file) {
// Merge each file to the configuration array
$config = Arr::merge($config, Kohana::load($file));
}
}
return parent::load($group, $config);
}
示例8: load_merged_array
/**
*
* @param string $directory
* @param string $file
* @return array
*/
public static function load_merged_array($directory, $file)
{
if (isset(self::$_cache[$directory][$file])) {
return self::$_cache[$directory][$file];
}
$array = array();
if ($files = Kohana::find_file($directory, $file, NULL, TRUE)) {
foreach ($files as $file) {
// Merge each file to the configuration array
$array = Arr::merge($array, Kohana::load($file));
}
}
self::$_cache[$directory][$file] = $array;
return $array;
}
示例9: append
public static function append($string, $lang)
{
$parts = explode('-', $lang);
$path = implode(DIRECTORY_SEPARATOR, $parts);
// Ищем файл для текущей локали
$file = APPPATH . 'i18n' . DIRECTORY_SEPARATOR . $path . EXT;
if (!file_exists($file)) {
throw new Kohana_Exception('File :file not exists', array(':file' => $file));
}
if (Kohana::$profiling === TRUE) {
$benchmark = Profiler::start('Generate i18n data', $lang);
}
// Загружаем файл
$data = Kohana::load($file);
$data[$string] = $string;
// Генерируем массив
$arrayString = "<?php defined( 'SYSPATH' ) OR die( 'No direct access allowed.' );\n" . "return " . var_export($data, true) . ";\n";
// Записываем в файл
$result = @file_put_contents($file, $arrayString, LOCK_EX);
if (isset($benchmark)) {
Profiler::stop($benchmark);
}
return $result;
}
示例10: init
public function init()
{
// Load session handler
$this->session = Session::instance();
// Set cache handler
$this->cache = Wi3TikoCache::instance();
// Define APPRELATIVEPATH, which is the path to the application relative to the web root
// We can retrieve this by using the SCRIPT_NAME from the front-controller ({pathfromroot}/app/index.php), and extracting the path-from-root
define("APPRELATIVEPATH", substr($_SERVER["SCRIPT_NAME"], 0, strpos($_SERVER["SCRIPT_NAME"], "/app/index.php")) . "/app/latest/");
// Define document root
// TODO: Add support for ISS (see http://www.helicron.net/php/)
define("DOCUMENTROOT", $_SERVER["DOCUMENT_ROOT"] . "/");
// Determine language
$lang = Cookie::get('lang');
if ($lang !== NULL) {
if (!in_array($lang, array('nl-nl', 'en-us'))) {
// Check the allowed languages, and force the default
$lang = 'nl-nl';
}
} else {
// Language not set in cookie. Get default language from i18n file.
$i18nfiles = Kohana::find_file("config", "i18n");
if (!empty($i18nfiles)) {
$i18nsettings = Kohana::load($i18nfiles[0]);
$lang = $i18nsettings["lang"];
} else {
$lang = 'nl-nl';
// Fall back to default
}
// Save loaded language in cookie
Cookie::set('lang', $lang);
}
// Set the target language
i18n::lang($lang);
// Set the source language to some non-existing language to prevent Kohana skipping translation lookup if source and target language are identical
i18n::$source = "bb-bb";
// See http://unicode.org/cldr/utility/languageid.jsp?a=bb&l=en for valid tags
// Load wi3-kohana-specific functions
$this->kohana = new Wi3_Kohana();
// XSS Clean all user input!
// TODO: only do this if the user is not an admin...
$this->originalpost = $_POST;
// Save original $_POST
foreach ($_POST as $key => $val) {
$_POST[$key] = Security::xss_clean($val);
}
$this->originalget = $_GET;
// Save original $_GET
foreach ($_GET as $key => $val) {
$_GET[$key] = Security::xss_clean($val);
}
// Load some Wi3 classes
// Load a global database configuration
$this->database = new Wi3_Database();
// Helper functions to create databases etc
$this->globaldatabase = Wi3_Database::instance("global");
Event::instance("wi3.init.globaldatabase.loaded")->execute();
// Get routing, url and path information
// These classes in turn add a callback to the wi3.init.site.loaded Event, after which they will update with path and urls to the site
$this->routing = Wi3_Routing::instance();
Event::instance("wi3.init.routing.loaded")->execute();
$this->pathof = Wi3_Pathof::instance();
Event::instance("wi3.init.pathof.loaded")->execute();
$this->urlof = Wi3_Urlof::instance();
Event::instance("wi3.init.urlof.loaded")->execute();
// Load CSS and Javascript 'injectors'
$this->css = Wi3_Css::instance();
$this->javascript = Wi3_Javascript::instance();
// Instantiate the Model class, that is an interface to the 'factory' method for any underlying model-systems
$this->model = Wi3_Model::inst();
Event::instance("wi3.init.model.loaded")->execute();
// Instantiate the form-builder
$this->formbuilder = Wi3_Formbuilder::inst();
Event::instance("wi3.init.formbuilder.loaded")->execute();
// Now find out what is the scope of this request
// It most often is a site-scope (i.e. the admin or view of a site), but might also be a global scope (i.e. superadmin)
// This depends on the controller.
// Pagefiller-specific controllers are always for the the sitearea
$this->scope = (substr(Request::instance()->controller, 0, 9) == "adminarea" or substr(Request::instance()->controller, 0, 10) == "pagefiller" or Request::instance()->controller == "sitearea") ? "site" : "global";
if ($this->scope == "site") {
$this->sitearea = Wi3_Sitearea::inst();
// Find out what site we are working with
// Both the admin controller and the site controller need to know this in order to work properly
// Find the site by apache 'sitename' variable
if (isset($_SERVER['REDIRECT_SITENAME'])) {
$sitename = $_SERVER['REDIRECT_SITENAME'];
// With correct loading, $_SERVER['REDIRECT_SITENAME'] should always be present, as it is set in the vhosts .htaccess that redirect here
// Global site is the site in the global space, i.e. the Site model in the 'list of sites' that is always accesible
// ( In the per-site database, there can only exist one Site model )
$this->sitearea->globalsite = $this->model->factory("site")->set('name', $sitename)->load();
Event::instance("wi3.init.sitearea.globalsite.loaded")->execute();
$this->sitearea->site = $this->sitearea->globalsite;
// This site instance will be replaced by the local user site. The ->name will be added to that local site, since it does not store that in the local db
}
// If the sitename not present, the page request came here via some illegal method.
// If the site was not loaded correctly or is not active, we cannot show the site either
if (!isset($_SERVER['REDIRECT_SITENAME']) or empty($sitename) or !$this->sitearea->globalsite->loaded() or $this->sitearea->globalsite->active == FALSE) {
// Site does not exist. Quit.
throw new Kohana_Exception("site does not exist");
}
//.........这里部分代码省略.........
示例11: defined
<?php
defined('SYSPATH') or die('No direct script access.');
/**
* Set the routes. Each route must have a minimum of a name, a URI and a set of
* defaults for the URI.
*/
// We can't use Kohana::$config because that causes my default config file to be merged
// with the application config file, with my config file taking priority. I'm almost 100%
// sure this is not what the user wants
$files = Kohana::find_file('config', 'routes', NULL);
while (count($files) > 1) {
// remove my copy of the config file from considerations, if its not the only one
if (strstr($files[0], basename(__DIR__))) {
array_shift($files);
}
}
foreach (Kohana::load(array_shift($files)) as $name => $params) {
$r = Route::set($name, $params['uri'], array_key_exists('rules', $params) ? $params['rules'] : null);
if (@$params['defaults']) {
$r->defaults($params['defaults']);
}
}
示例12: message
/**
* Get a message from a file. Messages are arbitary strings that are stored
* in the messages/ directory and reference by a key. Translation is not
* performed on the returned values.
*
* // Get "username" from messages/text.php
* $username = Kohana::message('text', 'username');
*
* @param string file name
* @param string key path to get
* @param mixed default value if the path does not exist
* @return string message string for the given path
* @return array complete message list, when no path is specified
* @uses Arr::merge
* @uses Arr::path
*/
public static function message($file, $path = NULL, $default = NULL)
{
static $messages;
if (!isset($messages[$file])) {
// Create a new message list
$messages[$file] = array();
if ($files = Kohana::find_file('messages', $file)) {
foreach ($files as $f) {
// Combine all the messages recursively
$messages[$file] = Arr::merge($messages[$file], Kohana::load($f));
}
}
}
if ($path === NULL) {
// Return all of the messages
return $messages[$file];
} else {
// Get a message using the path
return Arr::path($messages[$file], $path, $default);
}
}
示例13: action_generate
public function action_generate()
{
// Restrict to cli mode
if (!Kohana::$is_cli) {
echo "<pre>\nUsage: php index.php --uri=\"i18nget/generate\" or\n";
echo " php index.php --uri=\"i18nget/generate_for/mymodule\" or\n";
echo " php index.php --uri=\"i18nget/generate_for/mymodule/application\"\n</pre>";
return;
}
$user_paths = array($this->request->param('from_path', 'application'));
$user_paths[] = $this->request->param('to_path', $user_paths[0]);
//if we should check all i18n files in the projetcs or just module files
$global_i18n = $user_paths[1] == 'application';
foreach ($user_paths as $idx => $path_to_check) {
//application?
if ($path_to_check == 'application') {
$user_paths[$idx] = APPPATH;
continue;
}
//module?
$modules = array_slice(scandir(MODPATH), 2);
if (!in_array($path_to_check, $modules)) {
die("Your given option '{$path_to_check}' must either match 'application'" . " or one of the module names:\n " . join("\n ", $modules));
} else {
$user_paths[$idx] = MODPATH . $path_to_check;
}
}
$this->auto_render = FALSE;
$path = $user_paths[0];
$output_path = rtrim($user_paths[1], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
echo "\nGenerating files for \n'{$path}'\ninto\n'{$output_path}i18n'\n\n";
$data = array();
$unique_phrases_helper = array();
$scan_files = $this->get_dir_files($path, array('php'));
//echo Debug::dump($this->request, 9999);
//print_r(Request::$current->uri());
//print_r($user_paths);
//print_r($scan_files); return;
foreach ($scan_files as $file) {
$file_path_human = substr($file, strlen($path));
// echo Debug::dump($file_path_human, 9999);
// Get each line of the file
$file_lines = file($file, FILE_IGNORE_NEW_LINES);
$data_file = array();
foreach ($file_lines as $num_line => $file_line) {
$num_line++;
// echo Kohana::debug($num_line, $file_line, $file_path_human);
// if (preg_match_all('/(?P<key>\w+):(?P<name>[\p{L}+|\D+])/u', $file_line, $matches))
// if (preg_match('/^(?P<name>.*?[^(TO|COPYTO)]+)( TO (?P<assignedto>\w[^(COPYTO)]+))?( COPYTO (?P<copyto>\w[^(TO)]+))?$/u', trim($email['Subject']), $matches))
// if (preg_match_all('/__\(\'(?P<phrase>.+)\'(, ?array\(.+\))?\)/u', $file_line, $matches))
// if (preg_match_all('/__\(\'(?P<phrase>.*)(, ?array\(.+\))?\'\)/u', $file_line, $matches))
// if (preg_match_all("/__\('(?P<phrase>.*?[^;])'\)/u", $file_line, $matches))
// if (preg_match_all("/__\([^'.+'$]\)/u", $file_line, $matches))
// if (preg_match_all("/__\([^_]+\)/u", $file_line, $matches))
// if (preg_match_all("/__\([^\b__]+\)/u", $file_line, $matches))
// if (preg_match_all("/__\((?P<phrase>((?!__).)+)\)/u", $file_line, $matches)) /// NOTE IT WORKS!!!
// if (preg_match_all("/__\((?P<phrase>((?!__)|(?!array).)+)\)/u", $file_line, $matches))
// if (preg_match_all("/__\(('|\")(?P<phrase>((?!__)|(?! ?array ?\().)+)('|\")/u", $file_line, $matches)) /// NOTE IT WORKS!!!
if (preg_match_all("/__\\(('|\")(?P<phrase>((?!__)|(?! ?array ?\\().)+)('\\)|',|\"\\)|\",)/u", $file_line, $matches)) {
// echo Kohana::debug($file_path_human, $num_line, $file_line, $matches);
// echo Kohana::debug($file_path_human, $num_line, $file_line, $matches['phrase']);
// echo Kohana::debug($matches['phrase']);
$new_phrases = array_diff(array_unique($matches['phrase']), $unique_phrases_helper);
if ($new_phrases) {
$data_file[] = array('line_number' => $num_line, 'line_string' => $file_line, 'phrases' => $new_phrases);
$unique_phrases_helper = array_merge($new_phrases, $unique_phrases_helper);
}
}
}
if ($data_file) {
$data[] = array('filepath' => $file, 'filepath_human' => $file_path_human, 'lines' => $data_file);
}
/* if( strpos($file, 'format')!==False )
{
print_r($data_file);
die('found');
} */
}
//echo Debug::dump($data, 9999);
$languages = Kohana::$config->load('i18nget.languages');
$default_language = Kohana::$config->load('i18nget.default');
$orphe_phrases = array();
// Fix phrases
foreach ($unique_phrases_helper as $key => $phrase) {
$unique_phrases_helper[$key] = str_replace('\\\'', '\'', $unique_phrases_helper[$key]);
$unique_phrases_helper[$key] = str_replace('\\"', '"', $unique_phrases_helper[$key]);
}
// Add phrases present in current i18n language files but are not present in current code
foreach ($languages as $language_code => $language) {
if ($global_i18n) {
//only if we write to application we want to look at kohana's complete CFS for i18n files.
$i18n_messages = array_keys(I18n::load($language_code));
} else {
//if we output in an i18n folder of a module, we are only interested in that modules current translations
$lang_file = $this->lang_file_path($output_path, $language_code);
if (file_exists($lang_file)) {
$i18n_messages = array_keys(Kohana::load($lang_file));
} else {
$i18n_messages = array();
}
//.........这里部分代码省略.........
示例14: array
$phrase_translated = Arr::get(file_exists($filename) ? Kohana::load($filename) : array(), $phrase_fixed, NULL);
}
$phrase_translated_fixed = str_replace('\'', '\\\'', (string) $phrase_translated);
$not_translated = '';
if (is_null($phrase_translated)) {
$not_translated = '/// TODO';
$phrase_translated_fixed = '';
}
// print($not_translated."\t'$phrase' => '".$phrase_translated_fixed."', // ".$line['line_number'].": ".$line['line_string']."\n");
print $not_translated . "\t'{$phrase}' => '" . $phrase_translated_fixed . "', // " . $line['line_number'] . "\n";
}
}
print "\n";
}
// Orphan phrases
print "\t// Orphan phrases\n";
foreach ($orphe_phrases as $phrase) {
if ($global_i18n) {
//I18n::get() doesnt tell us if the key is equal to the translation
$phrase_translated = Arr::get($table, $phrase, NULL);
} else {
$phrase_translated = Arr::get(file_exists($filename) ? Kohana::load($filename) : array(), $phrase, NULL);
}
$not_translated = '';
if (is_null($phrase_translated)) {
$not_translated = '/// TODO';
$phrase_translated = '';
}
print $not_translated . "\t'{$phrase}' => '" . $phrase_translated . "',\n";
}
print ");\n";
示例15: defined
<?php
defined('SYSPATH') or die('No direct script access.');
Kohana::load(Kohana::find_file('../vendor/erusev/parsedown', 'Parsedown'));
class markdown extends Parsedown
{
private static $instance = false;
public static function instance($name = null)
{
if (!self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
protected function identifyLink($Excerpt)
{
$extent = $Excerpt['text'][0] === '!' ? 1 : 0;
if (strpos($Excerpt['text'], ']') and preg_match('/\\[((?:[^][]|(?R))*)\\]/', $Excerpt['text'], $matches)) {
$Link = array('text' => $matches[1], 'label' => strtolower($matches[1]));
$extent += strlen($matches[0]);
$substring = substr($Excerpt['text'], $extent);
if (preg_match('/^\\s*\\[([^][]+)\\]/', $substring, $matches)) {
$Link['label'] = strtolower($matches[1]);
if (isset($this->Definitions['Reference'][$Link['label']])) {
$Link += $this->Definitions['Reference'][$Link['label']];
$extent += strlen($matches[0]);
} else {
return;
}
} elseif (isset($this->Definitions['Reference'][$Link['label']])) {
$Link += $this->Definitions['Reference'][$Link['label']];