Skip to content

Commit

Permalink
docs(system): strip redundant tabs or replace with 4 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
kilofox committed Jul 31, 2023
1 parent df7149d commit b49cf4a
Show file tree
Hide file tree
Showing 29 changed files with 950 additions and 950 deletions.
44 changes: 22 additions & 22 deletions system/guide/kohana/autoloading.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ You can easily gain access to other libraries if they include an autoloader. For

Somewhere in `application/bootstrap.php`, copy the following code:

/**
* Enable Zend Framework autoloading
*/
if ($path = Kohana::find_file('vendor', 'Zend/Loader'))
{
ini_set('include_path',
ini_get('include_path').PATH_SEPARATOR.dirname(dirname($path)));
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
}
/**
* Enable Zend Framework autoloading
*/
if ($path = Kohana::find_file('vendor', 'Zend/Loader'))
{
ini_set('include_path',
ini_get('include_path').PATH_SEPARATOR.dirname(dirname($path)));

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
}

#### Usage example

You can now autoload any Zend Framework classes from inside your Kohana application.

if ($validate($this->request->post()))
{
$mailer = new Zend_Mail;
$mailer->setBodyHtml($view)
->setFrom(Kohana::$config->load('site')->email_from)
->addTo($email)
->setSubject($message)
->send();
}
if ($validate($this->request->post()))
{
$mailer = new Zend_Mail;

$mailer->setBodyHtml($view)
->setFrom(Kohana::$config->load('site')->email_from)
->addTo($email)
->setSubject($message)
->send();
}
32 changes: 16 additions & 16 deletions system/guide/kohana/bootstrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Kohana is then initialized by calling [Kohana::init], and the log and [config](f
Kohana::init(array('
base_url' => '/kohana/',
index_file => false,
index_file => false,
));
// Attach the file writer to logging. Multiple writers are supported.
Expand All @@ -54,22 +54,22 @@ You can add conditional statements to make the bootstrap have different values b
*/
if (strpos($_SERVER['HTTP_HOST'], 'kohanaframework.org') !== FALSE)
{
// We are live!
Kohana::$environment = Kohana::PRODUCTION;
// We are live!
Kohana::$environment = Kohana::PRODUCTION;
// Turn off notices and strict errors
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
// Turn off notices and strict errors
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
}
/**
* Initialize Kohana, setting the default options.
... [trimmed]
*/
Kohana::init(array(
'base_url' => Kohana::$environment === Kohana::PRODUCTION ? '/' : '/kohanaframework.org/',
'caching' => Kohana::$environment === Kohana::PRODUCTION,
'profile' => Kohana::$environment !== Kohana::PRODUCTION,
'index_file' => FALSE,
'base_url' => Kohana::$environment === Kohana::PRODUCTION ? '/' : '/kohanaframework.org/',
'caching' => Kohana::$environment === Kohana::PRODUCTION,
'profile' => Kohana::$environment !== Kohana::PRODUCTION,
'index_file' => FALSE,
));
... [trimmed]
Expand All @@ -89,9 +89,9 @@ Each key in the array should be the name of the module, and the value is the pat
// Example excerpt from bootstrap.php
Kohana::modules(array(
'database' => MODPATH.'database',
'orm' => MODPATH.'orm',
'userguide' => MODPATH.'userguide',
'database' => MODPATH.'database',
'orm' => MODPATH.'orm',
'userguide' => MODPATH.'userguide',
));
~~~

Expand All @@ -104,8 +104,8 @@ Kohana::modules(array(
~~~
// The default route that comes with Kohana 3
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'Welcome',
'action' => 'index',
));
->defaults(array(
'controller' => 'Welcome',
'action' => 'index',
));
~~~
154 changes: 77 additions & 77 deletions system/guide/kohana/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ you need a **Config Writer**.
Implementing them is as simple as extending the
[Kohana_Config_Reader] / [Kohana_Config_Writer] interfaces:

class Kohana_Config_Database_Reader implements Kohana_Config_Reader
class Kohana_Config_Database_Writer extends Kohana_Config_Database_Reader implements Kohana_Config_Writer
class Kohana_Config_Database_Reader implements Kohana_Config_Reader
class Kohana_Config_Database_Writer extends Kohana_Config_Database_Reader implements Kohana_Config_Writer

You'll notice in the above example that the Database Writer extends the Database Reader.
This is the convention with config sources, the reasoning being that if you can write to a
Expand All @@ -35,44 +35,44 @@ the database source uses a column to distinguish between groups.

To load a config group simply call `Kohana::$config->load()` with the name of the group you wish to load:

$config = Kohana::$config->load('my_group');
$config = Kohana::$config->load('my_group');

`load()` will return an instance of [Config_Group] which encapsulates the config values and ensures
that any modifications made will be passed back to the config writers.

To get a config value from a [Config_Group] object simply call [Config_Group::get]:

$config = Kohana::$config->load('my_group');
$value = $config->get('var');
$config = Kohana::$config->load('my_group');
$value = $config->get('var');

To modify a value call [Config_Group::set]:

$config = Kohana::$config->load('my_group');
$config->set('var', 'new_value');
$config = Kohana::$config->load('my_group');
$config->set('var', 'new_value');

### Alternative methods for getting / setting config

In addition to the methods described above you can also access config values using dots to outline a path
from the config group to the value you want:

// Config file: database.php
return array(
'default' => array(
'connection' => array(
'hostname' => 'localhost'
)
)
);
// Config file: database.php
return array(
'default' => array(
'connection' => array(
'hostname' => 'localhost'
)
)
);

// Code which needs hostname:
$hostname = Kohana::$config->load('database.default.connection.hostname');
// Code which needs hostname:
$hostname = Kohana::$config->load('database.default.connection.hostname');


Which is equivalent to:

$config = Kohana::$config->load('database')->get('default');
$config = Kohana::$config->load('database')->get('default');

$hostname = $config['connection']['hostname'];
$hostname = $config['connection']['hostname'];

Obviously this method is a lot more compact than the original. However, please bear in mind that using
`dot.notation` is a _lot_ slower than calling `get()` and traversing the array yourself. Dot notation
Expand All @@ -81,13 +81,13 @@ can be useful if you only need one specific variable, but otherwise it's best to
As [Config_Group] extends [Array_Object](http://php.net/manual/en/class.arrayobject.php) you can also use array
syntax to get/set config vars:

$config = Kohana::$config->load('database');
$config = Kohana::$config->load('database');

// Getting the var
$hostname = $config['default']['connection']['hostname'];
// Getting the var
$hostname = $config['default']['connection']['hostname'];

// Setting the var
$config['default']['connection']['hostname'] = '127.0.0.1';
// Setting the var
$config['default']['connection']['hostname'] = '127.0.0.1';

Again, this syntax is more costly than calling `get()` / `set()`.

Expand All @@ -106,66 +106,66 @@ The position of sources in the stack is determined by how they are loaded in you
By default when you load a source it is pushed to the top of a stack:

// Stack: <empty>
Kohana::$config->attach(new Config_File);
// Stack: Config_File
Kohana::$config->attach(new Config_Database);
// Stack: Config_Database, Config_File
Kohana::$config->attach(new Config_File);
// Stack: Config_File
Kohana::$config->attach(new Config_Database);
// Stack: Config_Database, Config_File

In the example above, any config values found in the database will override those found in the filesystem.
For example, using the setup outlined above:

// Configuration in the filesystem:
email:
sender:
email: [email protected]
name: Unknown
method: smtp

// Configuration in the database:
email:
sender:
email: [email protected]
name: Kohana Bot

// Configuration returned by Kohana::$config->load('email')
email:
sender:
email: [email protected]
name: Kohana Bot
method: smtp
// Configuration in the filesystem:
email:
sender:
email: [email protected]
name: Unknown
method: smtp

// Configuration in the database:
email:
sender:
email: [email protected]
name: Kohana Bot

// Configuration returned by Kohana::$config->load('email')
email:
sender:
email: [email protected]
name: Kohana Bot
method: smtp

[!!] **Note:** The above syntax is simply pseudo code to illustrate the concept of config merging.

On some occasions you may want to append a config source to the bottom of the stack, to do this pass `FALSE`
as the second parameter to `attach()`:

// Stack: <empty>
Kohana::$config->attach(new Config_File);
// Stack: Config_File
Kohana::$config->attach(new Config_Database, FALSE);
// Stack: Config_File, Config_Database
// Stack: <empty>
Kohana::$config->attach(new Config_File);
// Stack: Config_File
Kohana::$config->attach(new Config_Database, FALSE);
// Stack: Config_File, Config_Database

In this example, any values found in the filesystem will override those found in the db. For example:

// Configuration in the filesystem:
email:
sender:
email: [email protected]
name: Unknown
method: smtp

// Configuration in the database:
email:
sender:
email: [email protected]
name: Kohana Bot

// Configuration returned by Kohana::$config->load('email')
email:
sender:
email: [email protected]
name: Unknown
method: smtp
// Configuration in the filesystem:
email:
sender:
email: [email protected]
name: Unknown
method: smtp

// Configuration in the database:
email:
sender:
email: [email protected]
name: Kohana Bot

// Configuration returned by Kohana::$config->load('email')
email:
sender:
email: [email protected]
name: Unknown
method: smtp

## Using different config sources based on the environment

Expand All @@ -180,14 +180,14 @@ so replacing the default `Config_File` source isn't really an option.
To get around this you can attach a separate config file reader which loads its config from a subdir of `config` called
"testing":

Kohana::$config->attach(new Config_File);
Kohana::$config->attach(new Config_File);

Kohana::$config->attach(new Config_Database);
Kohana::$config->attach(new Config_Database);

if (Kohana::$environment === Kohana::TESTING)
{
Kohana::$config->attach(new Config_File('config/testing'));
}
if (Kohana::$environment === Kohana::TESTING)
{
Kohana::$config->attach(new Config_File('config/testing'));
}

During normal development the config source stack looks like `Config_Database, Config_File('config')`. However,
when `Kohana::$environment === Kohana::TESTING` the stack looks like `Config_File('config/testing'), Config_Database, Config_File('config')`
Loading

0 comments on commit b49cf4a

Please sign in to comment.