Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Nov 6, 2016
1 parent 2f4cb04 commit e3dd301
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions README.md
Expand Up @@ -87,18 +87,18 @@ echo $time; // 2013-05-17T14:30:45Z
The getter/setter feature provided by [icanboogie/accessor][], and extended by
[icanboogie/prototype][], allows you to create read-only or write-only properties,
façades properties, fallbacks to generate default values. Getters are setters are also often
using to control types, lazy load resources, and inject dependencies.
using to control types, lazy load resources, and inversion of control.





### Dependency injection
### Inversion of control

[icanboogie/prototype][] allows methods to be defined at runtime, and since getters and setters
are methods as well, this feature in often used as a mean to inject dependencies. What's great
about it is that dependencies are only _injected_ when they are required, not when to instance
is created.
[icanboogie/prototype][] allows methods to be defined at runtime, and since getters and setters are
methods as well, this feature in often used as a mean to reverse control to provide dependencies.
What's great about it is that dependencies are only provided when they are required, not when to
instance is created.

The following example demonstrates how a shared database connection is obtained through a `db`
property:
Expand All @@ -116,7 +116,7 @@ use ICanBoogie\PrototypeTrait;
class A
{
use PrototypeTrait;

public function truncate()
{
$this->db("TRUNCATE my_table");
Expand All @@ -126,7 +126,7 @@ class A
Prototype::from(A::class)['get_db'] = function(A $a) {

static $db;

return $db ?: $db = new Connection("sqlite::memory:");

};
Expand Down Expand Up @@ -174,6 +174,8 @@ use ICanBoogie\HTTP\Response;
$response = new Response('ok', 200);
echo $response; // HTTP/1.0 200 OK\r\nDate: Fri, 17 May 2013 15:08:21 GMT\r\n\r\nok

/* @var $app ICanBoogie\Core */

echo $app->models['pages']->own->visible->filter_by_nid(12)->order('created_on DESC')->limit(5);
// SELECT * FROM `pages` `page` INNER JOIN `nodes` `node` USING(`nid`) WHERE (`constructor` = ?) AND (`is_online` = ?) AND (site_id = 0 OR site_id = ?) AND (language = "" OR language = ?) AND (`nid` = ?) ORDER BY created_on DESC LIMIT 5
```
Expand All @@ -192,6 +194,8 @@ prepared database statement is invoked to perform a command:

# DB statements

/* @var $app ICanBoogie\Core */

$statement = $app->models['nodes']->prepare('UPDATE {self} SET title = ? WHERE nid = ?');
$statement("Title 1", 1);
$statement("Title 2", 2);
Expand All @@ -203,6 +207,8 @@ This applies to database connections, models, requests, responses, translators
```php
<?php

/* @var $app ICanBoogie\Core */

$pages = $app->models['pages'];
$pages('SELECT * FROM {self_and_related} WHERE YEAR(created_on) = 2013')->all;

Expand Down Expand Up @@ -234,12 +240,18 @@ database, database connections, models, modules, header fields…
```php
<?php

/* @var $app ICanBoogie\Core */

$app->models['nodes'][123]; // fetch record with key 123 in nodes
$app->modules['nodes']; // obtain the Nodes module
$app->connections['primary']; // obtain the primary database connection

/* @var $request ICanBoogie\HTTP\Request */

$request['param1']; // fetch param of the request named `param1`, returns `null` if it doesn't exists

/* @var $response ICanBoogie\HTTP\Response */

$response->headers['Cache-Control'] = 'no-cache';
$response->headers['Content-Type'] = 'text/html; charset=utf-8';
```
Expand Down Expand Up @@ -283,12 +295,11 @@ $initial_request = Request::from($_SERVER);

$custom_request = Request::from([

'path' => '/path/to/controller',
'is_post' => true,
'is_local' => true,
'is_xhr' => true,

'request_params' => [
Request::OPTION_URI => '/path/to/controller',
Request::OPTION_IS_POST => true,
Request::OPTION_IS_LOCAL => true,
Request::OPTION_IS_XHR => true,
Request::OPTION_REQUEST_PARAMS => [

'param1' => 'value1',
'param2' => 'value2'
Expand Down Expand Up @@ -521,15 +532,15 @@ return [

'session' => [

'name' => "ICanBoogie",
'domain' => ".example.org"
'name' => "ICanBoogie",
'domain' => ".example.org"

]
]

];
```

Check ICanBoogie's "config/core.php" for a list of available options and their default values.
> Check ICanBoogie's "config/core.php" for a list of available options and their default values.


Expand Down Expand Up @@ -655,8 +666,12 @@ if one existed in the first place. When the `timer` query parameter is present,
gives timing information as well.

```php
<?php

use ICanBoogie\HTTP\Request;

$request = Request::from('/api/ping?timer');

echo $request()->body;
// pong, in 4.875 ms (ready in 3.172 ms)
```
Expand Down Expand Up @@ -811,7 +826,7 @@ The package is continuously tested by [Travis CI](http://about.travis-ci.org/).

[DateTime]: http://api.icanboogie.org/datetime/1.1/class-ICanBoogie.DateTime.html
[TimeZone]: http://api.icanboogie.org/datetime/1.1/class-ICanBoogie.TimeZone.html
[Request]: http://api.icanboogie.org/http/2.5/class-ICanBoogie.HTTP.Request.html
[Request]: http://api.icanboogie.org/http/2.6/class-ICanBoogie.HTTP.Request.html
[BootEvent]: http://api.icanboogie.org/icanboogie/3.0/class-ICanBoogie.Core.BootEvent.html
[ClearCacheEvent]: http://api.icanboogie.org/icanboogie/3.0/class-ICanBoogie.Core.ClearCacheEvent.html
[ConfigureEvent]: http://api.icanboogie.org/icanboogie/3.0/class-ICanBoogie.Core.ConfigureEvent.html
Expand Down

0 comments on commit e3dd301

Please sign in to comment.