Compare commits
	
		
			24 Commits
		
	
	
	| Author | SHA1 | Date | 
|---|---|---|
|  | 73af54b952 | |
|  | 83f328d8ff | |
|  | f7d8f76a79 | |
|  | 766c29c5f3 | |
|  | e14198e262 | |
|  | 1be8bc5511 | |
|  | 37599e8cf6 | |
|  | fbf2aaae07 | |
|  | 1920374639 | |
|  | 1c886fb385 | |
|  | b9d1d1601a | |
|  | 3f9758c403 | |
|  | 661406db67 | |
|  | 9c6c34f870 | |
|  | a026facb7c | |
|  | 3c43612503 | |
|  | d32c7a0b92 | |
|  | d9da5559c5 | |
|  | afc2b5a261 | |
|  | 54113fffc0 | |
|  | 9204f70e50 | |
|  | a3d8bb6131 | |
|  | a3d71c7bc5 | |
|  | 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