Skip to content

Commit

Permalink
Use class names
Browse files Browse the repository at this point in the history
  • Loading branch information
jakejohns committed Aug 21, 2017
1 parent 4646b1c commit 3c0940b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
52 changes: 20 additions & 32 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Aura\Di\Container;
use Aura\Di\ContainerConfig;

use Aura\Auth\AuthFactory as Factory;
use Aura\Auth;
use Aura\Auth\Adapter\NullAdapter;

/**
Expand All @@ -38,18 +38,6 @@
*/
class Config extends ContainerConfig
{
const COOKIE = 'cookie';

const FACTORY = 'aura/auth:factory';
const ADAPTER = 'aura/auth:adapter';

const AUTH = 'aura/auth:auth';

const LOGIN = 'aura/auth:login';
const LOGOUT = 'aura/auth:logout';
const RESUME = 'aura/auth:resume';


/**
* Cookie
*
Expand Down Expand Up @@ -84,53 +72,53 @@ public function __construct(array $cookie = null)
*/
public function define(Container $di)
{
if (! isset($di->values[static::COOKIE])) {
$di->values[static::COOKIE] = $this->cookie;
if (! isset($di->values['_COOKIE'])) {
$di->values['_COOKIE'] = $this->cookie;
}

$di->params[Factory::class]['cookie'] = $di->lazyValue(static::COOKIE);
$di->params[Auth\AuthFactory::class]['cookie'] = $di->lazyValue('_COOKIE');

$di->set(
static::FACTORY,
$di->lazyNew(Factory::class)
Auth\AuthFactory::class,
$di->lazyNew(Auth\AuthFactory::class)
);

if (! $di->has(static::ADAPTER)) {
if (! $di->has(Auth\Adapter::class)) {
$di->set(
static::ADAPTER,
$di->lazyNew(NullAdapter::class)
Auth\Adapter::class,
$di->lazyNew(Auth\Adapter\NullAdapter::class)
);
}

$di->set(
static::AUTH,
$di->lazyGetCall(static::FACTORY, 'newInstance')
Auth\Auth::class,
$di->lazyGetCall(Auth\AuthFactory::class, 'newInstance')
);

$di->set(
static::LOGIN,
Auth\Service\LoginService::class,
$di->lazyGetCall(
static::FACTORY,
Auth\AuthFactory::class,
'newLoginService',
$di->lazyGet(static::ADAPTER)
$di->lazyGet(Auth\Adapter::class)
)
);

$di->set(
static::LOGOUT,
Auth\Service\LogoutService::class,
$di->lazyGetCall(
static::FACTORY,
Auth\AuthFactory::class,
'newLogoutService',
$di->lazyGet(static::ADAPTER)
$di->lazyGet(Auth\Adapter::class)
)
);

$di->set(
static::RESUME,
Auth\Service\ResumeService::class,
$di->lazyGetCall(
static::FACTORY,
Auth\AuthFactory::class,
'newResumeService',
$di->lazyGet(static::ADAPTER)
$di->lazyGet(Auth\Adapter::class)
)
);
}
Expand Down
17 changes: 9 additions & 8 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Fusible\AuthProvider;

use Aura\Di\AbstractContainerConfigTest;
use Aura\Auth;

class ConfigTest extends AbstractContainerConfigTest
{
Expand All @@ -16,26 +17,26 @@ protected function setUp()
protected function getConfigClasses()
{
return [
'Fusible\AuthProvider\Config'
Config::class
];
}

public function provideGet()
{
return [
[ 'aura/auth:factory', 'Aura\Auth\AuthFactory' ],
[ 'aura/auth:adapter', 'Aura\Auth\Adapter\NullAdapter' ],
[ 'aura/auth:auth', 'Aura\Auth\Auth' ],
[ 'aura/auth:login', 'Aura\Auth\Service\LoginService' ],
[ 'aura/auth:logout', 'Aura\Auth\Service\LogoutService'],
[ 'aura/auth:resume', 'Aura\Auth\Service\ResumeService']
[ Auth\AuthFactory::class, Auth\AuthFactory::class],
[ Auth\Adapter::class, Auth\Adapter\NullAdapter::class ],
[ Auth\Auth::class, Auth\Auth::class ],
[ Auth\Service\LoginService::class, Auth\Service\LoginService::class ],
[ Auth\Service\LogoutService::class, Auth\Service\LogoutService::class],
[ Auth\Service\ResumeService::class, Auth\Service\ResumeService::class]
];
}

public function provideNewInstance()
{
return [
['Aura\Auth\AuthFactory']
[Auth\AuthFactory::class]
];
}

Expand Down

0 comments on commit 3c0940b

Please sign in to comment.