Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Commit

Permalink
migrate to slice
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Apr 11, 2017
1 parent 79a088f commit 91b0bc1
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"deimos/orm": "~2.0",
"deimos/orm": "~3.0",
"deimos/session": "~1.0",
"deimos/cookie": "~1.0"
},
Expand Down
10 changes: 5 additions & 5 deletions demo/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
15 changes: 8 additions & 7 deletions src/Auth/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Deimos\Helper\Helper;
use Deimos\ORM\ORM;
use Deimos\Session\Session;
use Deimos\Slice\Slice;

class Auth
{
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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);
Expand Down
25 changes: 13 additions & 12 deletions src/Auth/Provider/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Deimos\Cookie\Cookie;
use Deimos\ORM\Entity;
use Deimos\Session\Session;
use Deimos\Slice\Slice;

class Provider
{
Expand All @@ -27,9 +28,9 @@ class Provider
protected $user;

/**
* @var ConfigObject
* @var Slice
*/
protected $config;
protected $slice;

/**
* @var Cookie
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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];
Expand All @@ -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())
{
Expand All @@ -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();
}
Expand Down
14 changes: 7 additions & 7 deletions src/Auth/Provider/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Deimos\Auth\Provider;

use Deimos\Config\ConfigObject;
use Deimos\Slice\Slice;

abstract class Type implements TypeInterface
{
Expand All @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions src/Auth/Provider/Type/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/Auth/Provider/Type/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
];
}

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/Auth/Provider/Type/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 91b0bc1

Please sign in to comment.