strelov1
4/2/2018 - 11:33 AM

simpleQueryBuilder

class Query {
  
  private $conditions;
  
  public static function find()
  {
    return new self;
  }
  
  public function where(array $conditions)
  {
     $this->conditions = implode(' ', $conditions);
     return $this;
  }
  
  public function andWhere(array $conditions)
  {
     $conditionString = implode(' ', $conditions);
     $this->conditions .= " AND {$conditionString}";
     return $this;
  }
  
  public function all()
  {
      return "SELECT * FROM WHERE {$this->conditions}";
  }
}

$query = Query::find()->where(['createAt', '>', 'now()'])->andWhere(['updateAt', '>', 'now()'])->all();

var_dump($query);