<?php


namespace App\User;

use App\Core\AbstractRepository;
use PDO;


class UsersRepository extends AbstractRepository
{
// abstract functions aus dem AbstractRepositery müssen hier definiert werden!
  public function getTableName() {
    return "users";
  }

  public function getModelName() {
    return "App\\User\\UserModel";
  }
// nachstehende function findet den username und gibt array des users zurück
  public function findByUserName($username) {
    $table = $this->getTableName();
    $model = $this->getModelName();

    $stmt = $this->pdo->prepare("SELECT * FROM `$table` WHERE username = :username");
    $stmt->execute(['username' => $username]);
    $stmt->setFetchMode(PDO::FETCH_CLASS, $model);
    $user = $stmt->fetch(PDO::FETCH_CLASS);
    return $user;
  }
}
?>
