Skip to content

Commit

Permalink
Document and test PSR-1 compliant method access
Browse files Browse the repository at this point in the history
  • Loading branch information
treffynnon committed Aug 28, 2013
1 parent 7b1e19f commit 7f59e95
Show file tree
Hide file tree
Showing 4 changed files with 589 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Features
* Database agnostic. Currently supports SQLite, MySQL, Firebird and PostgreSQL. May support others, please give it a try!
* Supports collections of models with method chaining to filter or apply actions to multiple results at once.
* Multiple connections supported
* PSR-1 compliant methods (any method can be called in camelCase instead of underscores eg. `find_many()` becomes `findMany()`) - you'll need PHP 5.3+

Documentation
-------------
Expand Down Expand Up @@ -68,6 +69,7 @@ Changelog

#### 1.4.0 - release 2013-XX-XX

* Add PSR-1 compliant camelCase method calls to Idiorm (PHP 5.3+ required) [[crhayes](https://github.com/crhayes)] - [issue #108](https://github.com/j4mie/idiorm/issues/108)
* Add static method `get_config()` to access current configuration [[javierd](https://github.com/mikejestes)] - [issue #141](https://github.com/j4mie/idiorm/issues/141)
* Uses table aliases in `WHERE` clauses [[vicvicvic](https://github.com/vicvicvic)] - [issue #140](https://github.com/j4mie/idiorm/issues/140)
* Ignore result columns when calling an aggregate function [[tassoevan](https://github.com/tassoevan)] - [issue #120](https://github.com/j4mie/idiorm/issues/120)
Expand Down
32 changes: 32 additions & 0 deletions docs/querying.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,38 @@ which contains the columns ``id`` (the primary key of the record -
Idiorm assumes the primary key column is called ``id`` but this is
configurable, see below), ``name``, ``age`` and ``gender``.

A note on PSR-1 and camelCase
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

All the methods detailed in the documentation can also be called in a PSR-1 way:
underscores (_) become camelCase. Here follows an example of one query chain
being converted to a PSR-1 compliant style.

.. code-block:: php
<?php
// documented and default style
$person = ORM::for_table('person')->where('name', 'Fred Bloggs')->find_one();
// PSR-1 compliant style
$person = ORM::forTable('person')->where('name', 'Fred Bloggs')->findOne();
As you can see any method can be changed from the documented underscore (_) format
to that of a camelCase method name.

.. note::

In the background the PSR-1 compliant style uses the `__call()` and
`__callStatic()` magic methods to map the camelCase method name you supply
to the original underscore method name. It then uses `call_user_func_array()`
to apply the arguments to the method. If this minimal overhead is too great
then you can simply revert to using the underscore methods to avoid it. In
general this will not be a bottle neck in any application however and should
be considered a micro-optimisation.

As `__callStatic()` was added in PHP 5.3.0 you will need at least that version
of PHP to use this feature in any meaningful way.

Single records
^^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<testsuites>
<testsuite name="Idiorm Test Suite">
<directory suffix="Test.php">test</directory>
<directory suffix="Test53.php" phpVersion="5.3.0" phpVersionOperator=">=">test</directory>
</testsuite>
</testsuites>
</phpunit>
Loading

0 comments on commit 7f59e95

Please # to comment.