コード例 #1
0
ファイル: Blueprint.php プロジェクト: derptest/phpmachinist
 /**
  * Attempt to find a machine by the provided data. An array of machine objects
  * will be returned.
  * @param  $data
  * @return array|bool
  */
 public function find($data)
 {
     $store = $this->machinist->getStore($this->store);
     $table = $this->getTable($data);
     $return = array();
     $rows = $store->find($table, $data);
     if (!is_array($rows)) {
         $rows = array($rows);
     }
     if (is_array($this->defaults)) {
         $relationships = array_filter($this->defaults, function ($i) {
             return $i instanceof \DerpTest\Machinist\Relationship;
         });
     } else {
         $relationships = false;
     }
     foreach ($rows as $row) {
         $machine = new \DerpTest\Machinist\Machine($store, $table, (array) $row);
         if (!empty($relationships)) {
             foreach ($relationships as $k => $r) {
                 $local = $r->getLocal();
                 if (!empty($row->{$local})) {
                     $machine->set($k, $r->getBlueprint()->findOne($row->{$local}));
                 }
             }
         }
         $return[] = $machine;
     }
     return $return;
 }
コード例 #2
0
ファイル: MachineTest.php プロジェクト: derptest/phpmachinist
 public function testNonCompoundKeyId()
 {
     $machine = new Machine($this->store, 'some_table', array('name' => "awesome", "id" => 134, 'other' => 'whut'));
     Phake::when($this->store)->primaryKey('some_table')->thenReturn('id');
     $this->assertEquals(134, $machine->getId());
 }