Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initiate config with array #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions sdk/src/core/Auth/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public static function getInstance()

#region Private methods

private function _generateNewToken()
private function _generateNewToken(array $config = [])
{
$username = ConfigFileLoader::getInstance()->getConfAttribute('username');
$password = ConfigFileLoader::getInstance()->getConfAttribute('password');
$urlToken = ConfigFileLoader::getInstance()->getConfAttribute('urltoken');
$username = isset($config['username']) ? $config['username'] : ConfigFileLoader::getInstance()->getConfAttribute('username');
$password = isset($config['password']) ? $config['password'] : ConfigFileLoader::getInstance()->getConfAttribute('password');
$urlToken = isset($config['urlToken']) ? $config['urlToken'] : ConfigFileLoader::getInstance()->getConfAttribute('urltoken');

$request = new CDSApiRequest($username, $password, $urlToken);

Expand All @@ -104,13 +104,15 @@ private function _generateNewToken()

/**
* Generate a new token or return the actual active token
* @param array $config
* @return string|null
*/
public function getToken()
public function getToken(array $config = [])
{
//TODO vérifier la date

if (!$this->_isValid) {
$this->_generateNewToken();
$this->_generateNewToken($config);
}
return $this->_token;
}
Expand Down
6 changes: 4 additions & 2 deletions sdk/src/public/ApiClient/CDSApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ public function getMailPoint()

/**
* Create and check the token
* @param array $config
* @return string|null
*/
public function init()
public function init(array $config = [])
{
$token = Token::getInstance()->getToken();
$token = Token::getInstance()->getToken($config);
return $token;
}

Expand Down