コード例 #1
0
ファイル: UncachedMovie.php プロジェクト: ngmy/cached-object
 public static function get($movieId)
 {
     $m = PhysicalMovie::find($movieId);
     if (is_null($m)) {
         return null;
     } else {
         $movie = new Movie($m->id, $m->name, $m->length_minutes);
         return $movie;
     }
 }
コード例 #2
0
 public function testPhysicalModelObserver()
 {
     // Set a physical model observer
     PhysicalMovie::observe(new \Ngmy\CachedObject\Tests\Models\Logical\MovieObserver());
     // In the first time, a cached value should match
     $ls = LogicalMovie::getAll();
     $this->assertEquals($ls[0]->name, $this->ps[0]->name);
     $this->assertEquals($ls[1]->name, $this->ps[1]->name);
     // After updating a physical model, a cache is rebuilded and a cached value should match
     $ls[0]->name = 'Celeste and Jesse Forever';
     $ls[0]->lengthMinutes = 92;
     $ls[0]->update();
     $ls = LogicalMovie::getAll();
     $ps[0] = physicalmovie::find($ls[0]->id);
     $ps[1] = PhysicalMovie::find($ls[1]->id);
     $this->assertEquals($ls[0]->name, $ps[0]->name);
     $this->assertEquals($ls[0]->lengthMinutes, $ps[0]->length_minutes);
     $this->assertEquals($ls[1]->name, $ps[1]->name);
     $this->assertEquals($ls[1]->lengthMinutes, $ps[1]->length_minutes);
     // After deleting a physical model, a cache is rebuilded and a cached value should match
     $ls[0]->delete();
     $ls = LogicalMovie::getAll();
     $ps[0] = physicalmovie::find($ls[0]->id);
     $this->assertEquals($ls[0]->name, $ps[0]->name);
     $this->assertEquals($ls[0]->lengthMinutes, $ps[0]->length_minutes);
 }
コード例 #3
0
ファイル: Movie.php プロジェクト: ngmy/cached-object
 public function delete()
 {
     $m = PhysicalMovie::find($this->id);
     $m->delete();
 }