コード例 #1
0
 /**
  * map data
  * @param mixed $data
  * @return mixed
  **/
 public function mapData($data, $singular = false)
 {
     // init return variable
     $return = false;
     if ($data) {
         // if singular response required
         if ($singular) {
             // instantiate new object
             $return = new Cd();
             // map data
             $return->setId($data['id'])->setSlug($data['slug'])->setName($data['name']);
         } else {
             // array to map, not singular
             $return = array();
             foreach ($data as $key => $entity) {
                 $return[$key] = new Cd();
                 $return[$key]->setId($entity['id'])->setSlug($entity['slug'])->setName($entity['name']);
             }
         }
     }
     return $return;
 }
コード例 #2
0
 /**
  * test save
  * @return void
  **/
 public function testSave()
 {
     // init factory
     $factory = new Factory($this->dsn);
     // call repo
     $repo = $factory->fetch('SuperSimple\\ORM\\Tests\\Lib:Cd');
     $cd = new Cd();
     $cd->setSlug('test-cd-3')->setName('Test CD 3');
     $id = $repo->persist($cd);
     // fetch the new object
     $new = $repo->find($id);
     $this->assertInstanceOf('SuperSimple\\ORM\\Tests\\Lib\\Entity\\Cd', $new);
     $this->assertEquals($new->getName(), $cd->getName());
     $this->assertEquals($new->getSlug(), $cd->getSlug());
 }