Ejemplo n.º 1
0
 /**
  * Return all the models that are both saved and changed
  *
  * @return Models
  */
 public function getModelsToUpdate()
 {
     return $this->models->filter(function (AbstractModel $model) {
         return $model->isChanged() and ($model->isSaved() or $model->isSoftDeleted());
     });
 }
Ejemplo n.º 2
0
 /**
  * Return a new RepoModels object with only the models that pass the filter callback
  * (Filter callback returned true).
  *
  * @param  Closure $filter must return true for each item
  * @return RepoModels  Filtered models
  */
 public function filter(Closure $filter)
 {
     return $this->current->filter($filter);
 }
Ejemplo n.º 3
0
 /**
  * @covers ::filter
  */
 public function testFilter()
 {
     $source = [new City(['name' => 'test1']), new City(['name' => 'test1']), new City(['name' => 'test2'])];
     $models = new Models($source);
     $filtered = $models->filter(function ($model) {
         return $model->name !== 'test1';
     });
     $this->assertInstanceOf('Harp\\Harp\\Model\\Models', $filtered);
     $this->assertEquals([$source[2]], Objects::toArray($filtered->all()));
 }