本文整理汇总了PHP中Kohana::include_paths方法的典型用法代码示例。如果您正苦于以下问题:PHP Kohana::include_paths方法的具体用法?PHP Kohana::include_paths怎么用?PHP Kohana::include_paths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kohana
的用法示例。
在下文中一共展示了Kohana::include_paths方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
/**
* When visiting any page on the site, check if the user is already logged in,
* or they are visiting a page that is allowed when logged out. Otherwise,
* redirect to the login page. If visiting the login page, check the browser
* supports cookies.
*/
public function check()
{
$uri = new URI();
// Skip check when accessing the data services, as it is redundant but would slow the services down.
// Also no need to login when running the scheduled tasks.
if ($uri->segment(1) == 'services' || $uri->segment(1) == 'scheduled_tasks') {
return;
}
// check for setup request
//
if ($uri->segment(1) == 'setup_check') {
// get kohana paths
//
$ipaths = Kohana::include_paths();
// check if indicia_setup module folder exists
//
clearstatcache();
foreach ($ipaths as $path) {
if (preg_match("/indicia_setup/", $path) && file_exists($path)) {
return;
}
}
}
// Always logged in
$auth = new Auth();
if (!$auth->logged_in() and !$auth->auto_login() and $uri->segment(1) != 'login' and $uri->segment(1) != 'logout' and $uri->segment(1) != 'new_password' and $uri->segment(1) != 'forgotten_password') {
$_SESSION['requested_page'] = $uri->string();
url::redirect('login');
} else {
if ($auth->logged_in() and is_null($_SESSION['auth_user']->password) and $uri->segment(1) != 'new_password' and $uri->segment(1) != 'logout' and $uri->segment(1) != 'setup_check') {
$_SESSION['requested_page'] = $uri->string();
url::redirect('new_password');
}
}
}
示例2: instance
public static function instance()
{
if (!Kotwig::$instance) {
Kotwig::$instance = new static();
// Load Twig configuration
Kotwig::$instance->config = Kohana::$config->load('kotwig');
// Create the the loader
$views = Kohana::include_paths();
$look_in = array();
foreach ($views as $key => $view) {
$dir = $view . Kotwig::$instance->config->templates;
if (is_dir($dir)) {
$look_in[] = $dir;
}
}
$loader = new Twig_Loader_Filesystem($look_in);
// Set up Twig
Kotwig::$instance->twig = new Twig_Environment($loader, Kotwig::$instance->config->environment);
foreach (Kotwig::$instance->config->extensions as $extension) {
// Load extensions
Kotwig::$instance->twig->addExtension(new $extension());
}
foreach (Kotwig::$instance->config->globals as $global => $object) {
// Load globals
Kotwig::$instance->twig->addGlobal($global, $object);
}
foreach (Kotwig::$instance->config->filters as $filter => $object) {
// Load filters
Kotwig::$instance->twig->addFilter($filter, $object);
}
}
return Kotwig::$instance;
}
示例3: __call
public function __call($method, $args)
{
// Concat all the arguments into a filepath
array_unshift($args, $method);
$path = join('/', $args);
// Strip the extension from the filepath
$path = substr($path, 0, -strlen($this->extension) - 1);
// Search for file using cascading file system
$filename = Kohana::find_file($this->directory, $path, FALSE, $this->extension);
if (!$filename) {
Event::run('system.404');
}
// Add all the module JavaScript directories to the include paths list
foreach (Kohana::include_paths() as $path) {
$this->include_paths[] = $path . $this->directory;
}
// Load file, along with all dependencies
$preprocessor = new JavaScriptPreprocessor($this->include_paths, $this->vars);
$output = $preprocessor->requires($filename);
// Compress JavaScript, if desired
if ($this->compress) {
$output = $this->compress($output, $this->compress_config);
}
echo $output;
}
示例4: find_plugins
/**
* Find all plugins defined in your Kohana codebase
*/
public function find_plugins()
{
$paths = Kohana::include_paths();
foreach ($paths as $path) {
$dir = $path . self::$plugins_dir;
//if there's no plugin dir skip to the next path
if (!file_exists($dir)) {
continue;
}
// Instantiate a new directory iterator object
$directory = new DirectoryIterator($dir);
if ($directory->isDir()) {
foreach ($directory as $plugin) {
// Is directory?
if ($plugin->isDir() && !$plugin->isDot()) {
// if there's no plugin.php in this folder, ignore it
if (!file_exists($plugin->getPath() . DIRECTORY_SEPARATOR . $directory->getBasename() . DIRECTORY_SEPARATOR . 'plugin.php')) {
continue;
}
// Store plugin in our pool
self::$plugins_pool[$plugin->getFilename()]['plugin'] = ucfirst($plugin->getFilename());
self::$plugins_pool[$plugin->getFilename()]['path'] = $plugin->getPath() . DIRECTORY_SEPARATOR . $directory->getBasename();
}
}
}
}
return $this;
}
示例5: test_get_all_class_names_considers_class_paths_from_config
public function test_get_all_class_names_considers_class_paths_from_config()
{
Kohana::$config->load('doctrine')->set('entity_paths', array('Some/Entity/Path' => TRUE, 'Other/Entities' => TRUE));
$reader = new SimpleAnnotationReader();
$reader->addNamespace('Doctrine\\ORM\\Mapping');
$driver = new Doctrine_KohanaAnnotationDriver(new CachedReader($reader, new ArrayCache()), Kohana::include_paths());
$this->assertEquals(array('Some_Entity_Path_Entity', 'Other_Entities_Entity'), $driver->getAllClassNames());
}
示例6: _execute
/**
* Execute the task and compile the LESS files
*
* @param array $params the passed command options
*
* @throws Exception
* @return void
*/
protected function _execute(array $params)
{
// Prepare the options for recess
$recess_opts = array();
// Create the list of valid assets/less paths found in the CFS and format them as recess arguments
$paths = Kohana::include_paths();
foreach ($paths as $path) {
$path .= 'assets/less';
if (file_exists($path)) {
$recess_opts[] = '--includePath ' . escapeshellarg($path);
}
}
// Add paths for fontawesome and twitter bootstrap
// Note that these are deliberately set at organisation level to namespace the less files below
$recess_opts[] = '--includePath ' . escapeshellarg(realpath($params['vendor-path'] . '/fortawesome'));
$recess_opts[] = '--includePath ' . escapeshellarg(realpath($params['vendor-path'] . '/twbs'));
// Determine whether to lint or compile, and whether the output should be compressed
if ($params['lint-only']) {
$output = '';
} else {
$recess_opts[] = '--compile';
// Find the path for the output file
$output = ' > ' . escapeshellarg($params['public-path'] . '/css/' . $params['css-output'] . '.css');
if (!$params['no-compress']) {
$recess_opts[] = '--compress';
}
}
// Find the input file to use
$input = Kohana::find_file('assets/less', $params['less-input'], 'less');
if (!$input) {
throw new Exception("Could not find a valid input file source for {$params['less-input']}");
}
// Build and log the recess command
$command = 'recess ' . implode(' ', $recess_opts) . ' ' . escapeshellarg($input) . $output;
Minion_CLI::write(Minion_CLI::color('Preparing to execute recess with following command', 'green'));
Minion_CLI::write(Minion_CLI::color('> ' . $command, 'green'));
$loop = $params['loop-after'] > 0;
do {
Minion_CLI::write(Minion_CLI::color('Building CSS', 'light_gray'));
// Execute and check the result
system($command, $exit_code);
if ($exit_code != 0) {
throw new Exception("Command '" . $command . '" failed with exit code ' . $exit_code);
}
Minion_CLI::write(Minion_CLI::color('Compiled ' . $input . ' to ' . $output, 'green'));
if ($loop) {
sleep($params['loop-after']);
}
} while ($loop);
}
示例7: commands
/**
* A list of item commands
* @return array
*/
public function commands()
{
$commands = Item::list_commands();
$list_c = array();
foreach ($commands as $cmd) {
$name = str_replace(Kohana::include_paths(), '', $cmd);
$name = str_replace(array('\\', '/'), '_', $name);
$value = 'Item_Command_' . $name;
$command = new $value();
if ($command->is_default() == FALSE) {
$list_c[] = array('name' => str_replace('_', ' - ', $name), 'value' => $value);
}
}
return $list_c;
}
示例8: autoload
public static function autoload($class)
{
//Make use of Kohanas transparent file structure
foreach (Kohana::include_paths() as $path) {
$orig = $path;
$path1 = $path . "models" . DIRECTORY_SEPARATOR . strtolower($class) . '.php';
$path2 = $path . "models/generated" . DIRECTORY_SEPARATOR . strtolower($class) . '.php';
//^^ Bit of a hack to allow for generated doctrine models
//Only add the directory if it is valid
if (file_exists($path1)) {
include $path1;
return true;
} else {
if (file_exists($path2)) {
include $path2;
return true;
}
}
}
}
示例9: __call
public function __call($method, $args)
{
if (count($segments = $this->uri->segment_array(1)) > 1) {
// Find directory (type) and filename
$type = array_shift($segments);
$file = implode('/', $segments);
if (substr($file, -strlen(EXT)) === EXT) {
// Remove extension
$file = substr($file, 0, -strlen(EXT));
}
if ($type === 'config') {
if ($file === 'config') {
// This file can only exist in one location
$file = APPPATH . $type . '/config' . EXT;
} else {
foreach (array_reverse(Kohana::include_paths()) as $path) {
if (is_file($path . $type . '/' . $file . EXT)) {
// Found the file
$file = $path . $type . '/' . $file . EXT;
break;
}
}
}
} else {
// Get absolute path to file
$file = Kohana::find_file($type, $file);
}
if (in_array($type, Kodoc::get_types())) {
// Load Kodoc
$this->kodoc = new Kodoc($type, $file);
// Set the title
$this->template->title = implode('/', $this->uri->segment_array(1));
// Load documentation for this file
$this->template->content = new View('kodoc/documentation');
// Exit this method
return;
}
}
// Nothing to document
url::redirect('kodoc');
}
示例10: __construct
public function __construct()
{
Event::add('system.routing', array($this, 'install'));
Event::add('system.display', array($this, 'render'));
$modules = Kohana::config('core.modules');
if (!is_dir(DOCROOT . 'installation')) {
// Delete install app from Config::$include_paths
unset($modules[0]);
}
$installed_mods = array();
foreach (Module_Model::factory()->find(ALL) as $module) {
/**
* @todo Validate the modules via /config/[module].php or something
*/
is_dir(MODPATH . $module->name) and $installed_mods[] = MODPATH . $module->name;
}
// Set module include paths
Kohana::config_set('core.modules', array_merge($installed_mods, $modules));
// Re-process the include paths
Kohana::include_paths(TRUE);
Kohana::log('debug', 'Hanami Core Hook initialized');
}
示例11: _remove_from_path
private static function _remove_from_path($module)
{
$available = (array) static::$available;
$kohana_modules = Kohana::modules();
if (in_array($module, array_keys($available)) && isset($available[$module])) {
$module = $available[$module];
if (($key = array_search($module->path, $kohana_modules)) !== false) {
unset($kohana_modules[$key]);
$kohana_modules = array_values($kohana_modules);
// reindex
}
Kohana::modules($kohana_modules);
Kohana::include_paths(true);
}
}
示例12: list_files
/**
* Lists all files and directories in a resource path.
*
* @param string directory to search
* @param boolean list all files to the maximum depth?
* @param string full path to search (used for recursion, *never* set this manually)
* @return array filenames and directories
*/
public static function list_files($directory, $recursive = FALSE, $path = FALSE)
{
$files = array();
if ($path === FALSE) {
$paths = array_reverse(Kohana::include_paths());
foreach ($paths as $path) {
// Recursively get and merge all files
$files = array_merge($files, self::list_files($directory, $recursive, $path . $directory));
}
} else {
$path = rtrim($path, '/') . '/';
if (is_readable($path)) {
$items = (array) glob($path . '*');
foreach ($items as $index => $item) {
$files[] = $item = str_replace('\\', '/', $item);
// Handle recursion
if (is_dir($item) and $recursive == TRUE) {
// Filename should only be the basename
$item = pathinfo($item, PATHINFO_BASENAME);
// Append sub-directory search
$files = array_merge($files, self::list_files($directory, TRUE, $path . $item));
}
}
}
}
return $files;
}
示例13: setup
/**
* Router setup routine. Automatically called during Kohana setup process.
*
* @return void
*/
public static function setup()
{
if (!empty($_SERVER['QUERY_STRING'])) {
// Set the query string to the current query string
Router::$query_string = '?' . trim($_SERVER['QUERY_STRING'], '&/');
}
if (Router::$routes === NULL) {
// Load routes
Router::$routes = Kohana::config('routes');
}
// Default route status
$default_route = FALSE;
if (Router::$current_uri === '') {
// Make sure the default route is set
if (!isset(Router::$routes['_default'])) {
throw new Kohana_Exception('core.no_default_route');
}
// Use the default route when no segments exist
Router::$current_uri = Router::$routes['_default'];
// Default route is in use
$default_route = TRUE;
}
// Make sure the URL is not tainted with HTML characters
Router::$current_uri = html::specialchars(Router::$current_uri, FALSE);
// Remove all dot-paths from the URI, they are not valid
Router::$current_uri = preg_replace('#\\.[\\s./]*/#', '', Router::$current_uri);
// At this point segments, rsegments, and current URI are all the same
Router::$segments = Router::$rsegments = Router::$current_uri = trim(Router::$current_uri, '/');
// Set the complete URI
Router::$complete_uri = Router::$current_uri . Router::$query_string;
// Explode the segments by slashes
Router::$segments = ($default_route === TRUE or Router::$segments === '') ? array() : explode('/', Router::$segments);
if ($default_route === FALSE and count(Router::$routes) > 1) {
// Custom routing
Router::$rsegments = Router::routed_uri(Router::$current_uri);
}
// The routed URI is now complete
Router::$routed_uri = Router::$rsegments;
// Routed segments will never be empty
Router::$rsegments = explode('/', Router::$rsegments);
// Prepare to find the controller
$controller_path = '';
$method_segment = NULL;
// Paths to search
$paths = Kohana::include_paths();
foreach (Router::$rsegments as $key => $segment) {
// Add the segment to the search path
$controller_path .= $segment;
$found = FALSE;
foreach ($paths as $dir) {
// Search within controllers only
$dir .= 'controllers/';
if (is_dir($dir . $controller_path) or is_file($dir . $controller_path . EXT)) {
// Valid path
$found = TRUE;
// The controller must be a file that exists with the search path
if ($c = str_replace('\\', '/', realpath($dir . $controller_path . EXT)) and is_file($c) and strpos($c, $dir) === 0) {
// Set controller name
Router::$controller = $segment;
// Change controller path
Router::$controller_path = $c;
// Set the method segment
$method_segment = $key + 1;
// Stop searching
break;
}
}
}
if ($found === FALSE) {
// Maximum depth has been reached, stop searching
break;
}
// Add another slash
$controller_path .= '/';
}
if ($method_segment !== NULL and isset(Router::$rsegments[$method_segment])) {
// Set method
Router::$method = Router::$rsegments[$method_segment];
if (isset(Router::$rsegments[$method_segment + 1])) {
// Set arguments
Router::$arguments = array_slice(Router::$rsegments, $method_segment + 1);
}
}
// Last chance to set routing before a 404 is triggered
Event::run('system.post_routing');
if (Router::$controller === NULL) {
// No controller was found, so no page can be rendered
Event::run('system.404');
}
}
示例14: _list_classes
protected static function _list_classes($files = NULL)
{
if (is_null($files)) {
// Remove core module paths form search
$loaded_modules = Kohana::modules();
$exclude_modules = array('database', 'orm', 'sprig', 'auth', 'sprig-auth', 'userguide', 'image', 'codebench', 'unittest', 'pagination');
$paths = Kohana::include_paths();
// Remove known core module paths
foreach ($loaded_modules as $module => $path) {
if (in_array($module, $exclude_modules)) {
unset($paths[array_search($path . DIRECTORY_SEPARATOR, $paths)]);
}
}
// Remove system path
unset($paths[array_search(SYSPATH, $paths)]);
$files = Kohana::list_files('classes', $paths);
}
$classes = array();
foreach ($files as $name => $path) {
if (is_array($path)) {
$classes = array_merge($classes, self::_list_classes($path));
} else {
// Strip 'classes/' off start
$name = substr($name, 8);
// Strip '.php' off end
$name = substr($name, 0, 0 - strlen(EXT));
// Convert to class name
$classes[] = str_replace(DIRECTORY_SEPARATOR, '_', $name);
}
}
return $classes;
}
示例15: create_annotation_driver
/**
* Create an instance of the Kohana annotation driver, which supports loading model files from across the CFS. Also
* handles registering the Doctrine annotations in the Annotation registry - which would normally be handled by
* Doctrine\ORM\Configuration::newDefaultAnnotationDriver.
*
* @return Doctrine_KohanaAnnotationDriver
* @see Doctrine\ORM\Configuration::newDefaultAnnotationDriver
*/
protected function create_annotation_driver()
{
$config = $this->config->load('doctrine');
// Register the Doctrine annotations
$vendor_path = $config->get('composer_vendor_path');
AnnotationRegistry::registerFile($vendor_path . 'doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
if ($config->get('use_simple_annotation_reader')) {
// Register the ORM Annotations in the AnnotationReader
$reader = new SimpleAnnotationReader();
$reader->addNamespace('Doctrine\\ORM\\Mapping');
} else {
$reader = new AnnotationReader();
}
$cachedReader = new CachedReader($reader, new ArrayCache());
return new Doctrine_KohanaAnnotationDriver($cachedReader, Kohana::include_paths());
}