Compare commits

..

1 Commits
0.9 ... master

Author SHA1 Message Date
Michał Sieciechowicz 248006a830 PR2: 0.2.3
Co-Authored-By: Sieciech <sieciech@noreply.fufle.net>
Co-Committed-By: Sieciech <sieciech@noreply.fufle.net>
2021-03-08 10:28:32 +00:00
2 changed files with 8 additions and 91 deletions

View File

@ -7,8 +7,7 @@ use Fufle\ORM\Database\ConnectionManager;
abstract class Model { abstract class Model {
protected static string $primaryKey = 'id'; protected static string $primaryKey = 'id';
protected static ?string $table = null; protected static ?string $table = null;
protected static ?IQuery $query = null; private static ?IQuery $query = null;
private static array $queryModels = [];
protected static array $fields = []; protected static array $fields = [];
@ -16,28 +15,18 @@ abstract class Model {
$array = []; $array = [];
$fields = static::$fields; $fields = static::$fields;
foreach($fields as $field) { foreach($fields as $field) {
if (isset($this->{$field})) { if ($this->{$field} ?? null !== null) {
$array[$field] = $this->{$field}; $array[$field] = $this->{$field};
} }
} }
return $array; return $array;
} }
public static function Instance(object $object): static {
$obj = new static;
$params = get_object_vars($object);
foreach ($params as $key => $value) {
$obj->{$key} = $value;
}
return $obj;
}
protected static function QueryModel() { protected static function QueryModel() {
if (!isset(static::$queryModels[static::class])) if (self::$query === null && self::class !== static::class) {
if (static::$query === null) { self::$query = static::SetQueryModel();
static::$queryModels[static::class] = static::SetQueryModel();
} }
return static::$queryModels[static::class]; return self::$query;
} }
public static function GetTableName() { public static function GetTableName() {
@ -58,26 +47,18 @@ abstract class Model {
} }
protected static function Query(string $sql, array|object $params = []) { protected static function Query(string $sql, array|object $params = []) {
$result = ConnectionManager::Query( return ConnectionManager::Query(
$sql, $sql,
$params, $params,
get_called_class()); get_called_class());
if (!$result) {
return null;
}
return $result;
} }
protected static function QueryAll(string $sql, array|object $params = []) { protected static function QueryAll(string $sql, array|object $params = []) {
$result = ConnectionManager::QueryAll( return ConnectionManager::QueryAll(
$sql, $sql,
$params, $params,
get_called_class()); get_called_class());
if (!$result) {
return [];
}
return $result;
} }
abstract public static function SetQueryModel(): IQuery; abstract public static function SetQueryModel(): IQuery;
} }

View File

@ -1,64 +0,0 @@
<?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) {
}
}