Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/daviddeutsch/rx.git
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddeutsch committed Jul 31, 2013
2 parents d09c26b + ce2ee37 commit e3cc0e1
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
rx
==

A shorthand library for RedBeanPHP


#### CAUTION: Large parts of this are untested and I'm making stuff up as I go along


Rx_Facade extends the RedBean_Facade, so you can load it like so:

```php
use Rx_Facade as R;
```

Currently, the two main concepts I'm adding is a R::_() function that serves as a shorthand for the most common functions (loading, dispensing etc.) and the R::$x FindHelper which extends on R::$f to cut down creation of finder queries.

A couple of examples for the _() function:

Storing a bean:

```php
R::_( $bean );
```

Dispensing a bean:

```php
$type = R::_( 'type' );
```

Dispense a bean and inject data:

```php
$object = new \stdClass();
$object->name = 'name';
$object->data = 'data';

$type = R::_( 'type', $object );
```

(can be used to easily convert existing data into a bean)

Load a bean:

```php
$type = R::_( 'type', $id );
```

---

Example for the $x() FindHelper:

```php
R::findLast(
'package',
' name = :name AND major = :major AND minor = :minor ',
array(
':name' => $name,
':major' => $version[0],
':minor' => $version[1]
)
);
```

Would become:

```php
R::$x->last->package
->name($name)
->major($version[0])
->minor($version[1])
->find();
```

If you already know pretty well what you're searching for, there's the like() function where instead of this:

```php
R::$x->thing->test("data")->test2("data2")->find();
```

You can do this:

```php
$array = [ "test" => "data", "test2" => "data2" ];

R::$x->thing->like($array)->find();
```

(granted, this only cuts things short if you already have the data in an array)

0 comments on commit e3cc0e1

Please sign in to comment.