17 |
18 | ## Disabling Error/Exception Handling
19 |
20 | If you do not want to use the internal error handling, you can disable it (highly discouraged) when calling [Kohana::init]:
21 |
22 | Kohana::init(array('errors' => FALSE));
23 |
24 | ## Error Reporting
25 |
26 | By default, Kohana displays all errors, including strict mode warnings. This is set using [error_reporting](http://php.net/error_reporting):
27 |
28 | error_reporting(E_ALL | E_STRICT);
29 |
30 | When you application is live and in production, a more conservative setting is recommended, such as ignoring notices:
31 |
32 | error_reporting(E_ALL & ~E_NOTICE);
33 |
34 | If you get a white screen when an error is triggered, your host probably has disabled displaying errors. You can turn it on again by adding this line just after your `error_reporting` call:
35 |
36 | ini_set('display_errors', TRUE);
37 |
38 | Errors should **always** be displayed, even in production, because it allows you to use [exception and error handling](debugging.errors) to serve a nice error page rather than a blank white screen when an error happens.
39 |
40 | ## HTTP Exception Handling
41 |
42 | Kohana comes with a robust system for handing http errors. It includes exception classes for each http status code. To trigger a 404 in your application (the most common scenario):
43 |
44 | throw HTTP_Exception::factory(404, 'File not found!');
45 |
46 | To register error pages for these, using 404 as an example:
47 |
48 | class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
49 |
50 | public function get_response()
51 | {
52 | $response = Response::factory();
53 |
54 | $view = View::factory('errors/404');
55 |
56 | // We're inside an instance of Exception here, all the normal stuff is available.
57 | $view->message = $this->getMessage();
58 |
59 | $response->body($view->render());
60 |
61 | return $response;
62 | }
63 |
64 | }
--------------------------------------------------------------------------------
/guide/kohana/files/classes.md:
--------------------------------------------------------------------------------
1 | # Classes
2 |
3 | TODO: Brief intro to classes.
4 |
5 | [Models](mvc/models) and [Controllers](mvc/controllers) are classes as well, but are treated slightly differently by Kohana. Read their respective pages to learn more.
6 |
7 | ## Helper or Library?
8 |
9 | Kohana 3 does not differentiate between "helper" classes and "library" classes like in previous versions. They are all placed in the `classes/` folder and follow the same conventions. The distinction is that in general, a "helper" class is used statically, (for examples see the [helpers included in Kohana](helpers)), and library classes are typically instantiated and used as objects (like the [Database query builders](../database/query/builder)). The distinction is not black and white, and is irrelevant anyways, since they are treated the same by Kohana.
10 |
11 | ## Creating a class
12 |
13 | To create a new class, simply place a file in the `classes/` directory at any point in the [Cascading Filesystem](files), that follows the [Class naming conventions](conventions#class-names-and-file-location). For example, lets create a `Foobar` class.
14 |
15 | // classes/Foobar.php
16 |
17 | class Foobar {
18 | static function magic() {
19 | // Does something
20 | }
21 | }
22 |
23 | We can now call `Foobar::magic()` any where and Kohana will [autoload](autoloading) the file for us.
24 |
25 | We can also put classes in subdirectories.
26 |
27 | // classes/Professor/Baxter.php
28 |
29 | class Professor_Baxter {
30 | static function teach() {
31 | // Does something
32 | }
33 | }
34 |
35 | We could now call `Professor_Baxter::teach()` any where we want.
36 |
37 | For examples of how to create and use classes, simply look at the 'classes' folder in `system` or any module.
38 |
39 | ## Namespacing your classes
40 |
41 | TODO: Discuss namespacing to provide transparent extension functionality in your own classes/modules.
42 |
--------------------------------------------------------------------------------
/guide/kohana/files/config.md:
--------------------------------------------------------------------------------
1 | # Config Files
2 |
3 | Configuration files are used to store any kind of configuration needed for a module, class, or anything else you want. They are plain PHP files, stored in the `config/` directory, which return an associative array:
4 |
5 | 'value',
9 | 'options' => array(
10 | 'foo' => 'bar',
11 | ),
12 | );
13 |
14 | If the above configuration file was called `myconf.php`, you could access it using:
15 |
16 | $config = Kohana::$config->load('myconf');
17 | $options = $config->get('options')
18 |
19 | ## Merge
20 |
21 | Configuration files are slightly different from most other files within the [cascading filesystem](files) in that they are **merged** rather than overloaded. This means that all configuration files with the same file path are combined to produce the final configuration. The end result is that you can overload *individual* settings rather than duplicating an entire file.
22 |
23 | For example, if we wanted to change or add to an entry in the inflector configuration file, we would not need to duplicate all the other entries from the default configuration file.
24 |
25 | // config/inflector.php
26 |
27 | array(
31 | 'die' => 'dice', // does not exist in default config file
32 | 'mouse' => 'mouses', // overrides 'mouse' => 'mice' in the default config file
33 | );
34 |
35 |
36 | ## Creating your own config files
37 |
38 | Let's say we want a config file to store and easily change things like the title of a website, or the google analytics code. We would create a config file, let's call it `site.php`:
39 |
40 | // config/site.php
41 |
42 | 'Our Shiny Website',
46 | 'analytics' => FALSE, // analytics code goes here, set to FALSE to disable
47 | );
48 |
49 | We could now call `Kohana::$config->load('site.title')` to get the site name, and `Kohana::$config->load('site.analytics')` to get the analytics code.
50 |
51 | Let's say we want an archive of versions of some software. We could use config files to store each version, and include links to download, documentation, and issue tracking.
52 |
53 | // config/versions.php
54 |
55 | array(
59 | 'codename' => 'Frog',
60 | 'download' => 'files/ourapp-1.0.0.tar.gz',
61 | 'documentation' => 'docs/1.0.0',
62 | 'released' => '06/05/2009',
63 | 'issues' => 'link/to/bug/tracker',
64 | ),
65 | '1.1.0' => array(
66 | 'codename' => 'Lizard',
67 | 'download' => 'files/ourapp-1.1.0.tar.gz',
68 | 'documentation' => 'docs/1.1.0',
69 | 'released' => '10/15/2009',
70 | 'issues' => 'link/to/bug/tracker',
71 | ),
72 | /// ... etc ...
73 | );
74 |
75 | You could then do the following:
76 |
77 | // In your controller
78 | $view->versions = Kohana::$config->load('versions');
79 |
80 | // In your view:
81 | foreach ($versions as $version)
82 | {
83 | // echo some html to display each version
84 | }
85 |
--------------------------------------------------------------------------------
/guide/kohana/files/i18n.md:
--------------------------------------------------------------------------------
1 | # I18n
2 |
3 | Kohana has a fairly simple and easy to use i18n system. It is slightly modeled after gettext, but is not as featureful. If you need the features of gettext, please use that :)
4 |
5 | ## __()
6 |
7 | Kohana has a __() function to do your translations for you. This function is only meant for small sections of text, not entire paragraphs or pages of translated text.
8 |
9 | To echo a translated string:
10 |
11 |
12 |
13 | This will echo 'Home' unless you've changed the defined language, which is explained below.
14 |
15 | ## Changing the displayed language
16 |
17 | Use the I18n::lang() method to change the displayed language:
18 |
19 | I18n::lang('fr');
20 |
21 | This will change the language to 'es-es'.
22 |
23 | ## Defining language files
24 |
25 | To define the language file for the above language change, create a `i18n/fr.php` that contains:
26 |
27 | 'Bonjour, monde!',
32 | );
33 |
34 | Now when you do `__('Hello, world!')`, you will get `Bonjour, monde!`
35 |
36 | ## I18n variables
37 |
38 | You can define variables in your __() calls like so:
39 |
40 | echo __('Hello, :user', array(':user' => $username));
41 |
42 | Your i18n key in your translation file will need to be defined as:
43 |
44 | 'Bonjour, :user',
49 | );
50 |
51 | ## Defining your own __() function
52 |
53 | You can define your own __() function by simply defining your own i18n class:
54 |
55 | 'Hello, world!',
17 | );
18 |
19 | You can also look in subfolders and sub-keys:
20 |
21 | Kohana::message('forms/contact', 'foobar.bar');
22 |
23 | This will look in the `messages/forms/contact.php` for the `[foobar][bar]` key:
24 |
25 | array(
29 | 'bar' => 'Hello, world!',
30 | ),
31 | );
32 |
33 | ## Notes
34 |
35 | * Don't use __() in your messages files, as these files can be cached and will not work properly.
36 | * Messages are merged by the cascading file system, not overwritten like classes and views.
37 |
--------------------------------------------------------------------------------
/guide/kohana/flow.md:
--------------------------------------------------------------------------------
1 | # Request Flow
2 |
3 | Every application follows the same flow:
4 |
5 | 1. Application starts from `index.php`.
6 | 1. The application, module, and system paths are set. (`APPPATH`, `MODPATH`, and `SYSPATH`)
7 | 2. Error reporting levels are set.
8 | 3. Install file is loaded, if it exists.
9 | 4. The bootstrap file, `APPPATH/bootstrap.php`, is included.
10 | 2. Once we are in `bootstrap.php`:
11 | 6. The [Kohana] class is loaded.
12 | 7. [Kohana::init] is called, which sets up error handling, caching, and logging.
13 | 8. [Kohana_Config] readers and [Kohana_Log] writers are attached.
14 | 9. [Kohana::modules] is called to enable additional modules.
15 | * Module paths are added to the [cascading filesystem](files).
16 | * Includes each module's `init.php` file, if it exists.
17 | * The `init.php` file can perform additional environment setup, including adding routes.
18 | 10. [Route::set] is called multiple times to define the [application routes](routing).
19 | 11. [Request::factory] is called to start processing the request.
20 | 1. Checks each route that has been set until a match is found.
21 | 2. Creates the controller instance and passes the request to it.
22 | 3. Calls the [Controller::before] method.
23 | 4. Calls the controller action, which generates the request response.
24 | 5. Calls the [Controller::after] method.
25 | * The above 5 steps can be repeated multiple times when using [HMVC sub-requests](requests).
26 | 3. Application flow returns to index.php
27 | 12. The main [Request] response is displayed
28 |
--------------------------------------------------------------------------------
/guide/kohana/helpers.md:
--------------------------------------------------------------------------------
1 | # Helpers
2 |
3 | Kohana comes with many static "helper" functions to make certain tasks easier.
4 |
5 | You can make your own helpers by simply making a class and putting it in the `classes` directory, and you can also extend any helper to modify or add new functions using transparent extension.
6 |
7 | - **[Arr]** - Array functions. Get an array key or default to a set value, get an array key by path, etc.
8 |
9 | - **[CLI]** - Parse command line options.
10 |
11 | - **[Cookie]** - Covered in more detail on the [Cookies](cookies) page.
12 |
13 | - **[Date]** - Useful date functions and constants. Time between two dates, convert between am/pm and military, date offset, etc.
14 |
15 | - **[Encrypt]** - Covered in more detail on the [Security](security) page.
16 |
17 | - **[Feed]** - Parse and create RSS feeds.
18 |
19 | - **[File]** - Get file type by mime, split and merge a file into small pieces.
20 |
21 | - **[Form]** - Create HTML form elements.
22 |
23 | - **[Fragment]** - Simple file based caching. Covered in more detail on the [Fragments](fragments) page.
24 |
25 | - **[HTML]** - Useful HTML functions. Encode, obfuscate, create script, anchor, and image tags, etc.
26 |
27 | - **[I18n]** - Internationalization helper for creating multilanguage sites.
28 |
29 | - **[Inflector]** - Change a word into plural or singular form, camelize or humanize a phrase, etc.
30 |
31 | - **[Kohana]** - The Kohana class is also a helper. Debug variables (like print_r but better), file loading, etc.
32 |
33 | - **[Num]** - Provides locale aware formating and english ordinals (th, st, nd, etc).
34 |
35 | - **[Profiler]** - Covered in more detail on the [Profiling](profiling) page.
36 |
37 | - **[Remote]** - Remote server access helper using [CURL](http://php.net/curl).
38 |
39 | - **[Request]** - Get the current request url, create expire tags, send a file, get the user agent, etc.
40 |
41 | - **[Route]** - Create routes, create an internal link using a route.
42 |
43 | - **[Security]** - Covered in more detail on the [Security](security) page.
44 |
45 | - **[Session]** - Covered in more detail on the [Sessions](sessions) page.
46 |
47 | - **[Text]** - Autolink, prevent window words, convert a number to text, etc.
48 |
49 | - **[URL]** - Create a relative or absolute URL, make a URL-safe title, etc.
50 |
51 | - **[UTF8]** - Provides multi-byte aware string functions like strlen, strpos, substr, etc.
52 |
53 | - **[Upload]** - Helper for uploading files from a form.
54 |
--------------------------------------------------------------------------------
/guide/kohana/index.md:
--------------------------------------------------------------------------------
1 | # What is Kohana?
2 |
3 | Kohana is an open source, [object oriented](http://en.wikipedia.org/wiki/Object-oriented_programming) [MVC](http://en.wikipedia.org/wiki/Model–view–controller "Model View Controller") [web framework](http://en.wikipedia.org/wiki/Web_application_framework) built using [PHP5](http://php.net/manual/intro-whatis "PHP Hypertext Preprocessor") by a team of volunteers that aims to be swift, secure, and small.
4 |
5 | [!!] Kohana is licensed under a [BSD license](http://kohanaframework.org/license), so you can legally use it for any kind of open source, commercial, or personal project.
6 |
7 | ## What makes Kohana great?
8 |
9 | Anything can be extended using the unique [filesystem](files) design, little or no [configuration](config) is necessary, [error handling](errors) helps locate the source of errors quickly, and [debugging](debugging) and [profiling](profiling) provide insight into the application.
10 |
11 | To help secure your applications, tools for [input validation](security/validation), [signed cookies](security/cookies), [form] and [HTML] generators are all included. The [database](security/database) layer provides protection against [SQL injection](http://wikipedia.org/wiki/SQL_injection). Of course, all official code is carefully written and reviewed for security.
12 |
13 | ## Contribute to the Documentation
14 |
15 | We are working very hard to provide complete documentation. To help improve the guide, please [fork the userguide](http://github.com/kohana/userguide), make your changes, and send a pull request. If you are not familiar with Git, you can also submit a [feature request](http://dev.kohanaframework.org/projects/kohana3/issues) (requires registration).
16 |
17 | ## Unofficial Documentation
18 |
19 | If you are having trouble finding an answer here, have a look through the [unofficial wiki](http://kerkness.ca/kowiki/doku.php). Your answer may also be found by searching the [forum](http://forum.kohanaframework.org/) or [Stack Overflow](http://stackoverflow.com/questions/tagged/kohana) followed by asking your question on either. Additionally, you can chat with the community of developers on the freenode [#kohana](irc://irc.freenode.net/kohana) IRC channel.
--------------------------------------------------------------------------------
/guide/kohana/install.md:
--------------------------------------------------------------------------------
1 | # Requirements
2 |
3 | [!!] Before continuing, make sure you have a web server (like Apache) configured with the following requirements.
4 |
5 | - PHP 5.3.3 or newer.
6 | - [Iconv Extension](http://php.net/iconv)
7 | - [Character Type (CTYPE) Extension](http://php.net/ctype)
8 |
9 | # Download
10 |
11 | You can get the latest **stable** release on the [Kohana website](http://kohanaframework.org/). This will give you a fully functional application with an `application`, `modules`, and `system` directory.
12 |
13 | [!!] You can find information about the file structure on the [Cascading Filesystem](files) page.
14 |
15 | Once downloaded, you should extract the Kohana application to a directory where the web server can access it. Going forward, we are going to assume you've extracted the application to a `kohana` directory such that `http://localhost/kohana/index.php` is pointing to the `index.php` file in the Kohana release.
16 |
17 | # Configure
18 |
19 | Before the application can be run, you will need to make a few changes to the `application/bootstrap.php` file. This file is the first one to be included by `index.php` and sets up most of the global options for the application. Open `application/bootstrap.php` and make the following changes:
20 |
21 | - Set the default [timezone](http://php.net/timezones) for your application.
22 | ~~~
23 | // Example of changing timezone to Sao Paulo, Brazil
24 | date_default_timezone_set('America/Sao_Paulo');
25 | ~~~
26 | - Set the `base_url` in the [Kohana::init] call to reflect the location of the kohana folder on your server relative to the document root.
27 | ~~~
28 | /**
29 | * Example of kohana's installation at /var/www/kohana and
30 | * Apache's DocumentRoot configured to /var/www
31 | */
32 | Kohana::init(array(
33 | 'base_url' => '/kohana/',
34 | ));
35 | ~~~
36 |
37 | - List your trusted hosts. Open `application/config/url.php` and add regex patterns of the hosts you expect your application to be accessible from.
38 |
39 | [!!] Do not forget to escape your dots (.) as these are regex patterns. These patterns should always fully match, as they are prepended with `^` and appended with `$`.
40 | ~~~
41 | return array(
42 | 'trusted_hosts' => array(
43 | 'example\.org',
44 | '.*\.example\.org',
45 | ),
46 | );
47 | ~~~
48 |
49 | - Define a salt for the `Cookie` class.
50 | ~~~
51 | Cookie::$salt = 'some-really-long-cookie-salt-here';
52 | ~~~
53 |
54 | - Make sure the `application/cache` and `application/logs` directories are writable by the web server.
55 | ~~~
56 | sudo chmod -R a+rwx application/cache
57 | sudo chmod -R a+rwx application/logs
58 | ~~~
59 |
60 | [!!] Make sure to use a unique salt for your application and never to share it. Take a look at the [Cookies](cookies) page for more information on how cookies work in Kohana. If you do not define a `Cookie::$salt` value, Kohana will throw an exception when it encounters any cookie on your domain.
61 |
62 | - Test your installation by opening [http://localhost/kohana](http://localhost/kohana).
63 |
64 | You should see the installation page. If it reports any errors, you will need to correct them before continuing.
65 |
66 | 
67 |
68 | Once your install page reports that your environment is set up correctly you need to either rename or delete `install.php`. Kohana is now installed and you should see the output of the welcome controller:
69 |
70 | 
71 |
72 | ## Installing Kohana From GitHub
73 |
74 | The [source code](http://github.com/kohana/kohana) for Kohana is hosted with [GitHub](http://github.com). To install Kohana using the github source code first you need to install [git](http://git-scm.com/). Visit [http://help.github.com](http://help.github.com) for details on how to install git on your platform.
75 |
76 | [!!] For more information on installing Kohana using git, see the [Working with Git](tutorials/git) tutorial.
77 |
--------------------------------------------------------------------------------
/guide/kohana/menu.md:
--------------------------------------------------------------------------------
1 | ## [Kohana]()
2 |
3 | - [Installation](install)
4 | - Getting Started
5 | - [Conventions and Style](conventions)
6 | - [Model View Controller](mvc)
7 | - [Controllers](mvc/controllers)
8 | - [Models](mvc/models)
9 | - [Views](mvc/views)
10 | - [Cascading Filesystem](files)
11 | - [Class Files](files/classes)
12 | - [Config Files](files/config)
13 | - [Translation Files](files/i18n)
14 | - [Message Files](files/messages)
15 | - [Configuration](config)
16 | - [Request Flow](flow)
17 | - [Bootstrap](bootstrap)
18 | - [Modules](modules)
19 | - [Routing](routing)
20 | - [Error Handling](errors)
21 | - [Tips & Common Mistakes](tips)
22 | - [Upgrading from v3.2](upgrading)
23 | - [Upgrading from v3.3.3.1](upgrading-from-3-3-3-1)
24 | - Basic Usage
25 | - [Debugging](debugging)
26 | - [Loading Classes](autoloading)
27 | - [Transparent Extension](extension)
28 | - [Helpers](helpers)
29 | - [Requests](requests)
30 | - [Sessions](sessions)
31 | - [Cookies](cookies)
32 | - [Fragments](fragments)
33 | - [Profiling](profiling)
34 | - [Security](security)
35 | - [XSS](security/xss)
36 | - [Validation](security/validation)
37 | - [Cookies](security/cookies)
38 | - [Database](security/database)
39 | - [Encryption](security/encryption)
40 | - [Deploying](security/deploying)
41 | - Tutorials
42 | - [Hello World](tutorials/hello-world)
43 | - [Simple MVC](tutorials/simple-mvc)
44 | - [Custom Error Pages](tutorials/error-pages)
45 | - [Clean URLs](tutorials/clean-urls)
46 | - [Sharing Kohana](tutorials/sharing-kohana)
47 | - [Kohana as a Library](tutorials/library-kohana)
48 | - [Working with Git](tutorials/git)
49 |
--------------------------------------------------------------------------------
/guide/kohana/modules.md:
--------------------------------------------------------------------------------
1 | # Modules
2 |
3 | Modules are simply an addition to the [Cascading Filesystem](files). A module can add any kind of file (controllers, views, classes, config files, etc.) to the filesystem available to Kohana (via [Kohana::find_file]). This is useful to make any part of your application more transportable or shareable between different apps. For example, creating a new modeling system, a search engine, a css/js manager, etc.
4 |
5 | ## Where to find modules
6 |
7 | Kolanos has created [kohana-universe](http://github.com/kolanos/kohana-universe/tree/master/modules/), a fairly comprehensive list of modules that are available on Github. To get your module listed there, send him a message via Github.
8 |
9 | Mon Geslani created a [very nice site](http://kohana.mongeslani.com/) that allows you to sort Github modules by activity, watchers, forks, etc. It seems to not be as comprehensive as kohana-universe.
10 |
11 | Andrew Hutchings has created [kohana-modules](http://www.kohana-modules.com) which is similar to the above sites.
12 |
13 | ## Enabling modules
14 |
15 | Modules are enabled by calling [Kohana::modules] and passing an array of `'name' => 'path'`. The name isn't important, but the path obviously is. A module's path does not have to be in `MODPATH`, but usually is. You can only call [Kohana::modules] once.
16 |
17 | Kohana::modules(array(
18 | 'auth' => MODPATH.'auth', // Basic authentication
19 | 'cache' => MODPATH.'cache', // Caching with multiple backends
20 | 'codebench' => MODPATH.'codebench', // Benchmarking tool
21 | 'database' => MODPATH.'database', // Database access
22 | 'image' => MODPATH.'image', // Image manipulation
23 | 'orm' => MODPATH.'orm', // Object Relationship Mapping
24 | 'oauth' => MODPATH.'oauth', // OAuth authentication
25 | 'pagination' => MODPATH.'pagination', // Paging of results
26 | 'unittest' => MODPATH.'unittest', // Unit testing
27 | 'userguide' => MODPATH.'userguide', // User guide and API documentation
28 | ));
29 |
30 | ## Init.php
31 |
32 | When a module is activated, if an `init.php` file exists in that module's directory, it is included. This is the ideal place to have a module include routes or other initialization necessary for the module to function. The Userguide and Codebench modules have init.php files you can look at.
33 |
34 | ## How modules work
35 |
36 | A file in an enabled module is virtually the same as having that exact file in the same place in the application folder. The main difference being that it can be overwritten by a file of the same name in a higher location (a module enabled after it, or the application folder) via the [Cascading Filesystem](files). It also provides an easy way to organize and share your code.
37 |
38 | ## Creating your own module
39 |
40 | To create a module simply create a folder (usually in `DOCROOT/modules`) and place the files you want to be in the module there, and activate that module in your bootstrap. To share your module, you can upload it to [Github](http://github.com). You can look at examples of modules made by [Kohana](http://github.com/kohana) or [other users](#where-to-find-modules).
--------------------------------------------------------------------------------
/guide/kohana/mvc.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | Discuss the MVC pattern, as it pertains to Kohana. Perhaps have an image, etc.
--------------------------------------------------------------------------------
/guide/kohana/mvc/models.md:
--------------------------------------------------------------------------------
1 | # Models
2 |
3 | From Wikipedia:
4 |
5 | > The model manages the behavior and data of the application domain,
6 | > responds to requests for information about its state (usually from the view),
7 | > and responds to instructions to change state (usually from the controller).
8 |
9 | Creating a simple model:
10 |
11 | class Model_Post extends Model
12 | {
13 | public function do_stuff()
14 | {
15 | // This is where you do domain logic...
16 | }
17 | }
18 |
19 | If you want database access, have your model extend the Model_Database class:
20 |
21 | class Model_Post extends Model_Database
22 | {
23 | public function do_stuff()
24 | {
25 | // This is where you do domain logic...
26 | }
27 |
28 | public function get_stuff()
29 | {
30 | // Get stuff from the database:
31 | return $this->db->query(...);
32 | }
33 | }
34 |
35 | If you want CRUD/ORM capabilities, see the [ORM Module](../../guide/orm)
--------------------------------------------------------------------------------
/guide/kohana/profiling.md:
--------------------------------------------------------------------------------
1 | # Profiling
2 |
3 | Kohana provides a very simple way to display statistics about your application:
4 |
5 | 1. Common [Kohana] method calls, such as [Kohana::find_file()].
6 | 2. Requests. Including the main request, as well as any sub-requests.
7 | 3. [Database] queries
8 | 4. Average execution times for your application
9 |
10 | [!!] In order for profiling to work, the `profile` setting must be `TRUE` in your [Kohana::init()] call in your bootstrap.
11 |
12 | ## Profiling your code
13 |
14 | You can easily add profiling to your own functions and code. This is done using the [Profiler::start()] function. The first parameter is the group, the second parameter is the name of the benchmark.
15 |
16 | public function foobar($input)
17 | {
18 | // Be sure to only profile if it's enabled
19 | if (Kohana::$profiling === TRUE)
20 | {
21 | // Start a new benchmark
22 | $benchmark = Profiler::start('Your Category', __FUNCTION__);
23 | }
24 |
25 | // Do some stuff
26 |
27 | if (isset($benchmark))
28 | {
29 | // Stop the benchmark
30 | Profiler::stop($benchmark);
31 | }
32 |
33 | return $something;
34 | }
35 |
36 | ## How to read the profiling report
37 |
38 | The benchmarks are sorted into groups. Each benchmark will show its name, how many times it was run (show in parenthesis after the benchmark name), and then the min, max, average, and total time and memory spent on that benchmark. The total column will have shaded backgrounds to show the relative times between benchmarks in the same group.
39 |
40 | At the very end is a group called "Application Execution". This keeps track of how long each execution has taken. The number in parenthesis is how many executions are being compared. It shows the fastest, slowest, and average time and memory usage of the last several requsets. The last box is the time and memory usage of the current request.
41 |
42 | ((This could use a picture of a profiler with some database queries, etc. with annotations to point out each area as just described.))
43 |
44 | ## Displaying the profiler
45 |
46 | You can display or collect the current [profiler] statistics at any time:
47 |
48 |
49 |
50 | ## Preview
51 |
52 | (This is the actual profiler stats for this page.)
53 |
54 | {{profiler/stats}}
--------------------------------------------------------------------------------
/guide/kohana/security.md:
--------------------------------------------------------------------------------
1 | General security concerns, like using the Security class, CSRF, and a brief intro to XSS, database security, etc. Also mention the security features that Kohana provides, like cleaning globals.
--------------------------------------------------------------------------------
/guide/kohana/security/cookies.md:
--------------------------------------------------------------------------------
1 | Discuss security of cookies, like changing the encryption key in the config.
2 |
3 | Not sure why I'm linking to this:
--------------------------------------------------------------------------------
/guide/kohana/security/database.md:
--------------------------------------------------------------------------------
1 | Discuss database security.
2 |
3 | How to avoid injection, etc.
4 |
5 | Not sure why I'm linking to this:
--------------------------------------------------------------------------------
/guide/kohana/security/deploying.md:
--------------------------------------------------------------------------------
1 | Changes that should happen when you deploy. (Production)
2 |
3 | Security settings from:
4 |
5 |
6 |
7 |
8 | ## Setting up a production environment
9 |
10 | There are a few things you'll want to do with your application before moving into production.
11 |
12 | 1. See the [Bootstrap page](bootstrap) in the docs.
13 | This covers most of the global settings that would change between environments.
14 | As a general rule, you should enable caching and disable profiling ([Kohana::init] settings) for production sites.
15 | [Route::cache] can also help if you have a lot of routes.
16 | 2. Turn on APC or some kind of opcode caching.
17 | This is the single easiest performance boost you can make to PHP itself. The more complex your application, the bigger the benefit of using opcode caching.
18 |
19 | /**
20 | * Set the environment string by the domain (defaults to Kohana::DEVELOPMENT).
21 | */
22 | Kohana::$environment = ($_SERVER['SERVER_NAME'] !== 'localhost') ? Kohana::PRODUCTION : Kohana::DEVELOPMENT;
23 | /**
24 | * Initialise Kohana based on environment
25 | */
26 | Kohana::init(array(
27 | 'base_url' => '/',
28 | 'index_file' => FALSE,
29 | 'profile' => Kohana::$environment !== Kohana::PRODUCTION,
30 | 'caching' => Kohana::$environment === Kohana::PRODUCTION,
31 | ));
32 |
--------------------------------------------------------------------------------
/guide/kohana/security/xss.md:
--------------------------------------------------------------------------------
1 | # Cross-Site Scripting (XSS) Security
2 |
3 | *This page is not comprehensive and should not be considered a complete guide to XSS prevention.*
4 |
5 | The first step to preventing [XSS](http://wikipedia.org/wiki/Cross-Site_Scripting) attacks is knowing when you need to protect yourself. XSS can only be triggered when it is displayed within HTML content, sometimes via a form input or being displayed from database results. Any global variable that contains client information can be tainted. This includes `$_GET`, `$_POST`, and `$_COOKIE` data.
6 |
7 | ## Prevention
8 |
9 | There are a few simple rules to follow to guard your application HTML against XSS. If you do not want HTML in a variable, use [strip_tags](http://php.net/strip_tags) to remove all unwanted HTML tags from a value.
10 |
11 | [!!] If you allow users to submit HTML to your application, it is highly recommended to use an HTML cleaning tool such as [HTML Purifier](http://htmlpurifier.org/) or [HTML Tidy](http://php.net/tidy).
12 |
13 | The second is to always escape data when inserting into HTML. The [HTML] class provides generators for many common tags, including script and stylesheet links, anchors, images, and email (mailto) links. Any untrusted content should be escaped using [HTML::chars].
14 |
15 | ## References
16 |
17 | * [OWASP XSS Cheat Sheet](http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet)
--------------------------------------------------------------------------------
/guide/kohana/tips.md:
--------------------------------------------------------------------------------
1 | # Tips and Common Mistakes
2 |
3 | This is a collection of tips and common mistakes or errors you may encounter.
4 |
5 | ## Never edit the `system` folder!
6 |
7 | You should (almost) never edit the system folder. Any change you want to make to files in system and modules can be made via the [cascading filesystem](files) and [transparent extension](extension) and won't break when you try to update your Kohana version.
8 |
9 | ## Don't try and use one route for everything
10 |
11 | Kohana 3 [routes](routing) are very powerful and flexible, don't be afraid to use as many as you need to make your app function the way you want!
12 |
13 | ## Files not found on some systems
14 |
15 | As of Kohana 3.3, classes are autoloaded using the case-sensitive PSR-0 autoloader. This means that using the class Foo {} with a file in classes/foo.php will work on case-insensitive file systems (such as the default HFS+ FS used in Mac OS X) but will fail when used on a case-sensitive FS (typical on many production Linux servers).
16 |
17 | ## Handling lots of routes
18 |
19 | Sometimes your application is sufficiently complex that you have many routes and it becomes unmanageable to put them all in bootstrap.php. If this is the case, simply make a `routes.php` file in APPPATH and require that in your bootstrap: `require_once APPPATH.'routes'.EXT;`
20 |
21 | ## Reflection_Exception
22 |
23 | If you get a Reflection_Exception when setting up your site, it is almost certainly because your [Kohana::init] 'base_url' setting is wrong. If your base url is correct something is probably wrong with your [routes](routing).
24 |
25 | ReflectionException [ -1 ]: Class controller_ does not exist
26 | // where is part of the url you entered in your browser
27 |
28 | ### Solution {#reflection-exception-solution}
29 |
30 | Set your [Kohana::init] 'base_url' to the correct setting. The base url should be the path to your index.php file relative to the webserver document root.
31 |
32 | ## ORM/Session __sleep() bug
33 |
34 | There is a bug in php which can corrupt your session after a fatal error. A production server shouldn't have uncaught fatal errors, so this bug should only happen during development, when you do something stupid and cause a fatal error. On the next page load you will get a database connection error, then all subsequent page loads will display the following error:
35 |
36 | ErrorException [ Notice ]: Undefined index: id
37 | MODPATH/orm/classes/kohana/orm.php [ 1308 ]
38 |
39 | ### Solution {#orm-session-sleep-solution}
40 |
41 | To fix this, clear your cookies for that domain to reset your session. This should never happen on a production server, so you won't have to explain to your clients how to clear their cookies. You can see the [discussion on this issue](http://dev.kohanaframework.org/issues/3242) for more details.
42 |
--------------------------------------------------------------------------------
/guide/kohana/tutorials/clean-urls.md:
--------------------------------------------------------------------------------
1 | # Clean URLs
2 |
3 | Removing `index.php` from your urls.
4 |
5 | To keep your URLs clean, you will probably want to be able to access your app without having `/index.php/` in the URL. There are two steps to remove `index.php` from the URL.
6 |
7 | 1. Edit the bootstrap file
8 | 2. Set up rewriting
9 |
10 | ## 1. Configure Bootstrap
11 |
12 | The first thing you will need to change is the `index_file` setting of [Kohana::init] to false:
13 |
14 | Kohana::init(array(
15 | 'base_url' => '/myapp/',
16 | 'index_file' => FALSE,
17 | ));
18 |
19 | This change will make it so all of the links generated using [URL::site], [URL::base], and [HTML::anchor] will no longer include "index.php" in the URL. All generated links will start with `/myapp/` instead of `/myapp/index.php/`.
20 |
21 | ## 2. URL Rewriting
22 |
23 | Enabling rewriting is done differently, depending on your web server.
24 |
25 | Rewriting will make it so urls will be passed to index.php.
26 |
27 | ## Apache
28 |
29 | Rename `example.htaccess` to only `.htaccess` and alter the `RewriteBase` line to match the `base_url` setting from your [Kohana::init]
30 |
31 | RewriteBase /myapp/
32 |
33 | The rest of the `.htaccess file` rewrites all requests through index.php, unless the file exists on the server (so your css, images, favicon, etc. are still loaded like normal). In most cases, you are done!
34 |
35 | ### 404 errors
36 |
37 | If you get a "404 Not Found" error when trying to view a page then it's likely Apache is not configured to read the `.htaccess` file.
38 |
39 | In the main apache configuration file (usually `httpd.conf`), or in the virtual server configuration file, check that the `AccessFileName` directive is set to `.htaccess` and the `AllowOverride` directive is set to `All`.
40 |
41 | AccessFileName .htaccess
42 |
43 |
44 | AllowOverride All
45 |
46 |
47 |
48 | ### Failed!
49 |
50 | If you get a "Internal Server Error" or "No input file specified" error, try changing:
51 |
52 | RewriteRule ^(?:application|modules|system)\b - [F,L]
53 |
54 | Instead, we can try a slash:
55 |
56 | RewriteRule ^(application|modules|system)/ - [F,L]
57 |
58 | If that doesn't work, try changing:
59 |
60 | RewriteRule .* index.php/$0 [PT]
61 |
62 | To something more simple:
63 |
64 | RewriteRule .* index.php [PT]
65 |
66 | ### Still Failed!
67 |
68 | If you are still getting errors, check to make sure that your host supports URL `mod_rewrite`. If you can change the Apache configuration, add these lines to the configuration, usually `httpd.conf`:
69 |
70 |
71 | Order allow,deny
72 | Allow from all
73 | AllowOverride All
74 |
75 |
76 | You should also check your Apache logs to see if they can shed some light on the error.
77 |
78 | ## NGINX
79 |
80 | It is hard to give examples of nginx configuration, but here is a sample for a server:
81 |
82 | location / {
83 | index index.php index.html index.htm;
84 | try_files $uri index.php;
85 | }
86 |
87 | location = index.php {
88 | include fastcgi.conf;
89 | fastcgi_pass 127.0.0.1:9000;
90 | fastcgi_index index.php;
91 | }
92 |
93 | If you are having issues getting this working, enable debug level logging in nginx and check the access and error logs.
94 |
--------------------------------------------------------------------------------
/guide/kohana/tutorials/error-pages.md:
--------------------------------------------------------------------------------
1 | # Custom Error Pages
2 |
3 | Custom error pages allow you to display a friendly error message to users, rather than the standard Kohana stack trace.
4 |
5 | ## Prerequisites
6 |
7 | 1. You will need `'errors' => TRUE` passed to [Kohana::init]. This will convert PHP-errors into exceptions which are easier to handle (The default value is `TRUE`).
8 | 2. Custom error pages will only be used to handle throw [HTTP_Exception]'s. If you simply set a status of, for example, 404 via [Respose::status] the custom page will not be used.
9 |
10 | ## Extending the HTTP_Exception classes
11 |
12 | Handling [HTTP_Exception]'s in Kohana has become easier with the changes introduced in 3.3.
13 |
14 | For each [HTTP_Exception] class we can individually override the generation of the [Response] instance.
15 |
16 | [!!] Note: We can also use HMVC to issue a sub-request to another page rather than generating the [Response] in the [HTTP_Exception] itself.
17 |
18 | For example, to handle 404 pages we can do this in APPPATH/classes/HTTP/Exception/404.php:
19 |
20 | class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
21 |
22 | /**
23 | * Generate a Response for the 404 Exception.
24 | *
25 | * The user should be shown a nice 404 page.
26 | *
27 | * @return Response
28 | */
29 | public function get_response()
30 | {
31 | $view = View::factory('errors/404');
32 |
33 | // Remembering that `$this` is an instance of HTTP_Exception_404
34 | $view->message = $this->getMessage();
35 |
36 | $response = Response::factory()
37 | ->status(404)
38 | ->body($view->render());
39 |
40 | return $response;
41 | }
42 | }
43 |
44 | Another example, this time to handle 401 Unauthorized errors (aka "Not Logged In") we can do this in APPPATH/classes/HTTP/Exception/401.php:
45 |
46 | class HTTP_Exception_401 extends Kohana_HTTP_Exception_401 {
47 |
48 | /**
49 | * Generate a Response for the 401 Exception.
50 | *
51 | * The user should be redirect to a login page.
52 | *
53 | * @return Response
54 | */
55 | public function get_response()
56 | {
57 | $response = Response::factory()
58 | ->status(401)
59 | ->headers('Location', URL::site('account/login'));
60 |
61 | return $response;
62 | }
63 | }
64 |
65 | Finally, to override the default [Response] for all [HTTP_Exception]'s without a more specific override we can do this in APPPATH/classes/HTTP/Exception.php:
66 |
67 | class HTTP_Exception extends Kohana_HTTP_Exception {
68 |
69 | /**
70 | * Generate a Response for all Exceptions without a more specific override
71 | *
72 | * The user should see a nice error page, however, if we are in development
73 | * mode we should show the normal Kohana error page.
74 | *
75 | * @return Response
76 | */
77 | public function get_response()
78 | {
79 | // Lets log the Exception, Just in case it's important!
80 | Kohana_Exception::log($this);
81 |
82 | if (Kohana::$environment >= Kohana::DEVELOPMENT)
83 | {
84 | // Show the normal Kohana error page.
85 | return parent::get_response();
86 | }
87 | else
88 | {
89 | // Generate a nicer looking "Oops" page.
90 | $view = View::factory('errors/default');
91 |
92 | $response = Response::factory()
93 | ->status($this->getCode())
94 | ->body($view->render());
95 |
96 | return $response;
97 | }
98 | }
99 | }
--------------------------------------------------------------------------------
/guide/kohana/tutorials/sharing-kohana.md:
--------------------------------------------------------------------------------
1 | # Sharing Kohana
2 |
3 | Kohana follows a [front controller pattern](http://en.wikipedia.org/wiki/Front_Controller_pattern "Front Controller pattern") (which means that all requests are sent to `index.php`) and as such the [filesystem](files) is very configurable. Inside of `index.php` you can change the `$application`, `$modules`, and `$system` paths.
4 |
5 | [!!] There is a security check at the top of every Kohana file to prevent it from being accessed without using the front controller. Also, the `.htaccess` file should protect those folders as well. Moving the application, modules, and system directories to a location that cannot be accessed via the web can add another layer of security, but is optional.
6 |
7 | The `$application` variable lets you set the directory that contains your application files. By default, this is `application`. The `$modules` variable lets you set the directory that contains module files. The `$system` variable lets you set the directory that contains the default Kohana files. You can move these three directories anywhere.
8 |
9 | For instance, by default the directories are set up like this:
10 |
11 | www/
12 | index.php
13 | application/
14 | modules/
15 | system/
16 |
17 | You could move the directories out of the web root so they look like this:
18 |
19 | application/
20 | modules/
21 | system/
22 | www/
23 | index.php
24 |
25 | Then you would need to change the settings in `index.php` to be:
26 |
27 | $application = '../application';
28 | $modules = '../modules';
29 | $system = '../system';
30 |
31 | ## Sharing system and modules
32 |
33 | To take this a step further, we could point several Kohana apps to the same system and modules folders. For example (and this is just an example, you could arrange these anyway you want):
34 |
35 | apps/
36 | foobar/
37 | application/
38 | www/
39 | bazbar/
40 | application/
41 | www/
42 | kohana/
43 | 3.0.6/
44 | 3.0.7/
45 | 3.0.8/
46 | modules/
47 |
48 | And you would need to change the settings in `index.php` to be:
49 |
50 | $application = '../application';
51 | $system = '../../../kohana/3.0.6';
52 | $modules = '../../../kohana/modules';
53 |
54 | With this method each app can point to a central copy of Kohana, and when you add a new version, allow you to quickly update the apps by editing their respective `index.php` files.
--------------------------------------------------------------------------------
/guide/kohana/tutorials/simple-mvc.md:
--------------------------------------------------------------------------------
1 | Simple example of controller model and view working together.
--------------------------------------------------------------------------------
/guide/kohana/upgrading-from-3-3-3-1.md:
--------------------------------------------------------------------------------
1 | # Upgrading from 3.3.3.1
2 |
3 | Minor version upgrades are usually done in a drop-in fashion. Unfortunately, however, upgrading from 3.3.3.1 to 3.3.4 needs a little configuration. This is because a [security disclosure from HP Fortify](https://github.com/kohana/kohana/issues/74), that unveiled a serious [host header attack](https://github.com/kohana/core/issues/613) vulnerability.
4 |
5 | [!!] You *might* still be able to have a drop-in upgrade, in case you have set the `base_url` in the [Kohana::init] call to an absolute URL. We advise you however that you follow the step below to make your application secure, in case some day you decide to change your `base_url` to a relative URL.
6 |
7 | ## Trusted Hosts
8 |
9 | You need to setup a list of trusted hosts. Trusted hosts are hosts that you expect your application to be accessible from.
10 |
11 | Open `application/config/url.php` and add regex patterns of these hosts. An example is given hereunder:
12 |
13 | ~~~
14 | return array(
15 | 'trusted_hosts' => array(
16 | 'example\.org',
17 | '.*\.example\.org',
18 | ),
19 | );
20 | ~~~
21 |
22 | [!!] Do not forget to escape your dots (.) as these are regex patterns. These patterns should always fully match, as they are prepended with `^` and appended with `$`.
23 |
24 |
--------------------------------------------------------------------------------
/i18n/en.php:
--------------------------------------------------------------------------------
1 | 'Español',
6 | 'Hello, world!' => '¡Hola, mundo!',
7 |
8 | );
9 |
--------------------------------------------------------------------------------
/i18n/fr.php:
--------------------------------------------------------------------------------
1 | 'Français',
6 | 'Hello, world!' => 'Bonjour, monde!',
7 |
8 | );
9 |
--------------------------------------------------------------------------------
/koharness.php:
--------------------------------------------------------------------------------
1 | array(
5 | 'unittest' => __DIR__ . '/vendor/kohana/unittest'
6 | ),
7 | 'syspath' => __DIR__,
8 | );
9 |
--------------------------------------------------------------------------------
/media/guide/kohana/cascading_filesystem.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kohana/core/bdbe81afb5a09cee4269d2e2210a0d293265231a/media/guide/kohana/cascading_filesystem.png
--------------------------------------------------------------------------------
/media/guide/kohana/hello_world_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kohana/core/bdbe81afb5a09cee4269d2e2210a0d293265231a/media/guide/kohana/hello_world_1.png
--------------------------------------------------------------------------------
/media/guide/kohana/hello_world_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kohana/core/bdbe81afb5a09cee4269d2e2210a0d293265231a/media/guide/kohana/hello_world_2.png
--------------------------------------------------------------------------------
/media/guide/kohana/hello_world_2_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kohana/core/bdbe81afb5a09cee4269d2e2210a0d293265231a/media/guide/kohana/hello_world_2_error.png
--------------------------------------------------------------------------------
/media/guide/kohana/install.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kohana/core/bdbe81afb5a09cee4269d2e2210a0d293265231a/media/guide/kohana/install.png
--------------------------------------------------------------------------------
/media/guide/kohana/welcome.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kohana/core/bdbe81afb5a09cee4269d2e2210a0d293265231a/media/guide/kohana/welcome.png
--------------------------------------------------------------------------------
/messages/tests/validation/error_type_check.php:
--------------------------------------------------------------------------------
1 | array(
6 | 'custom' => 'very nice email address you have there',
7 | ),
8 |
9 | );
10 |
--------------------------------------------------------------------------------
/messages/validation.php:
--------------------------------------------------------------------------------
1 | ':field must contain only letters',
6 | 'alpha_dash' => ':field must contain only numbers, letters and dashes',
7 | 'alpha_numeric' => ':field must contain only letters and numbers',
8 | 'color' => ':field must be a color',
9 | 'credit_card' => ':field must be a credit card number',
10 | 'date' => ':field must be a date',
11 | 'decimal' => ':field must be a decimal with :param2 places',
12 | 'digit' => ':field must be a digit',
13 | 'email' => ':field must be an email address',
14 | 'email_domain' => ':field must contain a valid email domain',
15 | 'equals' => ':field must equal :param2',
16 | 'exact_length' => ':field must be exactly :param2 characters long',
17 | 'in_array' => ':field must be one of the available options',
18 | 'ip' => ':field must be an ip address',
19 | 'matches' => ':field must be the same as :param3',
20 | 'min_length' => ':field must be at least :param2 characters long',
21 | 'max_length' => ':field must not exceed :param2 characters long',
22 | 'not_empty' => ':field must not be empty',
23 | 'numeric' => ':field must be numeric',
24 | 'phone' => ':field must be a phone number',
25 | 'range' => ':field must be within the range of :param2 to :param3',
26 | 'regex' => ':field does not match the required format',
27 | 'url' => ':field must be a url',
28 |
29 | );
30 |
--------------------------------------------------------------------------------
/tests/kohana/Config/File/ReaderTest.php:
--------------------------------------------------------------------------------
1 |
12 | * @author Matt Button
13 | * @copyright (c) 2008-2014 Kohana Team
14 | * @license http://kohanaframework.org/license
15 | */
16 | class Kohana_Config_File_ReaderTest extends Kohana_Unittest_TestCase {
17 |
18 | /**
19 | * If we don't pass a directory to the reader then it should assume
20 | * that we want to search the dir 'config' by default
21 | *
22 | * @test
23 | * @covers Kohana_Config_File_Reader
24 | */
25 | public function test_default_search_dir_is_config()
26 | {
27 | $reader = new Kohana_Config_File_Reader;
28 |
29 | $this->assertAttributeSame('config', '_directory', $reader);
30 | }
31 |
32 | /**
33 | * If we pass a directory to the constructor of the file reader it
34 | * should change the search directory
35 | *
36 | * @test
37 | * @covers Kohana_Config_File_Reader
38 | */
39 | public function test_constructor_sets_search_dir_from_param()
40 | {
41 | $reader = new Kohana_Config_File_Reader('gafloog');
42 |
43 | $this->assertAttributeSame('gafloog', '_directory', $reader);
44 | }
45 |
46 | /**
47 | * If the config dir does not exist then the function should just
48 | * return an empty array
49 | *
50 | * @test
51 | * @covers Kohana_Config_File_Reader::load
52 | */
53 | public function test_load_returns_empty_array_if_conf_dir_dnx()
54 | {
55 | $config = new Kohana_Config_File_Reader('gafloogle');
56 |
57 | $this->assertSame(array(), $config->load('values'));
58 | }
59 |
60 | /**
61 | * If the requested config group does not exist then the reader
62 | * should return an empty array
63 | *
64 | * @test
65 | * @covers Kohana_Config_File_Reader::load
66 | */
67 | public function test_load_returns_empty_array_if_conf_dnx()
68 | {
69 | $config = new Kohana_Config_File_Reader;
70 |
71 | $this->assertSame(array(), $config->load('gafloogle'));
72 | }
73 |
74 | /**
75 | * Test that the load() function is actually loading the
76 | * configuration from the files.
77 | *
78 | * @test
79 | * @covers Kohana_Config_File_Reader::load
80 | */
81 | public function test_loads_config_from_files()
82 | {
83 | $config = new Kohana_Config_File_Reader;
84 |
85 | $values = $config->load('inflector');
86 |
87 | // Due to the way the cascading filesystem works there could be
88 | // any number of modifications to the system config in the
89 | // actual output. Therefore to increase compatability we just
90 | // check that we've got an array and that it's not empty
91 | $this->assertNotSame(array(), $values);
92 | $this->assertInternalType('array', $values);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/tests/kohana/ExceptionTest.php:
--------------------------------------------------------------------------------
1 | 'b')), 'b', 0),
32 | array(array(':a :b', array(':a' => 'c', ':b' => 'd')), 'c d', 0),
33 |
34 | array(array(':a', NULL, 5), ':a', 5),
35 | // #3358
36 | array(array(':a', NULL, '3F000'), ':a', '3F000'),
37 | // #3404
38 | array(array(':a', NULL, '42S22'), ':a', '42S22'),
39 | // #3927
40 | array(array(':a', NULL, 'b'), ':a', 'b'),
41 | // #4039
42 | array(array(':a', NULL, '25P01'), ':a', '25P01'),
43 | );
44 | }
45 |
46 | /**
47 | * Tests Kohana_Kohana_Exception::__construct()
48 | *
49 | * @test
50 | * @dataProvider provider_constructor
51 | * @covers Kohana_Kohana_Exception::__construct
52 | * @param array $arguments Arguments
53 | * @param string $expected_message Value from getMessage()
54 | * @param integer|string $expected_code Value from getCode()
55 | */
56 | public function test_constructor($arguments, $expected_message, $expected_code)
57 | {
58 | switch (count($arguments))
59 | {
60 | case 1:
61 | $exception = new Kohana_Exception(reset($arguments));
62 | break;
63 | case 2:
64 | $exception = new Kohana_Exception(reset($arguments), next($arguments));
65 | break;
66 | default:
67 | $exception = new Kohana_Exception(reset($arguments), next($arguments), next($arguments));
68 | }
69 |
70 | $this->assertSame($expected_code, $exception->getCode());
71 | $this->assertSame($expected_message, $exception->getMessage());
72 | }
73 |
74 | /**
75 | * Provides test data for test_text()
76 | *
77 | * @return array
78 | */
79 | public function provider_text()
80 | {
81 | return array(
82 | array(new Kohana_Exception('foobar'), $this->dirSeparator('Kohana_Exception [ 0 ]: foobar ~ SYSPATH/tests/kohana/ExceptionTest.php [ '.__LINE__.' ]')),
83 | );
84 | }
85 |
86 | /**
87 | * Tests Kohana_Exception::text()
88 | *
89 | * @test
90 | * @dataProvider provider_text
91 | * @covers Kohana_Exception::text
92 | * @param object $exception exception to test
93 | * @param string $expected expected output
94 | */
95 | public function test_text($exception, $expected)
96 | {
97 | $this->assertEquals($expected, Kohana_Exception::text($exception));
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/tests/kohana/FileTest.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright (c) 2008-2012 Kohana Team
15 | * @license http://kohanaframework.org/license
16 | */
17 | class Kohana_FileTest extends Unittest_TestCase
18 | {
19 | /**
20 | * Provides test data for test_sanitize()
21 | *
22 | * @return array
23 | */
24 | public function provider_mime()
25 | {
26 | return array(
27 | // $value, $result
28 | array(Kohana::find_file('tests', 'test_data/github', 'png'), 'image/png'),
29 | );
30 | }
31 |
32 | /**
33 | * Tests File::mime()
34 | *
35 | * @test
36 | * @dataProvider provider_mime
37 | * @param boolean $input Input for File::mime
38 | * @param boolean $expected Output for File::mime
39 | */
40 | public function test_mime($input, $expected)
41 | {
42 | //@todo: File::mime coverage needs significant improvement or to be dropped for a composer package - it's a "horribly unreliable" method with very little testing
43 | $this->assertSame($expected, File::mime($input));
44 | }
45 |
46 | /**
47 | * Provides test data for test_split_join()
48 | *
49 | * @return array
50 | */
51 | public function provider_split_join()
52 | {
53 | return array(
54 | // $value, $result
55 | array(Kohana::find_file('tests', 'test_data/github', 'png'), .01, 1),
56 | );
57 | }
58 |
59 | /**
60 | * Tests File::mime()
61 | *
62 | * @test
63 | * @dataProvider provider_split_join
64 | * @param boolean $input Input for File::split
65 | * @param boolean $peices Input for File::split
66 | * @param boolean $expected Output for File::splut
67 | */
68 | public function test_split_join($input, $peices, $expected)
69 | {
70 | $this->assertSame($expected, File::split($input, $peices));
71 | $this->assertSame($expected, File::join($input));
72 |
73 | foreach (glob(Kohana::find_file('tests', 'test_data/github', 'png').'.*') as $file)
74 | {
75 | unlink($file);
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/tests/kohana/I18nTest.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright (c) 2008-2012 Kohana Team
15 | * @license http://kohanaframework.org/license
16 | */
17 | class Kohana_I18nTest extends Unittest_TestCase {
18 |
19 | /**
20 | * Default values for the environment, see setEnvironment
21 | * @var array
22 | */
23 | // @codingStandardsIgnoreStart
24 | protected $environmentDefault = array(
25 | 'I18n::$lang' => 'en-us',
26 | );
27 | // @codingStandardsIgnoreEnd
28 |
29 | /**
30 | * Provides test data for test_lang()
31 | *
32 | * @return array
33 | */
34 | public function provider_lang()
35 | {
36 | return array(
37 | // $input, $expected_result
38 | array(NULL, 'en-us'),
39 | array('es-es', 'es-es'),
40 | );
41 | }
42 |
43 | /**
44 | * Tests I18n::lang()
45 | *
46 | * @test
47 | * @dataProvider provider_lang
48 | * @param boolean $input Input for I18n::lang
49 | * @param boolean $expected Output for I18n::lang
50 | */
51 | public function test_lang($input, $expected_result)
52 | {
53 | $this->assertSame($expected_result, I18n::lang($input));
54 | $this->assertSame($expected_result, I18n::lang());
55 | }
56 |
57 | /**
58 | * Provides test data for test_get()
59 | *
60 | * @return array
61 | */
62 | public function provider_get()
63 | {
64 | return array(
65 | // $value, $result
66 | array('en-us', 'Hello, world!', 'Hello, world!'),
67 | array('es-es', 'Hello, world!', '¡Hola, mundo!'),
68 | array('fr-fr', 'Hello, world!', 'Bonjour, monde!'),
69 | );
70 | }
71 |
72 | /**
73 | * Tests i18n::get()
74 | *
75 | * @test
76 | * @dataProvider provider_get
77 | * @param boolean $input Input for File::mime
78 | * @param boolean $expected Output for File::mime
79 | */
80 | public function test_get($lang, $input, $expected)
81 | {
82 | I18n::lang($lang);
83 | $this->assertSame($expected, I18n::get($input));
84 |
85 | // Test immediate translation, issue #3085
86 | I18n::lang('en-us');
87 | $this->assertSame($expected, I18n::get($input, $lang));
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/tests/kohana/LogTest.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright (c) 2008-2012 Kohana Team
15 | * @license http://kohanaframework.org/license
16 | */
17 | class Kohana_LogTest extends Unittest_TestCase
18 | {
19 |
20 | /**
21 | * Tests that when a new logger is created the list of messages is initially
22 | * empty
23 | *
24 | * @test
25 | * @covers Log
26 | */
27 | public function test_messages_is_initially_empty()
28 | {
29 | $logger = new Log;
30 |
31 | $this->assertAttributeSame(array(), '_messages', $logger);
32 | }
33 |
34 | /**
35 | * Tests that when a new logger is created the list of writers is initially
36 | * empty
37 | *
38 | * @test
39 | * @covers Log
40 | */
41 | public function test_writers_is_initially_empty()
42 | {
43 | $logger = new Log;
44 |
45 | $this->assertAttributeSame(array(), '_writers', $logger);
46 | }
47 |
48 | /**
49 | * Test that attaching a log writer using an array of levels adds it to the array of log writers
50 | *
51 | * @TODO Is this test too specific?
52 | *
53 | * @test
54 | * @covers Log::attach
55 | */
56 | public function test_attach_attaches_log_writer_and_returns_this()
57 | {
58 | $logger = new Log;
59 | $writer = $this->getMockForAbstractClass('Log_Writer');
60 |
61 | $this->assertSame($logger, $logger->attach($writer));
62 |
63 | $this->assertAttributeSame(
64 | array(spl_object_hash($writer) => array('object' => $writer, 'levels' => array())),
65 | '_writers',
66 | $logger
67 | );
68 | }
69 |
70 | /**
71 | * Test that attaching a log writer using a min/max level adds it to the array of log writers
72 | *
73 | * @TODO Is this test too specific?
74 | *
75 | * @test
76 | * @covers Log::attach
77 | */
78 | public function test_attach_attaches_log_writer_min_max_and_returns_this()
79 | {
80 | $logger = new Log;
81 | $writer = $this->getMockForAbstractClass('Log_Writer');
82 |
83 | $this->assertSame($logger, $logger->attach($writer, Log::NOTICE, Log::CRITICAL));
84 |
85 | $this->assertAttributeSame(
86 | array(spl_object_hash($writer) => array('object' => $writer, 'levels' => array(Log::CRITICAL, Log::ERROR, Log::WARNING, Log::NOTICE))),
87 | '_writers',
88 | $logger
89 | );
90 | }
91 |
92 | /**
93 | * When we call detach() we expect the specified log writer to be removed
94 | *
95 | * @test
96 | * @covers Log::detach
97 | */
98 | public function test_detach_removes_log_writer_and_returns_this()
99 | {
100 | $logger = new Log;
101 | $writer = $this->getMockForAbstractClass('Log_Writer');
102 |
103 | $logger->attach($writer);
104 |
105 | $this->assertSame($logger, $logger->detach($writer));
106 |
107 | $this->assertAttributeSame(array(), '_writers', $logger);
108 | }
109 |
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/tests/kohana/ModelTest.php:
--------------------------------------------------------------------------------
1 |
14 | * @copyright (c) 2008-2012 Kohana Team
15 | * @license http://kohanaframework.org/license
16 | */
17 | class Kohana_ModelTest extends Unittest_TestCase
18 | {
19 | /**
20 | * Test the model's factory.
21 | *
22 | * @test
23 | * @covers Model::factory
24 | */
25 | public function test_create()
26 | {
27 | $foobar = Model::factory('Foobar');
28 |
29 | $this->assertEquals(TRUE, $foobar instanceof Model);
30 | }
31 | }
32 |
33 | class Model_Foobar extends Model
34 | {
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/tests/kohana/SecurityTest.php:
--------------------------------------------------------------------------------
1 | "),
24 | );
25 | }
26 |
27 | /**
28 | * Tests Security::encode_php_tags()
29 | *
30 | * @test
31 | * @dataProvider provider_encode_php_tags
32 | * @covers Security::encode_php_tags
33 | */
34 | public function test_encode_php_tags($expected, $input)
35 | {
36 | $this->assertSame($expected, Security::encode_php_tags($input));
37 | }
38 |
39 | /**
40 | * Provides test data for test_strip_image_tags()
41 | *
42 | * @return array Test data sets
43 | */
44 | public function provider_strip_image_tags()
45 | {
46 | return array(
47 | array('foo', ''),
48 | );
49 | }
50 |
51 | /**
52 | * Tests Security::strip_image_tags()
53 | *
54 | * @test
55 | * @dataProvider provider_strip_image_tags
56 | * @covers Security::strip_image_tags
57 | */
58 | public function test_strip_image_tags($expected, $input)
59 | {
60 | $this->assertSame($expected, Security::strip_image_tags($input));
61 | }
62 |
63 | /**
64 | * Provides test data for Security::token()
65 | *
66 | * @return array Test data sets
67 | */
68 | public function provider_csrf_token()
69 | {
70 | $array = array();
71 | for ($i = 0; $i <= 4; $i++)
72 | {
73 | Security::$token_name = 'token_'.$i;
74 | $array[] = array(Security::token(TRUE), Security::check(Security::token(FALSE)), $i);
75 | }
76 | return $array;
77 | }
78 |
79 | /**
80 | * Tests Security::token()
81 | *
82 | * @test
83 | * @dataProvider provider_csrf_token
84 | * @covers Security::token
85 | */
86 | public function test_csrf_token($expected, $input, $iteration)
87 | {
88 | //@todo: the Security::token tests need to be reviewed to check how much of the logic they're actually covering
89 | Security::$token_name = 'token_'.$iteration;
90 | $this->assertSame(TRUE, $input);
91 | $this->assertSame($expected, Security::token(FALSE));
92 | Session::instance()->delete(Security::$token_name);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/tests/kohana/ViewTest.php:
--------------------------------------------------------------------------------
1 | realpath(dirname(__FILE__).'/../test_data/')
33 | );
34 | Kohana::modules($new_modules);
35 | }
36 |
37 | /**
38 | * Restores the module list
39 | *
40 | * @return null
41 | */
42 | // @codingStandardsIgnoreStart
43 | public static function teardownAfterClass()
44 | // @codingStandardsIgnoreEnd
45 | {
46 | Kohana::modules(self::$old_modules);
47 | }
48 |
49 | /**
50 | * Provider for test_instaniate
51 | *
52 | * @return array
53 | */
54 | public function provider_instantiate()
55 | {
56 | return array(
57 | array('kohana/error', FALSE),
58 | array('test.css', FALSE),
59 | array('doesnt_exist', TRUE),
60 | );
61 | }
62 |
63 | /**
64 | * Provider to test_set
65 | *
66 | * @return array
67 | */
68 | public function provider_set()
69 | {
70 | return array(
71 | array('foo', 'bar', 'foo', 'bar'),
72 | array(array('foo' => 'bar'), NULL, 'foo', 'bar'),
73 | array(new ArrayIterator(array('foo' => 'bar')), NULL, 'foo', 'bar'),
74 | );
75 | }
76 |
77 | /**
78 | * Tests that we can instantiate a view file
79 | *
80 | * @test
81 | * @dataProvider provider_instantiate
82 | *
83 | * @return null
84 | */
85 | public function test_instantiate($path, $expects_exception)
86 | {
87 | try
88 | {
89 | $view = new View($path);
90 | $this->assertSame(FALSE, $expects_exception);
91 | }
92 | catch(View_Exception $e)
93 | {
94 | $this->assertSame(TRUE, $expects_exception);
95 | }
96 | }
97 |
98 | /**
99 | * Tests that we can set using string, array or Traversable object
100 | *
101 | * @test
102 | * @dataProvider provider_set
103 | *
104 | * @return null
105 | */
106 | public function test_set($data_key, $value, $test_key, $expected)
107 | {
108 | $view = View::factory()->set($data_key, $value);
109 | $this->assertSame($expected, $view->$test_key);
110 | }
111 |
112 | /**
113 | * Tests that we can set global using string, array or Traversable object
114 | *
115 | * @test
116 | * @dataProvider provider_set
117 | *
118 | * @return null
119 | */
120 | public function test_set_global($data_key, $value, $test_key, $expected)
121 | {
122 | $view = View::factory();
123 | $view::set_global($data_key, $value);
124 | $this->assertSame($expected, $view->$test_key);
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/tests/kohana/request/client/InternalTest.php:
--------------------------------------------------------------------------------
1 | _log_object = Kohana::$log;
31 | Kohana::$log = NULL;
32 | }
33 |
34 | // @codingStandardsIgnoreStart
35 | public function tearDown()
36 | // @codingStandardsIgnoreEnd
37 | {
38 | // re-assign log object
39 | Kohana::$log = $this->_log_object;
40 |
41 | parent::tearDown();
42 | }
43 |
44 | public function provider_response_failure_status()
45 | {
46 | return array(
47 | array('', 'Welcome', 'missing_action', 'Welcome/missing_action', 404),
48 | array('kohana3', 'missing_controller', 'index', 'kohana3/missing_controller/index', 404),
49 | array('', 'Template', 'missing_action', 'kohana3/Template/missing_action', 500),
50 | );
51 | }
52 |
53 | /**
54 | * Tests for correct exception messages
55 | *
56 | * @test
57 | * @dataProvider provider_response_failure_status
58 | *
59 | * @return null
60 | */
61 | public function test_response_failure_status($directory, $controller, $action, $uri, $expected)
62 | {
63 | // Mock for request object
64 | $request = $this->getMock('Request', array('directory', 'controller', 'action', 'uri', 'response', 'method'), array($uri));
65 |
66 | $request->expects($this->any())
67 | ->method('directory')
68 | ->will($this->returnValue($directory));
69 |
70 | $request->expects($this->any())
71 | ->method('controller')
72 | ->will($this->returnValue($controller));
73 |
74 | $request->expects($this->any())
75 | ->method('action')
76 | ->will($this->returnValue($action));
77 |
78 | $request->expects($this->any())
79 | ->method('uri')
80 | ->will($this->returnValue($uri));
81 |
82 | $request->expects($this->any())
83 | ->method('response')
84 | ->will($this->returnValue($this->getMock('Response')));
85 |
86 | // mock `method` method to avoid fatals in newer versions of PHPUnit
87 | $request->expects($this->any())
88 | ->method('method')
89 | ->withAnyParameters();
90 |
91 | $internal_client = new Request_Client_Internal;
92 |
93 | $response = $internal_client->execute($request);
94 |
95 | $this->assertSame($expected, $response->status());
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/tests/test_data/callback_routes.php:
--------------------------------------------------------------------------------
1 | 'welcome',
43 | 'action' => 'index',
44 | );
45 | }
46 |
47 | /**
48 | * Route callback for test_required_parameters_are_needed
49 | *
50 | * @return array
51 | */
52 | public static function required_parameters_are_needed($uri)
53 | {
54 | if (substr($uri, 0, 5) == 'admin')
55 | {
56 | return array(
57 | 'controller' => 'foo',
58 | 'action' => 'bar',
59 | );
60 | }
61 | }
62 |
63 | /**
64 | * Route callback for test reverse_routing_returns_routes_uri_if_route_is_static
65 | *
66 | * @return array
67 | */
68 | public static function reverse_routing_returns_routes_uri_if_route_is_static($uri)
69 | {
70 | if ($uri == 'info/about_us')
71 | {
72 | return array(
73 |
74 | );
75 | }
76 | }
77 |
78 | /**
79 | * Route callback for test route_filter_modify_params
80 | *
81 | * @return array
82 | */
83 | public static function route_filter_modify_params_array(Route $route, $params)
84 | {
85 | $params['action'] = 'modified';
86 |
87 | return $params;
88 | }
89 |
90 | /**
91 | * Route callback for test route_filter_modify_params
92 | *
93 | * @return array
94 | */
95 | public static function route_filter_modify_params_false(Route $route, $params)
96 | {
97 | return FALSE;
98 | }
99 |
100 | }
--------------------------------------------------------------------------------
/tests/test_data/feeds/activity.atom:
--------------------------------------------------------------------------------
1 |
2 |
3 | Kohana v3.x: Activity
4 |
5 |
6 | http://dev.kohanaframework.org/
7 | http://dev.kohanaframework.org/favicon.ico?1392677580
8 | 2014-08-28T01:52:12Z
9 |
10 | Kohana Development
11 |
12 |
13 | Redmine
14 |
15 | Proposals (Political/Workflow) #4839 (New)
16 |
17 | http://dev.kohanaframework.org/issues/4839
18 | 2014-08-28T01:52:12Z
19 |
20 | Guillaume Poirier-Morency
21 | guillaumepoiriermorency@gmail.com
22 |
23 |
24 | <p>I have a prototype here <a class="external" href="https://github.com/arteymix/kohana-makefile">https://github.com/arteymix/kohana-makefile</a></p>
25 |
26 |
27 | <p>The tool is very useful for settings permissions and running tests.</p>
28 |
29 |
30 | <p>I think we should consider having a good make tool in the sample application for the 3.4.*.</p>
31 |
32 |
33 | Proposals (Political/Workflow) #4782
34 |
35 | http://dev.kohanaframework.org/issues/4782#change-17279
36 | 2014-08-28T01:44:26Z
37 |
38 | Guillaume Poirier-Morency
39 | guillaumepoiriermorency@gmail.com
40 |
41 |
42 | <p>Moving to composer is a nice idea. This will allow Kohana modules to define a wide range of dependencies.</p>
43 |
44 |
45 | <p>Although, I think that modules designed specifically for Kohana should end in modules and external libraries in application/vendor. This makes a clear dinsinction between what gets autoloaded by the CFS and what gets loaded by composer. Technically, we add "vendor-dir": "application/vendor" in "config" in composer.json.</p>
46 |
47 |
48 | <p>Then, only add a line after the modules loading in bootstrap.php</p>
49 |
50 |
51 | <pre>
52 | // Autoloading composer packages
53 | require Kohana::find_file('vendor', 'autoload');
54 | </pre>
55 |
56 | <p>This is pretty much what I do right now. This doesn't break anything and allow a full access to composer.</p>
57 |
58 |
59 |
--------------------------------------------------------------------------------
/tests/test_data/feeds/example.rss20:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | RSS Title
5 | This is an example of an RSS feed
6 | http://www.example.com/main.html
7 | Mon, 06 Sep 2010 00:01:00 +0000
8 | Sun, 06 Sep 2009 16:20:00 +0000
9 | 1800
10 |
11 |
12 | Example entry
13 | Here is some text containing an interesting description.
14 | http://www.example.com/blog/post/1
15 | 7bd204c6-1655-4c27-aeee-53f933c5395f
16 | Sun, 06 Sep 2009 16:20:00 +0000
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/tests/test_data/github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kohana/core/bdbe81afb5a09cee4269d2e2210a0d293265231a/tests/test_data/github.png
--------------------------------------------------------------------------------
/tests/test_data/message_tests/bottom_module/messages/kohana_core_message_tests.php:
--------------------------------------------------------------------------------
1 | 'inherited bottom message',
5 | 'cfs_replaced' => 'inherited cfs_replaced message',
6 | );
7 |
--------------------------------------------------------------------------------
/tests/test_data/message_tests/top_module/messages/kohana_core_message_tests.php:
--------------------------------------------------------------------------------
1 | 'top only message',
5 | 'cfs_replaced' => 'overriding cfs_replaced message',
6 | );
7 |
--------------------------------------------------------------------------------
/tests/test_data/views/test.css.php:
--------------------------------------------------------------------------------
1 | This is a view with a dot in the filename.
--------------------------------------------------------------------------------
/utf8/from_unicode.php:
--------------------------------------------------------------------------------
1 | = 0) AND ($arr[$k] <= 0x007f))
21 | {
22 | echo chr($arr[$k]);
23 | }
24 | // 2 byte sequence
25 | elseif ($arr[$k] <= 0x07ff)
26 | {
27 | echo chr(0xc0 | ($arr[$k] >> 6));
28 | echo chr(0x80 | ($arr[$k] & 0x003f));
29 | }
30 | // Byte order mark (skip)
31 | elseif ($arr[$k] == 0xFEFF)
32 | {
33 | // nop -- zap the BOM
34 | }
35 | // Test for illegal surrogates
36 | elseif ($arr[$k] >= 0xD800 AND $arr[$k] <= 0xDFFF)
37 | {
38 | // Found a surrogate
39 | throw new UTF8_Exception("UTF8::from_unicode: Illegal surrogate at index: ':index', value: ':value'", array(
40 | ':index' => $k,
41 | ':value' => $arr[$k],
42 | ));
43 | }
44 | // 3 byte sequence
45 | elseif ($arr[$k] <= 0xffff)
46 | {
47 | echo chr(0xe0 | ($arr[$k] >> 12));
48 | echo chr(0x80 | (($arr[$k] >> 6) & 0x003f));
49 | echo chr(0x80 | ($arr[$k] & 0x003f));
50 | }
51 | // 4 byte sequence
52 | elseif ($arr[$k] <= 0x10ffff)
53 | {
54 | echo chr(0xf0 | ($arr[$k] >> 18));
55 | echo chr(0x80 | (($arr[$k] >> 12) & 0x3f));
56 | echo chr(0x80 | (($arr[$k] >> 6) & 0x3f));
57 | echo chr(0x80 | ($arr[$k] & 0x3f));
58 | }
59 | // Out of range
60 | else
61 | {
62 | throw new UTF8_Exception("UTF8::from_unicode: Codepoint out of Unicode range at index: ':index', value: ':value'", array(
63 | ':index' => $k,
64 | ':value' => $arr[$k],
65 | ));
66 | }
67 | }
68 |
69 | $result = ob_get_contents();
70 | ob_end_clean();
71 | return $result;
72 | }
73 |
--------------------------------------------------------------------------------
/utf8/ltrim.php:
--------------------------------------------------------------------------------
1 | = 0 AND $ord0 <= 127)
16 | return $ord0;
17 |
18 | if ( ! isset($chr[1]))
19 | {
20 | throw new UTF8_Exception('Short sequence - at least 2 bytes expected, only 1 seen');
21 | }
22 |
23 | $ord1 = ord($chr[1]);
24 |
25 | if ($ord0 >= 192 AND $ord0 <= 223)
26 | return ($ord0 - 192) * 64 + ($ord1 - 128);
27 |
28 | if ( ! isset($chr[2]))
29 | {
30 | throw new UTF8_Exception('Short sequence - at least 3 bytes expected, only 2 seen');
31 | }
32 |
33 | $ord2 = ord($chr[2]);
34 |
35 | if ($ord0 >= 224 AND $ord0 <= 239)
36 | return ($ord0 - 224) * 4096 + ($ord1 - 128) * 64 + ($ord2 - 128);
37 |
38 | if ( ! isset($chr[3]))
39 | {
40 | throw new UTF8_Exception('Short sequence - at least 4 bytes expected, only 3 seen');
41 | }
42 |
43 | $ord3 = ord($chr[3]);
44 |
45 | if ($ord0 >= 240 AND $ord0 <= 247)
46 | return ($ord0 - 240) * 262144 + ($ord1 - 128) * 4096 + ($ord2-128) * 64 + ($ord3 - 128);
47 |
48 | if ( ! isset($chr[4]))
49 | {
50 | throw new UTF8_Exception('Short sequence - at least 5 bytes expected, only 4 seen');
51 | }
52 |
53 | $ord4 = ord($chr[4]);
54 |
55 | if ($ord0 >= 248 AND $ord0 <= 251)
56 | return ($ord0 - 248) * 16777216 + ($ord1-128) * 262144 + ($ord2 - 128) * 4096 + ($ord3 - 128) * 64 + ($ord4 - 128);
57 |
58 | if ( ! isset($chr[5]))
59 | {
60 | throw new UTF8_Exception('Short sequence - at least 6 bytes expected, only 5 seen');
61 | }
62 |
63 | if ($ord0 >= 252 AND $ord0 <= 253)
64 | return ($ord0 - 252) * 1073741824 + ($ord1 - 128) * 16777216 + ($ord2 - 128) * 262144 + ($ord3 - 128) * 4096 + ($ord4 - 128) * 64 + (ord($chr[5]) - 128);
65 |
66 | if ($ord0 >= 254 AND $ord0 <= 255)
67 | {
68 | throw new UTF8_Exception("Invalid UTF-8 with surrogate ordinal ':ordinal'", array(
69 | ':ordinal' => $ord0,
70 | ));
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/utf8/rtrim.php:
--------------------------------------------------------------------------------
1 | $val)
19 | {
20 | $str[$key] = UTF8::str_ireplace($search, $replace, $val, $count);
21 | }
22 | return $str;
23 | }
24 |
25 | if (is_array($search))
26 | {
27 | $keys = array_keys($search);
28 |
29 | foreach ($keys as $k)
30 | {
31 | if (is_array($replace))
32 | {
33 | if (array_key_exists($k, $replace))
34 | {
35 | $str = UTF8::str_ireplace($search[$k], $replace[$k], $str, $count);
36 | }
37 | else
38 | {
39 | $str = UTF8::str_ireplace($search[$k], '', $str, $count);
40 | }
41 | }
42 | else
43 | {
44 | $str = UTF8::str_ireplace($search[$k], $replace, $str, $count);
45 | }
46 | }
47 | return $str;
48 | }
49 |
50 | $search = UTF8::strtolower($search);
51 | $str_lower = UTF8::strtolower($str);
52 |
53 | $total_matched_strlen = 0;
54 | $i = 0;
55 |
56 | while (preg_match('/(.*?)'.preg_quote($search, '/').'/s', $str_lower, $matches))
57 | {
58 | $matched_strlen = strlen($matches[0]);
59 | $str_lower = substr($str_lower, $matched_strlen);
60 |
61 | $offset = $total_matched_strlen + strlen($matches[1]) + ($i * (strlen($replace) - 1));
62 | $str = substr_replace($str, $replace, $offset, strlen($search));
63 |
64 | $total_matched_strlen += $matched_strlen;
65 | $i++;
66 | }
67 |
68 | $count += $i;
69 | return $str;
70 | }
71 |
--------------------------------------------------------------------------------
/utf8/str_pad.php:
--------------------------------------------------------------------------------
1 | $pad_type,
51 | ));
52 | }
53 |
--------------------------------------------------------------------------------
/utf8/str_split.php:
--------------------------------------------------------------------------------
1 | = $strlen OR ($length < 0 AND $length <= $offset - $strlen))
24 | return '';
25 |
26 | // Whole string
27 | if ($offset == 0 AND ($length === NULL OR $length >= $strlen))
28 | return $str;
29 |
30 | // Build regex
31 | $regex = '^';
32 |
33 | // Create an offset expression
34 | if ($offset > 0)
35 | {
36 | // PCRE repeating quantifiers must be less than 65536, so repeat when necessary
37 | $x = (int) ($offset / 65535);
38 | $y = (int) ($offset % 65535);
39 | $regex .= ($x == 0) ? '' : ('(?:.{65535}){'.$x.'}');
40 | $regex .= ($y == 0) ? '' : ('.{'.$y.'}');
41 | }
42 |
43 | // Create a length expression
44 | if ($length === NULL)
45 | {
46 | $regex .= '(.*)'; // No length set, grab it all
47 | }
48 | // Find length from the left (positive length)
49 | elseif ($length > 0)
50 | {
51 | // Reduce length so that it can't go beyond the end of the string
52 | $length = min($strlen - $offset, $length);
53 |
54 | $x = (int) ($length / 65535);
55 | $y = (int) ($length % 65535);
56 | $regex .= '(';
57 | $regex .= ($x == 0) ? '' : ('(?:.{65535}){'.$x.'}');
58 | $regex .= '.{'.$y.'})';
59 | }
60 | // Find length from the right (negative length)
61 | else
62 | {
63 | $x = (int) (-$length / 65535);
64 | $y = (int) (-$length % 65535);
65 | $regex .= '(.*)';
66 | $regex .= ($x == 0) ? '' : ('(?:.{65535}){'.$x.'}');
67 | $regex .= '.{'.$y.'}';
68 | }
69 |
70 | preg_match('/'.$regex.'/us', $str, $matches);
71 | return $matches[1];
72 | }
73 |
--------------------------------------------------------------------------------
/utf8/substr_replace.php:
--------------------------------------------------------------------------------
1 | 'image/png', 'data' => '{$data}'); ?>");
--------------------------------------------------------------------------------
/views/profiler/stats.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
12 |
13 |