Permalink
Browse files

adding examples dir and model test

  • Loading branch information...
1 parent 3ddba04 commit 3df6df54391a7f394e217f9c16f653ff49228bcd @enygma committed Jun 6, 2011
Showing with 54 additions and 0 deletions.
  1. +54 −0 examples/modelTest.php
View
54 examples/modelTest.php
@@ -0,0 +1,54 @@
+<?php
+include_once 'lib/DataMapper.php';
+include_once 'lib/ExpandObject.php';
+include_once 'lib/MapItem.php';
+
+class UserModel {
+
+ private $_map = null;
+
+ public function __construct()
+ {
+ $this->_map = new DataMapper();
+ $this->_map = $this->_map->configure(array(
+ 'title' => new MapItem(array(
+ 'map:input' => 'details->name',
+ 'map:output' => 'username',
+ 'alias' => 'uname'
+ ))
+ ));
+ }
+
+ public function fetchUsers()
+ {
+ // Make us some sample users...
+ $users = array();
+ for($i=0;$i<5;$i++){
+ $users[]=(object)array('details' => (object)array(
+ 'name' => 'user'.$i
+ )
+ );
+ }
+
+ $results = array();
+ $dm = new DataMapper();
+ foreach($users as $key => $user){
+ // a sample class...
+ $target = new stdClass();
+
+ $results[$key] = $this->_map
+ ->setSource($user)
+ ->setTarget($target)
+ ->execute();
+ }
+
+ return $results;
+ }
+}
+
+$um = new UserModel();
+$users = $um->fetchUsers();
+foreach($users as $user){
+ echo 'from $user::details->name: '.$user->username."\n";
+}
+?>

0 comments on commit 3df6df5

Please sign in to comment.