Permalink
Browse files

Document Object.

  • Loading branch information...
lukemorton committed Apr 30, 2012
1 parent 2b0c696 commit 2c8cd9749039bcbc431f19475e1a792e9e465eba
Showing with 40 additions and 0 deletions.
  1. +40 −0 README.md
View
@@ -248,3 +248,43 @@ var_dump($user->friends()->count());
?>
```
+## Object, a data transfer object
+
+In order to transfer data between models and mappers we have
+devised a DTO called `Object`.
+
+### Creating an Object
+
+`Object::__construct()` optionally takes two arguments. The
+first is an array of data. The second a whitelist of keys to
+extract from the first arg.
+
+``` php
+<?php
+$object = new Object(array('name' => 'Luke'));
+
+// Or filter your data
+$object = new Object($_POST, array('name'));
+?>
+```
+
+### Updating an Object
+
+``` php
+<?php
+$object->name = 'Jim';
+$object->set('name', 'Jim');
+$object->accessor('name', 'Jim');
+?>
+```
+
+### Getting data from an Object
+
+``` php
+<?php
+var_dump($object->name);
+var_dump($object->get('name'));
+var_dump($object->accessor('name'));
+var_dump($object->as_array());
+?>
+```

0 comments on commit 2c8cd97

Please sign in to comment.