Compare commits
24 Commits
Author | SHA1 | Date |
---|---|---|
Michal Sieciechowicz | 73af54b952 | |
Dariusz Jaski | 83f328d8ff | |
Michal Sieciechowicz | f7d8f76a79 | |
Michal Sieciechowicz | 766c29c5f3 | |
Dariusz Jaski | e14198e262 | |
Dariusz Jaski | 1be8bc5511 | |
Dariusz Jaski | 37599e8cf6 | |
Dariusz Jaski | fbf2aaae07 | |
Dariusz Jaski | 1920374639 | |
Dariusz Jaski | 1c886fb385 | |
Dariusz Jaski | b9d1d1601a | |
Dariusz Jaski | 3f9758c403 | |
Dariusz Jaski | 661406db67 | |
Dariusz Jaski | 9c6c34f870 | |
Dariusz Jaski | a026facb7c | |
Dariusz Jaski | 3c43612503 | |
Dariusz Jaski | d32c7a0b92 | |
Dariusz Jaski | d9da5559c5 | |
Dariusz Jaski | afc2b5a261 | |
Dariusz Jaski | 54113fffc0 | |
Michal Sieciechowicz | 9204f70e50 | |
Michal Sieciechowicz | a3d8bb6131 | |
Michal Sieciechowicz | a3d71c7bc5 | |
Michal Sieciechowicz | a3c38a27c7 |
|
@ -7,7 +7,7 @@ use Fufle\ORM\Database\ConnectionManager;
|
|||
abstract class Model {
|
||||
protected static string $primaryKey = 'id';
|
||||
protected static ?string $table = null;
|
||||
private static ?IQuery $query = null;
|
||||
protected static ?IQuery $query = null;
|
||||
|
||||
protected static array $fields = [];
|
||||
|
||||
|
@ -15,7 +15,7 @@ abstract class Model {
|
|||
$array = [];
|
||||
$fields = static::$fields;
|
||||
foreach($fields as $field) {
|
||||
if ($this->{$field} ?? null !== null) {
|
||||
if (isset($this->{$field})) {
|
||||
$array[$field] = $this->{$field};
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,7 @@ abstract class Model {
|
|||
}
|
||||
|
||||
protected static function QueryModel() {
|
||||
if (self::$query === null && self::class !== static::class) {
|
||||
self::$query = static::SetQueryModel();
|
||||
}
|
||||
return self::$query;
|
||||
return static::SetQueryModel();
|
||||
}
|
||||
|
||||
public static function GetTableName() {
|
||||
|
@ -47,18 +44,26 @@ abstract class Model {
|
|||
}
|
||||
|
||||
protected static function Query(string $sql, array|object $params = []) {
|
||||
return ConnectionManager::Query(
|
||||
$result = ConnectionManager::Query(
|
||||
$sql,
|
||||
$params,
|
||||
get_called_class());
|
||||
if (!$result) {
|
||||
return null;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected static function QueryAll(string $sql, array|object $params = []) {
|
||||
return ConnectionManager::QueryAll(
|
||||
$result = ConnectionManager::QueryAll(
|
||||
$sql,
|
||||
$params,
|
||||
get_called_class());
|
||||
if (!$result) {
|
||||
return [];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
abstract public static function SetQueryModel(): IQuery;
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Fufle\ORM\Providers;
|
||||
|
||||
use Fufle\ORM\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Contracts\Auth\UserProvider;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
class PassportUserProvider implements UserProvider {
|
||||
/**
|
||||
* The ORM User Model
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* Create a new ORM user provider.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Model $userModel) {
|
||||
$this->model = $userModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a user by the given credentials.
|
||||
*
|
||||
* @param array $credentials
|
||||
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
||||
*/
|
||||
public function retrieveByCredentials(array $credentials) {
|
||||
if (empty($credentials)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user = $this->model->findForPassport($credentials['username']);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a user against the given credentials.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Authenticatable $user
|
||||
* @param array $credentials Request credentials
|
||||
* @return bool
|
||||
*/
|
||||
public function validateCredentials(Authenticatable $user, Array $credentials) {
|
||||
return ($credentials['username'] == $user->getAuthIdentifier() &&
|
||||
md5($credentials['password']) == $user->getAuthPassword());
|
||||
}
|
||||
|
||||
public function retrieveById($identifier) {
|
||||
$userClass = get_class($this->model);
|
||||
return $userClass::FindOrFail($identifier);
|
||||
}
|
||||
|
||||
public function retrieveByToken($identifier, $token) {
|
||||
}
|
||||
|
||||
public function updateRememberToken(Authenticatable $user, $token) {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue