From 91b0bc165025f5529e1e244ca93598697068c751 Mon Sep 17 00:00:00 2001 From: REZ1DENT3 Date: Tue, 11 Apr 2017 14:14:27 +0300 Subject: [PATCH] migrate to slice --- composer.json | 2 +- demo/bootstrap.php | 10 +++++----- src/Auth/Auth.php | 15 ++++++++------- src/Auth/Provider/Provider.php | 25 +++++++++++++------------ src/Auth/Provider/Type.php | 14 +++++++------- src/Auth/Provider/Type/Cookie.php | 12 ++++++------ src/Auth/Provider/Type/Password.php | 8 ++++---- src/Auth/Provider/Type/Session.php | 4 ++-- 8 files changed, 46 insertions(+), 44 deletions(-) diff --git a/composer.json b/composer.json index 2b60456..b6a3473 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "deimos/orm": "~2.0", + "deimos/orm": "~3.0", "deimos/session": "~1.0", "deimos/cookie": "~1.0" }, diff --git a/demo/bootstrap.php b/demo/bootstrap.php index f692f0d..13193d5 100644 --- a/demo/bootstrap.php +++ b/demo/bootstrap.php @@ -61,17 +61,17 @@ ]; -$builder = new Deimos\Builder\Builder(); +$helper = new Deimos\Helper\Helper(); -$dbConfig = new \Deimos\Config\ConfigObject($builder, [ +$dbConfig = new \Deimos\Slice\Slice($helper, [ 'adapter' => 'mysql', - 'database' => 'test', + 'database' => 'auth', 'username' => 'root', 'password' => 'root' ]); $database = new \Deimos\Database\Database($dbConfig); -$orm = new \Deimos\ORM\ORM($builder, $database); +$orm = new \Deimos\ORM\ORM($helper, $database); -$authConfig = new \Deimos\Config\ConfigObject($builder, $config); +$authConfig = new \Deimos\Slice\Slice($helper, $config); $auth = new \Deimos\Auth\Auth($orm, $authConfig); \ No newline at end of file diff --git a/src/Auth/Auth.php b/src/Auth/Auth.php index b06b064..f17b70c 100644 --- a/src/Auth/Auth.php +++ b/src/Auth/Auth.php @@ -8,6 +8,7 @@ use Deimos\Helper\Helper; use Deimos\ORM\ORM; use Deimos\Session\Session; +use Deimos\Slice\Slice; class Auth { @@ -48,20 +49,20 @@ class Auth protected $domains = []; /** - * @var ConfigObject + * @var Slice */ - protected $config; + protected $slice; /** * Auth constructor. * * @param $orm ORM - * @param $config ConfigObject + * @param $slice Slice */ - public function __construct(ORM $orm, ConfigObject $config) + public function __construct(ORM $orm, Slice $slice) { - $this->orm = $orm; - $this->config = $config; + $this->orm = $orm; + $this->slice = $slice; } /** @@ -73,7 +74,7 @@ public function domain($name = 'default') { if (!isset($this->domains[$name])) { - $slice = $this->config->slice($name); + $slice = $this->slice->getSlice($name); $class = $this->provider; $this->domains[$name] = new $class($this, $slice, $name); diff --git a/src/Auth/Provider/Provider.php b/src/Auth/Provider/Provider.php index 0be88b5..6b8ebce 100644 --- a/src/Auth/Provider/Provider.php +++ b/src/Auth/Provider/Provider.php @@ -7,6 +7,7 @@ use Deimos\Cookie\Cookie; use Deimos\ORM\Entity; use Deimos\Session\Session; +use Deimos\Slice\Slice; class Provider { @@ -27,9 +28,9 @@ class Provider protected $user; /** - * @var ConfigObject + * @var Slice */ - protected $config; + protected $slice; /** * @var Cookie @@ -58,15 +59,15 @@ class Provider /** * Provider constructor. * - * @param Auth $auth - * @param ConfigObject $config - * @param string $name + * @param Auth $auth + * @param Slice $slice + * @param string $name */ - public function __construct(Auth $auth, ConfigObject $config, $name) + public function __construct(Auth $auth, Slice $slice, $name) { - $this->auth = $auth; - $this->config = $config; - $this->name = $name; + $this->auth = $auth; + $this->slice = $slice; + $this->name = $name; } /** @@ -92,7 +93,7 @@ public function auth() */ public function provider($name) { - $slice = $this->config->slice($name); + $slice = $this->slice->getSlice($name); $type = $slice->getRequired('type'); $class = $this->mapClasses[$type]; @@ -119,7 +120,7 @@ public function user() { if (!$this->try && !$this->user) { - foreach ($this->config as $name => $class) + foreach ($this->slice as $name => $class) { if ($this->provider($name)->execute()) { @@ -135,7 +136,7 @@ public function user() public function forgetUser() { - foreach ($this->config as $name => $class) + foreach ($this->slice as $name => $class) { $this->provider($name)->forget(); } diff --git a/src/Auth/Provider/Type.php b/src/Auth/Provider/Type.php index d1072a4..fd61476 100644 --- a/src/Auth/Provider/Type.php +++ b/src/Auth/Provider/Type.php @@ -2,7 +2,7 @@ namespace Deimos\Auth\Provider; -use Deimos\Config\ConfigObject; +use Deimos\Slice\Slice; abstract class Type implements TypeInterface { @@ -13,20 +13,20 @@ abstract class Type implements TypeInterface protected $provider; /** - * @var \Deimos\Config\ConfigObject + * @var Slice */ - protected $config; + protected $slice; /** * Type constructor. * - * @param Provider $provider - * @param ConfigObject $config + * @param Provider $provider + * @param Slice $config */ - public function __construct(Provider $provider, ConfigObject $config) + public function __construct(Provider $provider, Slice $config) { $this->provider = $provider; - $this->config = $config; + $this->slice = $config; } public function forget() diff --git a/src/Auth/Provider/Type/Cookie.php b/src/Auth/Provider/Type/Cookie.php index 7ea0e66..66cc903 100644 --- a/src/Auth/Provider/Type/Cookie.php +++ b/src/Auth/Provider/Type/Cookie.php @@ -27,11 +27,11 @@ public function persist() if ($user) { $series = $this->provider->auth()->helper()->str()->random(); - $expires = $this->config->get('tokens.expires', 3600 * 24 * 14); + $expires = $this->slice->getData('tokens.expires', 3600 * 24 * 14); $orm = $this->provider->auth()->orm(); - $model = $this->config->getRequired('tokens.model'); + $model = $this->slice->getRequired('tokens.model'); $token = $orm->create($model); $save = $token->save([ @@ -65,7 +65,7 @@ public function execute() return null; } - $model = $this->config->getRequired('tokens.model'); + $model = $this->slice->getRequired('tokens.model'); $orm = $this->provider->auth()->orm(); @@ -78,10 +78,10 @@ public function execute() { $userId = $token->userId; - $persist = $this->config->getRequired('persist'); + $persist = $this->slice->getRequired('persist'); $provider = $this->provider->provider($persist); - $model = $provider->config->get('model'); + $model = $provider->slice->getData('model'); $orm = $this->provider->auth()->orm(); @@ -106,7 +106,7 @@ public function forget() $series = $cookie->get($this->getKey()); $cookie->remove($this->getKey()); - $model = $this->config->getRequired('tokens.model'); + $model = $this->slice->getRequired('tokens.model'); $user = $this->provider->auth()->orm()->repository($model) ->where('series', $series) diff --git a/src/Auth/Provider/Type/Password.php b/src/Auth/Provider/Type/Password.php index a95b434..cfe6cbb 100644 --- a/src/Auth/Provider/Type/Password.php +++ b/src/Auth/Provider/Type/Password.php @@ -21,7 +21,7 @@ protected function options() if (!$this->options) { $this->options = [ - 'cost' => $this->config->get('options.cost', 12), + 'cost' => $this->slice->getData('options.cost', 12), ]; } @@ -67,9 +67,9 @@ public function verify($password, $hash) */ public function login($username, $password) { - $model = $this->config->getRequired('model'); - $loginFields = $this->config->getRequired('loginFields'); - $hashField = $this->config->getRequired('hashField'); + $model = $this->slice->getRequired('model'); + $loginFields = $this->slice->getRequired('loginFields'); + $hashField = $this->slice->getRequired('hashField'); $userQuery = $this->provider->auth()->orm()->repository($model); diff --git a/src/Auth/Provider/Type/Session.php b/src/Auth/Provider/Type/Session.php index 49d3d19..f387725 100644 --- a/src/Auth/Provider/Type/Session.php +++ b/src/Auth/Provider/Type/Session.php @@ -44,10 +44,10 @@ public function execute() return; } - $persist = $this->config->getRequired('persist'); + $persist = $this->slice->getRequired('persist'); $provider = $this->provider->provider($persist); - $model = $provider->config->get('model'); + $model = $provider->slice->getData('model'); $orm = $this->provider->auth()->orm();