mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Merge pull request #859 from romainneutron/circular
[3.9] Remove some circular references
This commit is contained in:
@@ -16,11 +16,11 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
|
|
||||||
class TokenValidator
|
class TokenValidator
|
||||||
{
|
{
|
||||||
private $app;
|
private $random;
|
||||||
|
|
||||||
public function __construct(Application $app)
|
public function __construct(\random $random)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->random = $random;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,7 +32,7 @@ class TokenValidator
|
|||||||
public function isValid($token)
|
public function isValid($token)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$datas = $this->app['tokens']->helloToken($token);
|
$datas = $this->random->helloToken($token);
|
||||||
|
|
||||||
return $datas['usr_id'];
|
return $datas['usr_id'];
|
||||||
} catch (NotFoundHttpException $e) {
|
} catch (NotFoundHttpException $e) {
|
||||||
|
@@ -37,7 +37,7 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface
|
|||||||
});
|
});
|
||||||
|
|
||||||
$app['authentication.token-validator'] = $app->share(function (Application $app) {
|
$app['authentication.token-validator'] = $app->share(function (Application $app) {
|
||||||
return new TokenValidator($app);
|
return new TokenValidator($app['tokens']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app['authentication.persistent-manager'] = $app->share(function (Application $app) {
|
$app['authentication.persistent-manager'] = $app->share(function (Application $app) {
|
||||||
|
@@ -26,7 +26,6 @@ class Session_Logger
|
|||||||
* @var databox
|
* @var databox
|
||||||
*/
|
*/
|
||||||
protected $databox;
|
protected $databox;
|
||||||
protected $app;
|
|
||||||
|
|
||||||
const EVENT_DELETE = 'delete';
|
const EVENT_DELETE = 'delete';
|
||||||
const EVENT_EDIT = 'edit';
|
const EVENT_EDIT = 'edit';
|
||||||
@@ -48,9 +47,8 @@ class Session_Logger
|
|||||||
*
|
*
|
||||||
* @return Session_Logger
|
* @return Session_Logger
|
||||||
*/
|
*/
|
||||||
public function __construct(Application $app, databox $databox, $log_id)
|
public function __construct(databox $databox, $log_id)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
|
||||||
$this->databox = $databox;
|
$this->databox = $databox;
|
||||||
$this->id = (int) $log_id;
|
$this->id = (int) $log_id;
|
||||||
|
|
||||||
@@ -154,7 +152,7 @@ class Session_Logger
|
|||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
unset($stmt, $conn);
|
unset($stmt, $conn);
|
||||||
|
|
||||||
return new Session_Logger($app, $databox, $log_id);
|
return new Session_Logger($databox, $log_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function load(Application $app, databox $databox)
|
public static function load(Application $app, databox $databox)
|
||||||
@@ -179,7 +177,7 @@ class Session_Logger
|
|||||||
if ( ! $row)
|
if ( ! $row)
|
||||||
throw new Exception_Session_LoggerNotFound('Logger not found');
|
throw new Exception_Session_LoggerNotFound('Logger not found');
|
||||||
|
|
||||||
return new self($app, $databox, $row['id']);
|
return new self($databox, $row['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function updateClientInfos(Application $app, $appId)
|
public static function updateClientInfos(Application $app, $appId)
|
||||||
|
@@ -11,12 +11,10 @@ class TokenValidatorTest extends \PhraseanetTestCase
|
|||||||
*/
|
*/
|
||||||
public function testValidTokenIsValid()
|
public function testValidTokenIsValid()
|
||||||
{
|
{
|
||||||
$app = self::$DI['app'];
|
|
||||||
$usr_id = 42;
|
$usr_id = 42;
|
||||||
|
|
||||||
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_VALIDATE, $usr_id);
|
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_VALIDATE, $usr_id);
|
||||||
|
|
||||||
$validator = new TokenValidator($app);
|
$validator = new TokenValidator(self::$DI['app']['tokens']);
|
||||||
$this->assertEquals($usr_id, $validator->isValid($token));
|
$this->assertEquals($usr_id, $validator->isValid($token));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -24,12 +22,10 @@ class TokenValidatorTest extends \PhraseanetTestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidTokenIsNotValid()
|
public function testInvalidTokenIsNotValid()
|
||||||
{
|
{
|
||||||
$app = self::$DI['app'];
|
|
||||||
$usr_id = 42;
|
$usr_id = 42;
|
||||||
|
|
||||||
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_VALIDATE, $usr_id, new \DateTime('-2 hours'));
|
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_VALIDATE, $usr_id, new \DateTime('-2 hours'));
|
||||||
|
|
||||||
$validator = new TokenValidator($app);
|
$validator = new TokenValidator(self::$DI['app']['tokens']);
|
||||||
$this->assertFalse($validator->isValid($token));
|
$this->assertFalse($validator->isValid($token));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user