Skip to content

Instantly share code, notes, and snippets.

@mateusgf
Created December 3, 2015 11:43
Show Gist options
  • Save mateusgf/9b9797f4bff662a3e958 to your computer and use it in GitHub Desktop.
Save mateusgf/9b9797f4bff662a3e958 to your computer and use it in GitHub Desktop.
<?php
class Film {
protected $queryCriteria;
public function where($key, $value)
{
$this->queryCriteria .= "Findind the Film by $key:$value\n";
return $this;
}
public function all()
{
echo $this->queryCriteria;
}
}
class FilmRepository {
protected $film;
public function __construct(Film $film)
{
$this->film = $film;
}
public function criteria(array $criteria)
{
//logic for finding by criteria here
$this->film = $this->film->where('title', 'The Lord Of The Rings')->where('length', '120');
return $this;
}
public function all()
{
echo $this->film->all();
}
}
//Then you can use:
$films = new FilmRepository(new Film());
$films->criteria([])->all();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment