Leenooks customisations for Kohana

This commit is contained in:
Deon George 2013-04-22 14:21:45 +10:00
parent 78f0e6db06
commit a835c25dcc
11 changed files with 102 additions and 319 deletions

View File

@ -1,129 +0,0 @@
<?php defined('SYSPATH') or die('No direct script access.');
// -- Environment setup --------------------------------------------------------
// Load the core Kohana class
require SYSPATH.'classes/Kohana/Core'.EXT;
if (is_file(APPPATH.'classes/Kohana'.EXT))
{
// Application extends the core
require APPPATH.'classes/Kohana'.EXT;
}
else
{
// Load empty core extension
require SYSPATH.'classes/Kohana'.EXT;
}
/**
* Set the default time zone.
*
* @link http://kohanaframework.org/guide/using.configuration
* @link http://www.php.net/manual/timezones
*/
date_default_timezone_set('America/Chicago');
/**
* Set the default locale.
*
* @link http://kohanaframework.org/guide/using.configuration
* @link http://www.php.net/manual/function.setlocale
*/
setlocale(LC_ALL, 'en_US.utf-8');
/**
* Enable the Kohana auto-loader.
*
* @link http://kohanaframework.org/guide/using.autoloading
* @link http://www.php.net/manual/function.spl-autoload-register
*/
spl_autoload_register(array('Kohana', 'auto_load'));
/**
* Optionally, you can enable a compatibility auto-loader for use with
* older modules that have not been updated for PSR-0.
*
* It is recommended to not enable this unless absolutely necessary.
*/
//spl_autoload_register(array('Kohana', 'auto_load_lowercase'));
/**
* Enable the Kohana auto-loader for unserialization.
*
* @link http://www.php.net/manual/function.spl-autoload-call
* @link http://www.php.net/manual/var.configuration#unserialize-callback-func
*/
ini_set('unserialize_callback_func', 'spl_autoload_call');
// -- Configuration and initialization -----------------------------------------
/**
* Set the default language
*/
I18n::lang('en-us');
/**
* Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
*
* Note: If you supply an invalid environment name, a PHP warning will be thrown
* saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
*/
if (isset($_SERVER['KOHANA_ENV']))
{
Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
}
/**
* Initialize Kohana, setting the default options.
*
* The following options are available:
*
* - string base_url path, and optionally domain, of your application NULL
* - string index_file name of your index file, usually "index.php" index.php
* - string charset internal character set used for input and output utf-8
* - string cache_dir set the internal cache directory APPPATH/cache
* - integer cache_life lifetime, in seconds, of items cached 60
* - boolean errors enable or disable error handling TRUE
* - boolean profile enable or disable internal profiling TRUE
* - boolean caching enable or disable internal caching FALSE
* - boolean expose set the X-Powered-By header FALSE
*/
Kohana::init(array(
'base_url' => '/kohana/',
));
/**
* Attach the file write to logging. Multiple writers are supported.
*/
Kohana::$log->attach(new Log_File(APPPATH.'logs'));
/**
* Attach a file reader to config. Multiple readers are supported.
*/
Kohana::$config->attach(new Config_File);
/**
* Enable modules. Modules are referenced by a relative or absolute path.
*/
Kohana::modules(array(
// 'auth' => MODPATH.'auth', // Basic authentication
// 'cache' => MODPATH.'cache', // Caching with multiple backends
// 'codebench' => MODPATH.'codebench', // Benchmarking tool
// 'database' => MODPATH.'database', // Database access
// 'image' => MODPATH.'image', // Image manipulation
// 'minion' => MODPATH.'minion', // CLI Tasks
// 'orm' => MODPATH.'orm', // Object Relationship Mapping
// 'unittest' => MODPATH.'unittest', // Unit testing
// 'userguide' => MODPATH.'userguide', // User guide and API documentation
));
/**
* Set the routes. Each route must have a minimum of a name, a URI and a set of
* defaults for the URI.
*/
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));

View File

@ -1,10 +0,0 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Welcome extends Controller {
public function action_index()
{
$this->response->body('hello, world!');
}
} // End Welcome

View File

@ -1,21 +0,0 @@
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

121
index.php
View File

@ -1,121 +0,0 @@
<?php
/**
* The directory in which your application specific resources are located.
* The application directory must contain the bootstrap.php file.
*
* @link http://kohanaframework.org/guide/about.install#application
*/
$application = 'application';
/**
* The directory in which your modules are located.
*
* @link http://kohanaframework.org/guide/about.install#modules
*/
$modules = 'modules';
/**
* The directory in which the Kohana resources are located. The system
* directory must contain the classes/kohana.php file.
*
* @link http://kohanaframework.org/guide/about.install#system
*/
$system = 'system';
/**
* The default extension of resource files. If you change this, all resources
* must be renamed to use the new extension.
*
* @link http://kohanaframework.org/guide/about.install#ext
*/
define('EXT', '.php');
/**
* Set the PHP error reporting level. If you set this in php.ini, you remove this.
* @link http://www.php.net/manual/errorfunc.configuration#ini.error-reporting
*
* When developing your application, it is highly recommended to enable notices
* and strict warnings. Enable them by using: E_ALL | E_STRICT
*
* In a production environment, it is safe to ignore notices and strict warnings.
* Disable them by using: E_ALL ^ E_NOTICE
*
* When using a legacy application with PHP >= 5.3, it is recommended to disable
* deprecated notices. Disable with: E_ALL & ~E_DEPRECATED
*/
error_reporting(E_ALL | E_STRICT);
/**
* End of standard configuration! Changing any of the code below should only be
* attempted by those with a working knowledge of Kohana internals.
*
* @link http://kohanaframework.org/guide/using.configuration
*/
// Set the full path to the docroot
define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);
// Make the application relative to the docroot, for symlink'd index.php
if ( ! is_dir($application) AND is_dir(DOCROOT.$application))
$application = DOCROOT.$application;
// Make the modules relative to the docroot, for symlink'd index.php
if ( ! is_dir($modules) AND is_dir(DOCROOT.$modules))
$modules = DOCROOT.$modules;
// Make the system relative to the docroot, for symlink'd index.php
if ( ! is_dir($system) AND is_dir(DOCROOT.$system))
$system = DOCROOT.$system;
// Define the absolute paths for configured directories
define('APPPATH', realpath($application).DIRECTORY_SEPARATOR);
define('MODPATH', realpath($modules).DIRECTORY_SEPARATOR);
define('SYSPATH', realpath($system).DIRECTORY_SEPARATOR);
// Clean up the configuration vars
unset($application, $modules, $system);
if (file_exists('install'.EXT))
{
// Load the installation check
return include 'install'.EXT;
}
/**
* Define the start time of the application, used for profiling.
*/
if ( ! defined('KOHANA_START_TIME'))
{
define('KOHANA_START_TIME', microtime(TRUE));
}
/**
* Define the memory usage at the start of the application, used for profiling.
*/
if ( ! defined('KOHANA_START_MEMORY'))
{
define('KOHANA_START_MEMORY', memory_get_usage());
}
// Bootstrap the application
require APPPATH.'bootstrap'.EXT;
if (PHP_SAPI == 'cli') // Try and load minion
{
class_exists('Minion_Task') OR die('Please enable the Minion module for CLI support.');
set_exception_handler(array('Minion_Exception', 'handler'));
Minion_Task::factory(Minion_CLI::options())->execute();
}
else
{
/**
* Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
* If no source is specified, the URI will be automatically detected.
*/
echo Request::factory(TRUE, array(), FALSE)
->execute()
->send_headers(TRUE)
->body();
}

View File

@ -92,7 +92,7 @@ class Kohana_Minion_CLI {
{
foreach ($values as $opt => $value)
{
if ( ! in_array($opt, $options))
if ( ! in_array($opt, $options, TRUE))
{
// Set the given value
unset($values[$opt]);

View File

@ -183,6 +183,15 @@ class Kohana_ORM extends Model implements serializable {
*/
protected $_table_names_plural = TRUE;
// Suppress ORMs inclusion of <table_name>.*
protected $_disable_wild_select = FALSE;
// Suppress ORMs inclusion of <table_name>. to column joins
protected $_disable_join_table_name = FALSE;
// Suppress ORMs use of limit
protected $_disable_limit = FALSE;
/**
* Model configuration, reload on wakeup?
* @var bool
@ -268,7 +277,7 @@ class Kohana_ORM extends Model implements serializable {
else
{
// Passing the primary key
$this->where($this->_object_name.'.'.$this->_primary_key, '=', $id)->find();
$this->where(($this->_disable_join_table_name ? '' : $this->_object_name.'.').$this->_primary_key, '=', $id)->find();
}
}
elseif ( ! empty($this->_cast_data))
@ -351,6 +360,7 @@ class Kohana_ORM extends Model implements serializable {
}
$defaults['foreign_key'] = $this->_object_name.$this->_foreign_key_suffix;
$defaults['far_key'] = Inflector::singular($alias).$this->_foreign_key_suffix;
$init['_has_one'][$alias] = array_merge($defaults, $details);
}
@ -359,7 +369,7 @@ class Kohana_ORM extends Model implements serializable {
{
if ( ! isset($details['model']))
{
$defaults['model'] = str_replace(' ', '_', ucwords(str_replace('_', ' ', Inflector::singular($alias))));
$defaults['model'] = str_replace(' ', '_', ucwords(str_replace('_', ' ', ($this->_model_names_plural ? Inflector::singular($alias) : $alias))));
}
$defaults['foreign_key'] = $this->_object_name.$this->_foreign_key_suffix;
@ -626,7 +636,7 @@ class Kohana_ORM extends Model implements serializable {
$model = $this->_related($column);
// Use this model's column and foreign model's primary key
$col = $model->_object_name.'.'.$model->_primary_key;
$col = ($this->_disable_join_table_name ? '' : $model->_object_name.'.').$model->_primary_key;
$val = $this->_object[$this->_belongs_to[$column]['foreign_key']];
// Make sure we don't run WHERE "AUTO_INCREMENT column" = NULL queries. This would
@ -643,9 +653,23 @@ class Kohana_ORM extends Model implements serializable {
{
$model = $this->_related($column);
// Use this model's primary key value and foreign model's column
$col = $model->_object_name.'.'.$this->_has_one[$column]['foreign_key'];
$val = $this->pk();
if (! is_array($this->_has_one[$column]['foreign_key']))
{
// Use this model's primary key value and foreign model's column
$col = ($this->_disable_join_table_name ? '' : $model->_object_name.'.').$this->_has_one[$column]['foreign_key'];
$val = $this->_object[$this->_has_one[$column]['far_key']];
}
else
{
foreach ($this->_has_one[$column]['foreign_key'] as $fk)
{
// Simple has_many relationship, search where target model's foreign key is this model's primary key
$col = ($this->_disable_join_table_name ? '' : $model->_object_name.'.').$fk;
$val = $this->_object[$fk];
$model = $model->where($col, '=', $val);
}
}
$model->where($col, '=', $val)->find();
@ -655,29 +679,52 @@ class Kohana_ORM extends Model implements serializable {
{
$model = ORM::factory($this->_has_many[$column]['model']);
if (isset($this->_has_many[$column]['through']))
if (! is_array($this->_has_many[$column]['foreign_key']))
{
// Grab has_many "through" relationship table
$through = $this->_has_many[$column]['through'];
if (isset($this->_has_many[$column]['through']))
{
// Grab has_many "through" relationship table
$through = $this->_has_many[$column]['through'];
// Join on through model's target foreign key (far_key) and target model's primary key
$join_col1 = $through.'.'.$this->_has_many[$column]['far_key'];
$join_col2 = $model->_object_name.'.'.$model->_primary_key;
// Join on through model's target foreign key (far_key) and target model's primary key
$join_col1 = ($this->_disable_join_table_name ? '' : $through.'.').$this->_has_many[$column]['far_key'];
$join_col2 = ($this->_disable_join_table_name ? '' : $model->_object_name.'.').$model->_primary_key;
$model->join($through)->on($join_col1, '=', $join_col2);
$model->join($through)->on($join_col1, '=', $join_col2);
// Through table's source foreign key (foreign_key) should be this model's primary key
$col = $through.'.'.$this->_has_many[$column]['foreign_key'];
$val = $this->pk();
// Through table's source foreign key (foreign_key) should be this model's primary key
$col = ($this->_disable_join_table_name ? '' : $through.'.').$this->_has_many[$column]['foreign_key'];
$val = $this->pk();
}
else
{
// Simple has_many relationship, search where target model's foreign key is this model's primary key
$col = ($this->_disable_join_table_name ? '' : $model->_object_name.'.').$this->_has_many[$column]['foreign_key'];
$val = $this->_object[$this->_has_many[$column]['far_key']];
}
return $model->where($col, '=', $val);
}
else
{
// Simple has_many relationship, search where target model's foreign key is this model's primary key
$col = $model->_object_name.'.'.$this->_has_many[$column]['foreign_key'];
$val = $this->pk();
}
foreach ($this->_has_many[$column]['foreign_key'] as $mk => $fk)
{
if (isset($this->_has_many[$column]['through']))
{
throw new Kohana_Exception('This code hasnt been written yet!');
}
else
{
// Simple has_many relationship, search where target model's foreign key is this model's primary key
$col = ($this->_disable_join_table_name ? '' : $model->_object_name.'.').$fk;
$val = $this->_object[$mk];
}
return $model->where($col, '=', $val);
$model = $model->where($col, '=', $val);
}
return $model;
}
}
else
{
@ -1031,14 +1078,15 @@ class Kohana_ORM extends Model implements serializable {
{
$this->_db_builder->from(array($this->_table_name, $this->_object_name));
if ($multiple === FALSE)
if ($multiple === FALSE AND ! $this->_disable_limit)
{
// Only fetch 1 record
$this->_db_builder->limit(1);
}
// Select all columns by default
$this->_db_builder->select_array($this->_build_select());
if (! $this->_disable_wild_select)
$this->_db_builder->select_array($this->_build_select());
if ( ! isset($this->_db_applied['order_by']) AND ! empty($this->_sorting))
{
@ -1047,7 +1095,7 @@ class Kohana_ORM extends Model implements serializable {
if (strpos($column, '.') === FALSE)
{
// Sorting column for use in JOINs
$column = $this->_object_name.'.'.$column;
$column = ($this->_disable_join_table_name ? '' : $this->_object_name.'.').$column;
}
$this->_db_builder->order_by($column, $direction);
@ -1165,9 +1213,10 @@ class Kohana_ORM extends Model implements serializable {
* @param string $value The value to filter
* @return string
*/
protected function run_filter($field, $value)
protected function run_filter($field, $value, $filters=NULL)
{
$filters = $this->filters();
if (is_null($filters))
$filters = $this->filters();
// Get the filters for this column
$wildcards = empty($filters[TRUE]) ? array() : $filters[TRUE];

View File

@ -15,13 +15,15 @@ $application = 'application';
*/
$modules = 'modules';
$sysmodules = 'includes/kohana/modules';
/**
* The directory in which the Kohana resources are located. The system
* directory must contain the classes/kohana.php file.
*
* @link http://kohanaframework.org/guide/about.install#system
*/
$system = 'system';
$system = 'includes/kohana/system';
/**
* The default extension of resource files. If you change this, all resources
@ -74,6 +76,12 @@ if ( ! is_dir($modules) AND is_dir(DOCROOT.$modules))
$modules = DOCROOT.$modules;
}
// Make the system relative to the docroot, for symlink'd index.php
if ( ! is_dir($sysmodules) AND is_dir(DOCROOT.$sysmodules))
{
$sysmodules = DOCROOT.$sysmodules;
}
// Make the system relative to the docroot
if ( ! is_dir($system) AND is_dir(DOCROOT.$system))
{
@ -83,10 +91,11 @@ if ( ! is_dir($system) AND is_dir(DOCROOT.$system))
// Define the absolute paths for configured directories
define('APPPATH', realpath($application).DIRECTORY_SEPARATOR);
define('MODPATH', realpath($modules).DIRECTORY_SEPARATOR);
define('SMDPATH', realpath($sysmodules).DIRECTORY_SEPARATOR);
define('SYSPATH', realpath($system).DIRECTORY_SEPARATOR);
// Clean up the configuration vars
unset($application, $modules, $system);
unset($application, $modules, $sysmodules, $system);
/**
* Define the start time of the application, used for profiling.
@ -104,6 +113,8 @@ if ( ! defined('KOHANA_START_MEMORY'))
define('KOHANA_START_MEMORY', memory_get_usage());
}
define('PHPUNITTEST','192.168.242.3');
// Bootstrap the application
require APPPATH.'bootstrap'.EXT;
@ -122,4 +133,4 @@ if (($ob_len = ob_get_length()) !== FALSE)
}
// Enable the unittest module
Kohana::modules(Kohana::modules() + array('unittest' => MODPATH.'unittest'));
Kohana::modules(Kohana::modules() + array('unittest' => SMDPATH.'unittest'));

View File

@ -252,13 +252,17 @@ class Kohana_Debug {
{
$file = 'APPPATH'.DIRECTORY_SEPARATOR.substr($file, strlen(APPPATH));
}
elseif (strpos($file, MODPATH) === 0)
{
$file = 'MODPATH'.DIRECTORY_SEPARATOR.substr($file, strlen(MODPATH));
}
elseif (strpos($file, SYSPATH) === 0)
{
$file = 'SYSPATH'.DIRECTORY_SEPARATOR.substr($file, strlen(SYSPATH));
}
elseif (strpos($file, MODPATH) === 0)
elseif (strpos($file, SMDPATH) === 0)
{
$file = 'MODPATH'.DIRECTORY_SEPARATOR.substr($file, strlen(MODPATH));
$file = 'SMDPATH'.DIRECTORY_SEPARATOR.substr($file, strlen(SMDPATH));
}
elseif (strpos($file, DOCROOT) === 0)
{

View File

@ -64,7 +64,7 @@ class Kohana_Request_Client_Curl extends Request_Client_External {
$this->_options[CURLOPT_HEADER] = FALSE;
// Apply any additional options set to
$options += $this->_options;
$options = Arr::merge($options, $this->_options);
$uri = $request->uri();
@ -132,4 +132,4 @@ class Kohana_Request_Client_Curl extends Request_Client_External {
return $options;
}
} // End Kohana_Request_Client_Curl
} // End Kohana_Request_Client_Curl

View File

@ -250,7 +250,7 @@ class Kohana_CoreTest extends Unittest_TestCase
{
return array(
array(array('unittest' => MODPATH.'fo0bar')),
array(array('unittest' => MODPATH.'unittest', 'fo0bar' => MODPATH.'fo0bar')),
array(array('unittest' => SMDPATH.'unittest', 'fo0bar' => MODPATH.'fo0bar')),
);
}
@ -292,7 +292,7 @@ class Kohana_CoreTest extends Unittest_TestCase
{
return array(
array(array(), array()),
array(array('unittest' => MODPATH.'unittest'), array('unittest' => $this->dirSeparator(MODPATH.'unittest/'))),
array(array('unittest' => SMDPATH.'unittest'), array('unittest' => $this->dirSeparator(SMDPATH.'unittest/'))),
);
}

View File

@ -59,8 +59,8 @@ class Kohana_DebugTest extends Unittest_TestCase
'SYSPATH'.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.'kohana.php'
),
array(
MODPATH.$this->dirSeparator('unittest/classes/kohana/unittest/runner').EXT,
$this->dirSeparator('MODPATH/unittest/classes/kohana/unittest/runner').EXT
SMDPATH.$this->dirSeparator('unittest/classes/kohana/unittest/runner').EXT,
$this->dirSeparator('SMDPATH/unittest/classes/kohana/unittest/runner').EXT
),
);
}