示例#1
0
 /**
  * Kohana::list_files() should return an array on success and an empty array on failure
  *
  * @test
  * @covers Kohana::list_files
  */
 public function test_list_files_returns_array_on_success_and_failure()
 {
     $files = Kohana::list_files('config');
     $this->assertType('array', $files);
     $this->assertGreaterThan(3, count($files));
     $this->assertSame(array(), Kohana::list_files('geshmuck'));
 }
示例#2
0
文件: help.php 项目: MenZil-Team/cms
 /**
  * Generates a help list for all tasks
  *
  * @return null
  */
 protected function _execute(array $params)
 {
     $tasks = $this->_compile_task_list(Kohana::list_files('classes/task'));
     $view = new View('minion/help/list');
     $view->tasks = $tasks;
     echo $view;
 }
示例#3
0
 /**
  * Recurse into test directories to find all tests
  *
  * @param   string sub directory (under any /tests dir) to (recursively) look for tests in
  * @param   array  (optional) list of files to flatten (used for recursion)
  * @return  array  flattened list of all test files
  */
 public static function find_tests($directory = NULL, array $tests = NULL)
 {
     if (is_null($tests)) {
         if (is_null($directory)) {
             $tests_directory = "";
         } else {
             $tests_directory = 'tests' . DIRECTORY_SEPARATOR . trim($directory, DIRECTORY_SEPARATOR);
         }
         // Load tests from directory
         $tests = Kohana::list_files($tests_directory);
         // Load specified test case if found and make it first to run
         if (dirname($tests_directory) !== basename($tests_directory) and $test_file = Kohana::find_file(dirname($tests_directory), basename($tests_directory))) {
             array_unshift($tests, $test_file);
         }
     }
     $flattened_tests = array();
     foreach ($tests as $relative => $file) {
         if (is_array($file)) {
             $flattened_tests += self::find_tests(NULL, $file);
         } else {
             $flattened_tests[$relative] = $file;
         }
     }
     return $flattened_tests;
 }
 public function index()
 {
     // Require Zend_Amf_Server
     require_once 'Zend/Amf/Server.php';
     // *ZAMFBROWSER IMPLEMENTATION*
     // Require the ZendAmfServiceBrowser class, required to retrieve the list of methods on the ZendAMF server.
     require_once Kohana::find_file('vendor/ZamfBrowser', 'ZendAmfServiceBrowser');
     // Start Server
     $server = new Zend_Amf_Server();
     // $server->addDirectory( SHAREDPATH.Kohana::config('zendamf.services_path') );
     $services_path = APPPATH . Kohana::config('zendamf.services_path');
     $files = Kohana::list_files($services_path, FALSE);
     foreach ($files as $file) {
         $class = pathinfo($file, PATHINFO_FILENAME);
         $server->setClass($class);
     }
     // // do class mapping
     $vo_path = APPPATH . Kohana::config('zendamf.vo_path');
     $files = Kohana::list_files($vo_path, FALSE);
     foreach ($files as $file) {
         $class = pathinfo($file, PATHINFO_FILENAME);
         $server->setClassMap($class, $class);
     }
     // *ZAMFBROWSER IMPLEMENTATION*
     // Add the ZendAmfServiceBrowser class to the list of available classes.
     $server->setClass("ZendAmfServiceBrowser");
     // *ZAMFBROWSER IMPLEMENTATION*
     // Set this reference the class requires to the server object.
     // ZendAmfServiceBrowser::setAmfServer( $server );
     ZendAmfServiceBrowser::$ZEND_AMF_SERVER = $server;
     // Handle the AMF request
     echo $server->handle();
 }
 /**
  * Get plugins
  *
  * @return void
  * @author Peter Bowyer
  */
 function getPlugins()
 {
     $x = Kohana::list_files(PLUGPATH, false, PLUGPATH);
     for ($i = 0; $i < count($x); $i++) {
         $x[$i] = substr($x[$i], strlen(PLUGPATH . '/') - 1);
     }
     return $x;
 }
示例#6
0
 public function fetch_seed_groups()
 {
     $groups = [];
     $files = Kohana::list_files('database/seeds');
     foreach ($files as $file => $path) {
         $groups[] = substr($file, 15);
     }
     return $groups;
 }
 function get_template_list()
 {
     $f = Kohana::list_files('views/containers');
     $arr = array();
     foreach ($f as $file) {
         $n = basename($file, ".php");
         $arr[$n] = $n;
     }
     return $arr;
 }
 /**
  * get a list of container templates
  *
  * @return array
  * @author Andy Bennett
  */
 public static function get_container_templates()
 {
     $arr = array();
     $l = Kohana::list_files('views/container');
     foreach ($l as $f) {
         $n = basename($f, ".php");
         $arr[$n] = ucfirst($n);
     }
     return $arr;
 }
示例#9
0
 /**
  * Dump all i18n files
  */
 public function action_i18n()
 {
     $files = Kohana::list_files('i18n');
     $i18n = array();
     foreach ($files as $key => $value) {
         // Trim off "i18n/" and ".php"
         $i18n[$key] = substr($key, 5, -strlen(EXT));
     }
     $this->template->content = View::factory('devtools/i18n', array('i18n' => $i18n));
 }
 protected static function _getTaskClasses()
 {
     $aClasses = self::_getTaskClassesList(Kohana::list_files('classes/Task'));
     foreach ($aClasses as $iKey => $sClass) {
         if (!in_array('Interface_TaskLauncherTask', class_implements($sClass))) {
             unset($aClasses[$iKey]);
         }
     }
     return $aClasses;
 }
示例#11
0
 /**
  * @return array
  */
 public static function find_local()
 {
     $patches_list = Kohana::list_files('patches', array(DOCROOT));
     $installed_patches = self::installed();
     $patches = array();
     foreach ($patches_list as $path) {
         $filename = pathinfo($path, PATHINFO_BASENAME);
         if (!in_array($filename, $installed_patches)) {
             $patches[$filename] = $path;
         }
     }
     return $patches;
 }
示例#12
0
 /**
  * Prints out the help for a specific task
  *
  */
 public function action_help()
 {
     $tasks = Minion_Util::compile_task_list(Kohana::list_files('classes/minion/task'));
     $view = NULL;
     if (empty($this->_task)) {
         $view = new View('minion/help/list');
         $view->tasks = $tasks;
     } else {
         $inspector = new ReflectionClass($this->_retrieve_task());
         list($description, $tags) = Minion_Util::parse_doccomment($inspector->getDocComment());
         $view = View::factory('minion/help/task')->set('description', $description)->set('tags', (array) $tags)->set('task', $this->_task);
     }
     echo $view;
 }
示例#13
0
 public function __construct($name, $directory)
 {
     $this->name = $name;
     $files = Kohana::list_files($directory);
     foreach ($files as $file) {
         if (!is_file($file)) {
             continue;
         }
         if (substr_compare($file, 'Base_Test' . EXT, strlen($file) - strlen('Base_Test' . EXT)) !== 0) {
             PHPUnit_Util_Filter::addFileToFilter($file);
             $this->addTestFile($file);
         }
     }
 }
示例#14
0
 public function _get_models()
 {
     $initial_classes = get_declared_classes();
     foreach (Kohana::list_files('models') as $file) {
         include_once $file;
     }
     $classes = array_diff(get_declared_classes(), $initial_classes);
     $models = array();
     foreach ($classes as $class) {
         if (is_subclass_of($class, 'ORM')) {
             $models[] = new $class();
         }
     }
     return $models;
 }
示例#15
0
 /**
  * Method to merge resources
  * It finds out all the controllers and adds the basenames to the acl config array
  * as resources only if the key doesnot already exists
  */
 private function merge_resources()
 {
     $controllers = Kohana::list_files('classes/controller');
     // controllers can also be nested, so just flatten the array
     $controllers = Arr::flatten($controllers);
     foreach ($controllers as $controller) {
         $resource = basename($controller, '.php');
         if (self::is_resource_ignored($resource) || array_key_exists($resource, $this->_acl)) {
             continue;
         }
         $this->_acl[$resource] = array();
     }
     ksort($this->_acl);
     return $this;
 }
示例#16
0
 /**
  * get all the controllers and the actions that can be used
  * @return array 
  */
 public static function list_controllers()
 {
     $list_controllers = array();
     $controllers = Kohana::list_files('classes/controller/panel');
     foreach ($controllers as $controller) {
         if (is_array($controller)) {
             foreach ($controller as $c) {
                 $c = basename($c, '.php');
                 $list_controllers[$c] = self::get_action_methods($c);
             }
         } else {
             $controller = basename($controller, '.php');
             $list_controllers[$controller] = self::get_action_methods($controller);
         }
     }
     return $list_controllers;
 }
示例#17
0
 /**
  * @param bool $parseActions
  * @param bool $forced
  */
 static function routes($parseActions = TRUE, $forced = FALSE)
 {
     if ($forced || !static::$_routes) {
         $pathPrefix = 'classes' . DIRECTORY_SEPARATOR;
         $directoryPrefix = self::config('directory_prefix');
         $path = rtrim($pathPrefix . 'Controller' . DIRECTORY_SEPARATOR . $directoryPrefix, DIRECTORY_SEPARATOR);
         $controllers = array_keys(Arr::flatten(Kohana::list_files($path)));
         $urlBase = self::config('route.url.base', 'api');
         $urlPrefix = $urlBase . self::config('route.url.version', '/v{version}');
         foreach ($controllers as $controller) {
             $className = str_replace([$pathPrefix, DIRECTORY_SEPARATOR, EXT], ['', '_', ''], $controller);
             self::getClassRoutes($className, $directoryPrefix, $urlPrefix, $parseActions);
         }
         Route::set('RestfulAPI\\Error', $urlBase . '(/<unknown>)', ['unknown' => '.*'])->filter([get_class(), 'error404']);
         static::$_routes = TRUE;
     }
 }
示例#18
0
 public function index()
 {
     $out = "<?php\n" . "// auto-generated by Kohana-Zend Autocomplete\n" . "// Developed by Peter Bowyer, Maple Design (http://www.mapledesign.co.uk/code/\n" . "// Last generated: " . date('Y-m-d H:i:s T') . "\n\n";
     $endings = array('_Controller', '_Core');
     $files = Kohana::list_files('', true);
     #print_r($files);
     // Regex taken from Symfony
     // Now used as backup for classes that don't have a __construct() method
     $regex2 = '~^[\\w|\\040]*(class|interface)[\\040]+([\\w]+)~mi';
     $regex = '~[\\w|\\040]*(class|interface)[\\040]+([\\w]+).+?function\\s+__construct[\\040]*\\([\\040]*(.*?)[\\040]*\\)\\s*\\n~si';
     foreach ($files as $file) {
         if (!is_dir($file) && !strstr($file, 'vendor')) {
             // We exclude external libraries in 'vendor' directories
             $file_contents = file_get_contents($file);
             preg_match_all($regex, $file_contents, $classes);
             #if (strpos($file, 'URI') !== false)
             #print_r($classes);
             if (!isset($classes[2][0]) || isset($classes[2][0]) && strlen($classes[2][0]) == 0) {
                 // No __construct method. Run the other regex.
                 preg_match_all($regex2, $file_contents, $classes);
                 for ($i = 0; $i < count($classes[2]); $i++) {
                     // See if we have a suffix to remove
                     foreach ($endings as $ending) {
                         if (preg_match("!{$ending}\$!i", $classes[2][$i])) {
                             $newclass = preg_replace("!{$ending}\$!i", '', $classes[2][$i]);
                             $out .= "// File {$file}:\nClass {$newclass} extends {$classes[2][$i]} {}\n\n";
                         }
                     }
                 }
             } else {
                 for ($i = 0; $i < count($classes[2]); $i++) {
                     // See if we have a suffix to remove
                     foreach ($endings as $ending) {
                         if (preg_match("!{$ending}\$!i", $classes[2][$i])) {
                             $newclass = preg_replace("!{$ending}\$!i", '', $classes[2][$i]);
                             $out .= "// File {$file}:\nClass {$newclass} extends {$classes[2][$i]} { function __construct({$classes[3][$i]}); }\n\n";
                         }
                     }
                 }
             }
         }
     }
     file_put_contents(APPPATH . '/cache/ide_autocomplete.php', $out);
     print APPPATH . '/cache/ide_autocomplete.php was successfully generated';
 }
示例#19
0
 public static function suite()
 {
     if (!class_exists('Kohana')) {
         throw new Exception('Please include the kohana bootstrap file.');
     }
     spl_autoload_unregister(array('Kohana', 'auto_load'));
     spl_autoload_register(array('Tests', 'auto_load'));
     $files = Kohana::list_files('tests');
     // Files to include in code coverage
     self::whitelist();
     $suite = new PHPUnit_Framework_TestSuite();
     $folders = Kohana::config('phpunit.filter_folders');
     foreach ($folders as $folder) {
         PHPUnit_Util_Filter::addDirectoryToFilter($folder);
     }
     self::addTests($suite, $files);
     return $suite;
 }
示例#20
0
 /**
  * Returns an array of all the classes available, built by listing all files in the classes folder and then trying to create that class.
  *
  * This means any empty class files (as in complety empty) will cause an exception
  *
  * @param   array   array of files, obtained using Kohana::list_files
  * @return  array   an array of all the class names
  */
 public static function classes(array $list = NULL)
 {
     if ($list === NULL) {
         $list = Kohana::list_files('classes');
     }
     $classes = array();
     foreach ($list as $name => $path) {
         if (is_array($path)) {
             $classes += Kodoc::classes($path);
         } else {
             // Remove "classes/" and the extension
             $class = substr($name, 8, -strlen(EXT));
             // Convert slashes to underscores
             $class = str_replace(DIRECTORY_SEPARATOR, '_', strtolower($class));
             $classes[$class] = $class;
         }
     }
     return $classes;
 }
示例#21
0
 /**
  * Gets list of instances of [CLI_Task] class.
  * 
  *     $catalog = CLI_Task_Info::get_list();
  * 
  * @param  string $path path to root directory of tasks
  * @return array
  */
 public static function get_list($path = CLI_Tasker::DIR_ROOT)
 {
     if (Kohana::$caching) {
         // Create cache key\tag for find task list
         $cache_key = __METHOD__ . '(' . $path . ')';
         // Try load list from cache
         if ($catalog = Kohana::cache($cache_key)) {
             return $catalog;
         }
     }
     $catalog = Kohana::list_files($path);
     $catalog = Arr::flatten($catalog);
     $catalog = array_keys($catalog);
     if (Kohana::$caching) {
         // Cache task information
         Kohana::cache($cache_key, $catalog, 3600);
     }
     return $catalog;
 }
示例#22
0
文件: admin.php 项目: Hinton/langify
 function action_import()
 {
     // Grab a list of files that can be imported.
     $files = array();
     $view_files = array();
     $config = Kohana::config('langify');
     foreach (Kohana::list_files('i18n', $config['paths']) as $k => $v) {
         $files[] = $k;
         $view_files[] = array('key' => $k);
     }
     $this->view->set('files', $view_files);
     $post = Validation::factory($_POST)->rule('file', 'not_empty')->rule('file', 'in_array', array(':value', $files));
     if ($post->check()) {
         // Remove unnesesary junk from the file name.
         $file = $post['file'];
         $file = str_replace(array('i18n\\', 'i18n/', '.php'), '', $file);
         $this->import($file, isset($post['keys']), isset($post['strings']));
     }
 }
示例#23
0
 function after()
 {
     $devils = array();
     $route = Route::get('devilities');
     foreach (Kohana::list_files('classes/controller/devils') as $devil => $_ignore) {
         // The name of our devil, horns removed
         $devil = substr($devil, strrpos($devil, '/') + 1, -strlen(EXT));
         // The wolf is not a devil!
         if ($devil === 'controller' or $devil === 'media') {
             continue;
         }
         $attributes = $devil == $this->request->controller ? array('class' => 'selected') : array();
         $params = array('controller' => $devil);
         $devils[] = Html::anchor($route->uri($params), ucfirst($devil), $attributes);
     }
     $this->template->set('devils', $devils);
     // Render the template
     return parent::after();
 }
示例#24
0
 public function action_index()
 {
     // TODO: Cache it!!!
     $templates = Kohana::list_files($this->_directory);
     $content = array();
     $last_changed = 0;
     foreach ($templates as $key => $value) {
         $changed = filemtime($value);
         $last_changed = max($last_changed, $changed);
         $key = str_replace($this->_directory . '/', '', $key);
         $key = str_replace('.mustache', '', $key);
         $value = file_get_contents($value);
         // $value = preg_replace('/\s\s+/', ' ', $value);
         // $value = stripslashes($value);
         $content[$key] = $value;
     }
     $this->response->headers('Content-Type', 'application/javascript');
     $this->response->headers('Last-Modified', (string) date('r', $last_changed));
     $this->response->body('TEMPLATES = ' . json_encode($content));
 }
示例#25
0
 /**
  * Retrieve a basic information about the API
  *
  * GET /api
  *
  * @return void
  */
 public function action_get_index_collection()
 {
     $path = 'classes/Controller/Api';
     $files = Arr::flatten(Kohana::list_files($path));
     $trim = strlen($path);
     $endpoints = [];
     foreach ($files as $file => $path) {
         if (__FILE__ === $path) {
             continue;
             // skip the index
         }
         // remove the base path (up to Api/) and the .php extension
         $file = substr($file, $trim + 1, -4);
         // @todo this would be much more awesome if it gave back a URI
         $endpoints[] = strtolower($file);
     }
     sort($endpoints);
     $user = service('session.user');
     $this->_response_payload = ['now' => date(DateTime::W3C), 'version' => static::$version, 'endpoints' => $endpoints, 'user' => ['id' => $user->id, 'username' => $user->username]];
 }
示例#26
0
 public static function bootstrapPackages($ignoreInstaller = FALSE)
 {
     if (Bluebox_Installer::is_installing() and $ignoreInstaller !== TRUE) {
         return TRUE;
     }
     $installedPackages = Doctrine::getTable('Package')->findByStatus(Package_Manager::STATUS_INSTALLED);
     if (empty($installedPackages)) {
         return FALSE;
     }
     $loadList = $navigation = array();
     foreach ($installedPackages as $package) {
         $packageDir = DOCROOT . $package['basedir'];
         $loadList[$package['name']] = $packageDir;
         if (is_dir($packageDir . '/models')) {
             // Note that with MODEL_LOADING_CONSERVATIVE set, the model isn't really loaded until first requested
             Doctrine::loadModels($packageDir . '/models', Doctrine::MODEL_LOADING_CONSERVATIVE);
         }
         if (empty($package['navigation'])) {
             continue;
         }
         $navigation[$package['name']] = $package['navigation'];
     }
     $loadedModules = Kohana::config('core.modules');
     $systemModules = array_unique(array_merge($loadedModules, $loadList));
     Kohana::config_set('core.modules', $systemModules);
     foreach ($loadList as $packageDir) {
         // Load hooks only for modules in the DB, if hooks are enabled
         if (Kohana::config('core.enable_hooks') === TRUE) {
             if (is_dir($packageDir . '/hooks')) {
                 // Since we're running late, we need to go grab
                 // the hook files again (sad but true)
                 $hooks = Kohana::list_files('hooks', TRUE, $packageDir . '/hooks');
                 foreach ($hooks as $file) {
                     // Load the hook
                     include_once $file;
                 }
             }
         }
     }
     navigation::bootstrap($navigation);
 }
示例#27
0
 /**
  *
  * Loads a basic list info
  * @param string $view template to render 
  */
 public function action_index($view = NULL)
 {
     $path = 'images/cms/';
     $root = DOCROOT . $path;
     $list_images = Kohana::list_files('../' . $path);
     $images = array();
     $i = 0;
     foreach ($list_images as $key => $image) {
         $image_name = str_replace($root, '', $image);
         $image_path = $root . $image_name;
         $image_url = Core::config('general.base_url') . $path . $image_name;
         $images[$i]['name'] = $image_name;
         $images[$i]['path'] = $image_path;
         $images[$i]['url'] = $image_url;
         $i++;
     }
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('CMS Images')));
     $this->template->scripts['footer'][] = 'js/oc-panel/crud/index.js';
     $this->template->title = __('CMS Images');
     $this->template->content = View::factory('oc-panel/pages/cmsimages/index', array('images' => $images));
 }
示例#28
0
文件: route.php 项目: greor/satin-spb
 public static function uri($page_id, $name, array $params = NULL, $region = TRUE)
 {
     if (empty(self::$dynamic_routes)) {
         foreach (Kohana::list_files('config' . DIRECTORY_SEPARATOR . 'routes') as $file_key => $file) {
             $_tmp = explode(DIRECTORY_SEPARATOR, $file_key);
             $config_file_name = array_pop($_tmp);
             $routes_config = Kohana::$config->load('routes/' . str_replace('.php', '', $config_file_name))->as_array();
             foreach ($routes_config as $key => $value) {
                 $route = new Route(Arr::get($value, 'uri_callback'), Arr::get($value, 'regex'));
                 $route->defaults(Arr::get($value, 'defaults'));
                 self::$dynamic_routes[$key] = $route;
             }
         }
     }
     if (isset(self::$dynamic_routes[$name])) {
         $base_uri = $page_id !== FALSE ? Page_Route::dynamic_base_uri($page_id) : '_module/' . $name;
         $route_uri = self::$dynamic_routes[$name]->uri($params, $region);
         return $base_uri . $route_uri;
     }
     return NULL;
 }
示例#29
0
 /**
  * Do the actual installation.
  *
  * Make sure you rollback any changes if your install fails (using uninstall())!
  *
  * By default, the install routine just installs your models. If that's all you need for your install,
  * you don't need to override this function. All models in the directory of your module will be installed.
  *
  * You do not need to override this class if you are not adding additional functionality to it.
  *
  * @return array | NULL Array of failures, or NULL if everything is OK
  */
 public function install($identifier)
 {
     $package = Package_Catalog::getPackageByIdentifier($identifier);
     if (!empty($package['directory']) and $package['type'] != Package_Manager::TYPE_CORE) {
         kohana::log('debug', 'Dynamically adding `' . $package['directory'] . '` to kohana');
         $loadedModules = Kohana::config('core.modules');
         $modules = array_unique(array_merge($loadedModules, array($package['directory'])));
         Kohana::config_set('core.modules', $modules);
         if (is_dir($package['directory'] . '/hooks')) {
             // Since we're running late, we need to go grab
             // the hook files again (sad but true)
             $hooks = Kohana::list_files('hooks', TRUE, $package['directory'] . '/hooks');
             foreach ($hooks as $file) {
                 // Load the hook
                 include_once $file;
             }
         }
     }
     // If this package has any models, load them and determine which ones are BASE models (i.e. not extensions of other models)
     // Note that we do this because Postgers & Doctrine don't like our polymorphic class extensions and try to create the same
     // tables twice.
     if (!empty($package['models'])) {
         $loadedModels = Doctrine::loadModels($package['directory'] . '/models', Doctrine::MODEL_LOADING_CONSERVATIVE);
     }
     if (!empty($loadedModels)) {
         $models = array();
         foreach ($loadedModels as $modelName) {
             if (get_parent_class($modelName) == 'Bluebox_Record' or get_parent_class($modelName) == 'Doctrine_Record') {
                 $models[] = $modelName;
             }
         }
         // If this package has any models of it's own (not extensions) then create the tables!
         if (!empty($models)) {
             kohana::log('debug', 'Adding table(s) ' . implode(', ', $models));
             Doctrine::createTablesFromArray($models);
         }
     }
 }
示例#30
0
 protected function _get_next_update($current_version)
 {
     $updates = $this->_find_all_updates(Kohana::list_files('classes/beans/setup/update/v'));
     if (!in_array($current_version, $updates)) {
         $updates[] = $current_version;
     }
     // PHP 5.4+ Required for this...  using an ugly hack instead.
     // sort($updates,'SORT_NATURAL');
     natsort($updates);
     $new_updates = array();
     foreach ($updates as $update) {
         $new_updates[] = $update;
     }
     $updates = $new_updates;
     $i = 0;
     $target_version = FALSE;
     while (!$target_version && $i < count($updates)) {
         if ($updates[$i] == $current_version && isset($updates[$i + 1])) {
             $target_version = $updates[$i + 1];
         }
         $i++;
     }
     return $target_version;
 }