Abstract Class yii\authclient\BaseClient
BaseClient is a base Auth Client class.
See also yii\
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $httpClient | array|\ |
Internal HTTP client. | yii\ |
| $id | string | Service id. | yii\ |
| $name | string | Service name. | yii\ |
| $normalizeUserAttributeMap | array | Normalize user attribute map. | yii\ |
| $requestOptions | array | HTTP request options. | yii\ |
| $stateStorage | yii\ |
Stage storage to be used. | yii\ |
| $title | string | Service title. | yii\ |
| $userAttributes | array | List of user attributes. | yii\ |
| $viewOptions | array | View options in format: optionName => optionValue. | yii\ |
Public Methods
Protected Methods
Property Details
Internal HTTP client.
Normalize user attribute map.
Stage storage to be used.
View options in format: optionName => optionValue.
Method Details
Creates HTTP client instance from reference or configuration.
| protected \ | ||
| $reference | string|array |
Component name or array configuration. |
| return | \ |
HTTP client instance. |
|---|---|---|
protected function createHttpClient($reference)
{
return Instance::ensure($reference, Client::class);
}
Creates HTTP request instance.
| public \ | ||
| return | \ |
HTTP request instance. |
|---|---|---|
public function createRequest()
{
return $this->getHttpClient()
->createRequest()
->addOptions($this->defaultRequestOptions())
->addOptions($this->getRequestOptions());
}
Generates service name.
| protected string defaultName ( ) | ||
| return | string |
Service name. |
|---|---|---|
protected function defaultName()
{
return Inflector::camel2id(StringHelper::basename(get_class($this)));
}
Returns the default $normalizeUserAttributeMap value.
Particular client may override this method in order to provide specific default map.
| protected array defaultNormalizeUserAttributeMap ( ) | ||
| return | array |
Normalize attribute map. |
|---|---|---|
protected function defaultNormalizeUserAttributeMap()
{
return [];
}
Returns default HTTP request options.
| protected array defaultRequestOptions ( ) | ||
| return | array |
HTTP request options. |
|---|---|---|
protected function defaultRequestOptions()
{
return [
'timeout' => 30,
];
}
Generates service title.
| protected string defaultTitle ( ) | ||
| return | string |
Service title. |
|---|---|---|
protected function defaultTitle()
{
return StringHelper::basename(get_class($this));
}
Returns the default $viewOptions value.
Particular client may override this method in order to provide specific default view options.
| protected array defaultViewOptions ( ) | ||
| return | array |
List of default $viewOptions |
|---|---|---|
protected function defaultViewOptions()
{
return [];
}
Returns HTTP client.
| public \ | ||
| return | \ |
Internal HTTP client. |
|---|---|---|
public function getHttpClient()
{
if (!is_object($this->_httpClient)) {
$this->_httpClient = $this->createHttpClient($this->_httpClient);
}
return $this->_httpClient;
}
| public string getId ( ) | ||
| return | string |
Service id |
|---|---|---|
public function getId()
{
if (empty($this->_id)) {
$this->_id = $this->getName();
}
return $this->_id;
}
| public string getName ( ) | ||
| return | string |
Service name. |
|---|---|---|
public function getName()
{
if ($this->_name === null) {
$this->_name = $this->defaultName();
}
return $this->_name;
}
| public array getNormalizeUserAttributeMap ( ) | ||
| return | array |
Normalize user attribute map. |
|---|---|---|
public function getNormalizeUserAttributeMap()
{
if ($this->_normalizeUserAttributeMap === null) {
$this->_normalizeUserAttributeMap = $this->defaultNormalizeUserAttributeMap();
}
return $this->_normalizeUserAttributeMap;
}
| public array getRequestOptions ( ) | ||
| return | array |
HTTP request options. |
|---|---|---|
public function getRequestOptions()
{
return $this->_requestOptions;
}
Returns persistent state value.
| protected mixed getState ( string $key ) | ||
| $key | string |
State key. |
| return | mixed |
State value. |
|---|---|---|
protected function getState($key)
{
return $this->getStateStorage()->get($this->getStateKeyPrefix() . $key);
}
Returns session key prefix, which is used to store internal states.
| protected string getStateKeyPrefix ( ) | ||
| return | string |
Session key prefix. |
|---|---|---|
protected function getStateKeyPrefix()
{
return get_class($this) . '_' . $this->getId() . '_';
}
| public yii\ | ||
| return | yii\ |
Stage storage. |
|---|---|---|
public function getStateStorage()
{
if (!is_object($this->_stateStorage)) {
$this->_stateStorage = Yii::createObject($this->_stateStorage);
}
return $this->_stateStorage;
}
| public string getTitle ( ) | ||
| return | string |
Service title. |
|---|---|---|
public function getTitle()
{
if ($this->_title === null) {
$this->_title = $this->defaultTitle();
}
return $this->_title;
}
| public array getUserAttributes ( ) | ||
| return | array |
List of user attributes |
|---|---|---|
public function getUserAttributes()
{
if ($this->_userAttributes === null) {
$this->_userAttributes = $this->normalizeUserAttributes($this->initUserAttributes());
}
return $this->_userAttributes;
}
| public array getViewOptions ( ) | ||
| return | array |
View options in format: optionName => optionValue |
|---|---|---|
public function getViewOptions()
{
if ($this->_viewOptions === null) {
$this->_viewOptions = $this->defaultViewOptions();
}
return $this->_viewOptions;
}
Initializes authenticated user attributes.
| protected abstract array initUserAttributes ( ) | ||
| return | array |
Auth user attributes. |
|---|---|---|
abstract protected function initUserAttributes();
Normalize given user attributes according to $normalizeUserAttributeMap.
| protected array normalizeUserAttributes ( array $attributes ) | ||
| $attributes | array |
Raw attributes. |
| return | array |
Normalized attributes. |
|---|---|---|
| throws | \ |
on incorrect normalize attribute map. |
protected function normalizeUserAttributes($attributes)
{
foreach ($this->getNormalizeUserAttributeMap() as $normalizedName => $actualName) {
if (is_scalar($actualName)) {
if (array_key_exists($actualName, $attributes)) {
$attributes[$normalizedName] = $attributes[$actualName];
}
} else {
if (is_callable($actualName)) {
$attributes[$normalizedName] = call_user_func($actualName, $attributes);
} elseif (is_array($actualName)) {
$haystack = $attributes;
$searchKeys = $actualName;
$isFound = true;
while (($key = array_shift($searchKeys)) !== null) {
if (is_array($haystack) && array_key_exists($key, $haystack)) {
$haystack = $haystack[$key];
} else {
$isFound = false;
break;
}
}
if ($isFound) {
$attributes[$normalizedName] = $haystack;
}
} else {
throw new InvalidConfigException('Invalid actual name "' . gettype($actualName) . '" specified at "' . get_class($this) . '::normalizeUserAttributeMap"');
}
}
}
return $attributes;
}
Removes persistent state value.
| protected boolean removeState ( string $key ) | ||
| $key | string |
State key. |
| return | boolean |
Success. |
|---|---|---|
protected function removeState($key)
{
return $this->getStateStorage()->remove($this->getStateKeyPrefix() . $key);
}
Sets HTTP client to be used.
| public mixed setHttpClient ( array|\ | ||
| $httpClient | array|\ |
Internal HTTP client. |
public function setHttpClient($httpClient)
{
$this->_httpClient = $httpClient;
}
| public mixed setId ( string $id ) | ||
| $id | string |
Service id. |
public function setId($id)
{
$this->_id = $id;
}
| public mixed setName ( string $name ) | ||
| $name | string |
Service name. |
public function setName($name)
{
$this->_name = $name;
}
| public mixed setNormalizeUserAttributeMap ( array $normalizeUserAttributeMap ) | ||
| $normalizeUserAttributeMap | array |
Normalize user attribute map. |
public function setNormalizeUserAttributeMap($normalizeUserAttributeMap)
{
$this->_normalizeUserAttributeMap = $normalizeUserAttributeMap;
}
| public mixed setRequestOptions ( array $options ) | ||
| $options | array |
HTTP request options. |
public function setRequestOptions(array $options)
{
$this->_requestOptions = $options;
}
Sets persistent state.
| protected $this setState ( string $key, mixed $value ) | ||
| $key | string |
State key. |
| $value | mixed |
State value |
| return | $this |
The object itself |
|---|---|---|
protected function setState($key, $value)
{
$this->getStateStorage()->set($this->getStateKeyPrefix() . $key, $value);
return $this;
}
| public mixed setStateStorage ( yii\ | ||
| $stateStorage | yii\ |
Stage storage to be used. |
public function setStateStorage($stateStorage)
{
$this->_stateStorage = $stateStorage;
}
| public mixed setTitle ( string $title ) | ||
| $title | string |
Service title. |
public function setTitle($title)
{
$this->_title = $title;
}
| public mixed setUserAttributes ( array $userAttributes ) | ||
| $userAttributes | array |
List of user attributes |
public function setUserAttributes($userAttributes)
{
$this->_userAttributes = $this->normalizeUserAttributes($userAttributes);
}
| public mixed setViewOptions ( array $viewOptions ) | ||
| $viewOptions | array |
View options in format: optionName => optionValue |
public function setViewOptions($viewOptions)
{
$this->_viewOptions = $viewOptions;
}