mirror of
https://github.com/1sept/oauth2-1sept.git
synced 2024-05-30 17:38:52 +03:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d95d71e571 | |||
| 5ab62ace79 | |||
| 0b2c6b6c31 | |||
| 66ae333e6a | |||
| 3380b4a0ae | |||
| c8b7f9901a | |||
| bc1a2399f4 | |||
| 88fe261f43 | |||
| ddf2d1b6e4 | |||
| eb43f28d61 | |||
| 6d06db0d56 | |||
| e418024705 | |||
| eca6845e85 |
16
.editorconfig
Normal file
16
.editorconfig
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# @see http://EditorConfig.org
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[**]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_style = space
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[{src,tests}/**.php]
|
||||||
|
tab_width = 4
|
||||||
|
|
||||||
|
[*.{neon,xml,md}]
|
||||||
|
tab_width = 4
|
||||||
43
.gitattributes
vendored
Normal file
43
.gitattributes
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Common settings that generally should always be used with your language specific settings
|
||||||
|
|
||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
# http://davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/
|
||||||
|
# Handle line endings automatically for files detected as text
|
||||||
|
# and leave all files detected as binary untouched.
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
# Git
|
||||||
|
.gitattributes text
|
||||||
|
.gitignore text
|
||||||
|
.gitconfig text
|
||||||
|
.gitmodules text
|
||||||
|
|
||||||
|
# source code
|
||||||
|
*.php diff=php
|
||||||
|
|
||||||
|
*.json text
|
||||||
|
*.markdown text
|
||||||
|
*.md text
|
||||||
|
*.neon.dist text
|
||||||
|
*.xml text
|
||||||
|
*.xml.dist text
|
||||||
|
*README* text
|
||||||
|
.editorconfig text
|
||||||
|
AUTHORS text
|
||||||
|
LICENSE text
|
||||||
|
|
||||||
|
# Ignore export
|
||||||
|
/.appveyor.yml export-ignore
|
||||||
|
/.editorconfig export-ignore
|
||||||
|
/.editorconfig export-ignore
|
||||||
|
/.gitattributes export-ignore
|
||||||
|
/.github export-ignore
|
||||||
|
/.gitignore export-ignore
|
||||||
|
/.gitignore export-ignore
|
||||||
|
/SECURITY.md export-ignore
|
||||||
|
/docs export-ignore
|
||||||
|
/phpcs.xml.dist export-ignore
|
||||||
|
/phpstan.neon.dist export-ignore
|
||||||
|
/phpunit.xml.dist export-ignore
|
||||||
|
/psalm.xml.dist export-ignore
|
||||||
|
/tests export-ignore
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
/build
|
/build
|
||||||
/vendor
|
/vendor
|
||||||
|
.phpunit.cache
|
||||||
composer.phar
|
composer.phar
|
||||||
composer.lock
|
composer.lock
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
@@ -21,7 +21,11 @@
|
|||||||
"league/oauth2-client": "^2.0"
|
"league/oauth2-client": "^2.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "~4.0"
|
"phpstan/extension-installer": "^1.3",
|
||||||
|
"phpstan/phpdoc-parser": "^1.29",
|
||||||
|
"phpstan/phpstan": "^1.10",
|
||||||
|
"phpstan/phpstan-strict-rules": "^1.5",
|
||||||
|
"phpunit/phpunit": "^11.1"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@@ -30,12 +34,25 @@
|
|||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Sept\\OAuth2\\Client\\Test\\": "test/src/"
|
"Sept\\OAuth2\\Client\\Test\\": "tests"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "1.0.x-dev"
|
"dev-master": "1.0.x-dev"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": [
|
||||||
|
"@phpunit",
|
||||||
|
"@phpstan"
|
||||||
|
],
|
||||||
|
"phpunit": "vendor/bin/phpunit",
|
||||||
|
"phpstan": "vendor/bin/phpstan"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"allow-plugins": {
|
||||||
|
"phpstan/extension-installer": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
phpstan.neon.dist
Normal file
5
phpstan.neon.dist
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
parameters:
|
||||||
|
level: 8
|
||||||
|
paths:
|
||||||
|
- src
|
||||||
|
- tests
|
||||||
37
phpunit.xml
37
phpunit.xml
@@ -1,37 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<phpunit backupGlobals="false"
|
|
||||||
backupStaticAttributes="false"
|
|
||||||
bootstrap="vendor/autoload.php"
|
|
||||||
colors="true"
|
|
||||||
convertErrorsToExceptions="true"
|
|
||||||
convertNoticesToExceptions="true"
|
|
||||||
convertWarningsToExceptions="true"
|
|
||||||
processIsolation="false"
|
|
||||||
stopOnFailure="false"
|
|
||||||
syntaxCheck="false"
|
|
||||||
>
|
|
||||||
<logging>
|
|
||||||
<log type="coverage-html"
|
|
||||||
target="./build/coverage/html"
|
|
||||||
charset="UTF-8"
|
|
||||||
highlight="false"
|
|
||||||
lowUpperBound="35"
|
|
||||||
highLowerBound="70"/>
|
|
||||||
<log type="coverage-clover"
|
|
||||||
target="./build/coverage/log/coverage.xml"/>
|
|
||||||
</logging>
|
|
||||||
<testsuites>
|
|
||||||
<testsuite name="Package Test Suite">
|
|
||||||
<directory suffix=".php">./test/</directory>
|
|
||||||
</testsuite>
|
|
||||||
</testsuites>
|
|
||||||
<filter>
|
|
||||||
<whitelist>
|
|
||||||
<directory suffix=".php">./</directory>
|
|
||||||
<exclude>
|
|
||||||
<directory suffix=".php">./vendor</directory>
|
|
||||||
<directory suffix=".php">./test</directory>
|
|
||||||
</exclude>
|
|
||||||
</whitelist>
|
|
||||||
</filter>
|
|
||||||
</phpunit>
|
|
||||||
13
phpunit.xml.dist
Executable file
13
phpunit.xml.dist
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" failOnRisky="true" failOnWarning="true" colors="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="true" beStrictAboutCoverageMetadata="true">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Gos Test Suite">
|
||||||
|
<directory suffix=".php">tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<source>
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">src</directory>
|
||||||
|
</include>
|
||||||
|
</source>
|
||||||
|
</phpunit>
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
<?php
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
namespace Sept\OAuth2\Client\Provider;
|
namespace Sept\OAuth2\Client\Provider;
|
||||||
|
|
||||||
use League\OAuth2\Client\Provider\AbstractProvider;
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
||||||
|
use League\OAuth2\Client\Provider\GenericProvider;
|
||||||
use League\OAuth2\Client\Token\AccessToken;
|
use League\OAuth2\Client\Token\AccessToken;
|
||||||
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
|
||||||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Провайдер данных Первого сентября
|
* Провайдер данных Первого сентября
|
||||||
*/
|
*/
|
||||||
class SeptemberFirstProvider extends AbstractProvider
|
class SeptemberFirstProvider extends GenericProvider
|
||||||
{
|
{
|
||||||
use BearerAuthorizationTrait;
|
use BearerAuthorizationTrait;
|
||||||
|
|
||||||
@@ -26,62 +26,74 @@ class SeptemberFirstProvider extends AbstractProvider
|
|||||||
const API_BASE = 'https://api.1sept.ru';
|
const API_BASE = 'https://api.1sept.ru';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string Версия API
|
* @var string[] Разрешения (scopes) по умолчанию
|
||||||
*/
|
*/
|
||||||
const API_VERSION = '2.0';
|
const SCOPES_DEFAULT = ['profile'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @var string Разделитель перечня запрашиваемых разрешений
|
||||||
*/
|
*/
|
||||||
public function getBaseAuthorizationUrl(): string
|
const SCOPES_SEPARATOR = ' ';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Путь авторизации
|
||||||
|
*/
|
||||||
|
const AUTHORIZE_PATH = '/oauth/authorize';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Путь получения токена
|
||||||
|
*/
|
||||||
|
const ACCESS_TOKEN_PATH = '/oauth/access_token';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Путь получения данных пользователя
|
||||||
|
*/
|
||||||
|
const USERINFO_PATH = '/2.0/userinfo';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param mixed[] $options
|
||||||
|
* @param object[] $collaborators
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = [], array $collaborators = [])
|
||||||
{
|
{
|
||||||
return static::AUTH_BASE.'/oauth/authorize';
|
$authBase = $options['authBase'] ?? static::AUTH_BASE;
|
||||||
|
$apiBase = $options['apiBase'] ?? static::API_BASE;
|
||||||
|
|
||||||
|
$defaultOptions = [
|
||||||
|
'urlAuthorize' => $authBase.static::AUTHORIZE_PATH,
|
||||||
|
'urlAccessToken' => $apiBase.static::ACCESS_TOKEN_PATH,
|
||||||
|
'urlResourceOwnerDetails' => $apiBase.static::USERINFO_PATH,
|
||||||
|
'scopes' => static::SCOPES_DEFAULT,
|
||||||
|
'scopeSeparator' => static::SCOPES_SEPARATOR,
|
||||||
|
];
|
||||||
|
|
||||||
|
parent::__construct(array_merge($defaultOptions, $options), $collaborators);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* Checks a provider response for errors.
|
||||||
*/
|
*
|
||||||
public function getBaseAccessTokenUrl(array $params): string
|
* @param ResponseInterface $response
|
||||||
{
|
* @param mixed[]|string $data — Parsed response data
|
||||||
return static::API_BASE.'/oauth/access_token';
|
* @return void
|
||||||
}
|
*
|
||||||
|
* @throws IdentityProviderException
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function getResourceOwnerDetailsUrl(AccessToken $token): string
|
|
||||||
{
|
|
||||||
return static::API_BASE.'/'.static::API_VERSION.'/userinfo';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function getDefaultScopes(): array
|
|
||||||
{
|
|
||||||
return ['profile'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
protected function getScopeSeparator(): string
|
|
||||||
{
|
|
||||||
return ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
*/
|
||||||
protected function checkResponse(ResponseInterface $response, $data): void
|
protected function checkResponse(ResponseInterface $response, $data): void
|
||||||
{
|
{
|
||||||
if (!empty($data['error'])) {
|
if (isset($data['error'])) {
|
||||||
throw new IdentityProviderException($data['error'].': '.$data['message'], null, $response);
|
throw new IdentityProviderException($data['error'].': '.$data['message'], 0, $response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* Generates a resource owner object from a successful resource owner details request.
|
||||||
|
*
|
||||||
|
* @param mixed[] $response
|
||||||
|
* @param AccessToken $token
|
||||||
|
* @return SeptemberFirstUser
|
||||||
*/
|
*/
|
||||||
protected function createResourceOwner(array $response, AccessToken $token): SeptemberFirstUser
|
protected function createResourceOwner(array $response, AccessToken $token): SeptemberFirstUser
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
namespace Sept\OAuth2\Client\Provider;
|
namespace Sept\OAuth2\Client\Provider;
|
||||||
|
|
||||||
@@ -12,10 +12,13 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
const AVATAR_BASE = 'https://avatar.1sept.ru';
|
const AVATAR_BASE = 'https://avatar.1sept.ru';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Массив с данными о пользователе
|
* @var mixed[] Массив с данными о пользователе
|
||||||
*/
|
*/
|
||||||
protected $data;
|
protected array $data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed[] $response
|
||||||
|
*/
|
||||||
public function __construct(array $response)
|
public function __construct(array $response)
|
||||||
{
|
{
|
||||||
$this->data = $response;
|
$this->data = $response;
|
||||||
@@ -24,7 +27,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Массив с данными о пользователе
|
* Массив с данными о пользователе
|
||||||
*
|
*
|
||||||
* @return array
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
@@ -56,7 +59,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Фамилия
|
* Фамилия
|
||||||
*
|
*
|
||||||
* @var string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getLastName(): ?string
|
public function getLastName(): ?string
|
||||||
{
|
{
|
||||||
@@ -66,7 +69,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Имя
|
* Имя
|
||||||
*
|
*
|
||||||
* @var string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getFirstName(): ?string
|
public function getFirstName(): ?string
|
||||||
{
|
{
|
||||||
@@ -76,7 +79,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Отчество
|
* Отчество
|
||||||
*
|
*
|
||||||
* @var string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getMiddleName(): ?string
|
public function getMiddleName(): ?string
|
||||||
{
|
{
|
||||||
@@ -113,6 +116,16 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
return $this->getField('sex');
|
return $this->getField('sex');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Регалии
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getRegalia(): string|null
|
||||||
|
{
|
||||||
|
return $this->getField('regalia');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Умер
|
* Умер
|
||||||
*
|
*
|
||||||
@@ -140,20 +153,20 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
*/
|
*/
|
||||||
public function getBirthday(): ?\DateTime
|
public function getBirthday(): ?\DateTime
|
||||||
{
|
{
|
||||||
return !empty($this->data['birthday']) ? new \DateTime($this->data['birthday']) : null;
|
return isset($this->data['birthday']) ? new \DateTime($this->data['birthday']) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL аватарки (150x150)
|
* URL аватарки (150x150)
|
||||||
*
|
*
|
||||||
* @param bool $addVersion Использовать версию аватарки для улучшенного кэширования
|
* @param bool $rejectDefaultAvatar
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*
|
*
|
||||||
* @example https://avatar.1sept.ru/12121212-3456-7243-2134-432432144221.jpeg?v=12345
|
* @example https://avatar.1sept.ru/12121212-3456-7243-2134-432432144221.jpeg?v=12345
|
||||||
*/
|
*/
|
||||||
public function getAvatarUrl(bool $addVersion = true): ?string
|
public function getAvatarUrl(bool $rejectDefaultAvatar = false): ?string
|
||||||
{
|
{
|
||||||
return $this->getField('avatar') . ($addVersion ? $this->getAvatarVersionQuery() : '');
|
return ($rejectDefaultAvatar && ($this->isDefaultAvatar() ?? false)) ? null : $this->getField('avatar');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,7 +180,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
public function getAvatarSizeUrl(int $size, int $ratioMultiplier = 1, bool $addVersion = true): ?string
|
public function getAvatarSizeUrl(int $size, int $ratioMultiplier = 1, bool $addVersion = true): ?string
|
||||||
{
|
{
|
||||||
$ratio = ($ratioMultiplier > 1) ? '@' . $ratioMultiplier . 'x' : '';
|
$ratio = ($ratioMultiplier > 1) ? '@' . $ratioMultiplier . 'x' : '';
|
||||||
$url = static::AVATAR_BASE .'/'. $this->getId() . ($size ? '.' : '') . $size . $ratio . '.jpeg';
|
$url = static::AVATAR_BASE .'/'. $this->getId() . (((bool) $size)? '.' : '') . $size . $ratio . '.jpeg';
|
||||||
return $url . ($addVersion ? $this->getAvatarVersionQuery() : '');
|
return $url . ($addVersion ? $this->getAvatarVersionQuery() : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,8 +201,9 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* URL аватарки c максимальным размером
|
* URL аватарки c максимальным размером
|
||||||
*
|
*
|
||||||
* @param bool $useVersion Использовать версию аватарки для улучшенного кэширования
|
* @param bool $addVersion Использовать версию аватарки для улучшенного кэширования
|
||||||
* @return string|null
|
* @return string|null
|
||||||
|
*
|
||||||
* @example https://avatar.1sept.ru/12121212-3456-7243-2134-432432144221.max.jpeg?v=12345
|
* @example https://avatar.1sept.ru/12121212-3456-7243-2134-432432144221.max.jpeg?v=12345
|
||||||
*/
|
*/
|
||||||
public function getAvatarMaxUrl(bool $addVersion = false): ?string
|
public function getAvatarMaxUrl(bool $addVersion = false): ?string
|
||||||
@@ -212,9 +226,9 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Является ли аватарка заглушкой
|
* Является ли аватарка заглушкой
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function isDefaultAvatar(): bool
|
public function isDefaultAvatar(): ?bool
|
||||||
{
|
{
|
||||||
return (bool) $this->getField('avatar_default');
|
return (bool) $this->getField('avatar_default');
|
||||||
}
|
}
|
||||||
@@ -228,7 +242,8 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
public function getAvatarVersionQuery(): string
|
public function getAvatarVersionQuery(): string
|
||||||
{
|
{
|
||||||
$query = '';
|
$query = '';
|
||||||
if ($version = $this->getField('avatar_version')) {
|
$version = $this->getField('avatar_version');
|
||||||
|
if ((bool) $version) {
|
||||||
$query .= '?v=' . $version;
|
$query .= '?v=' . $version;
|
||||||
}
|
}
|
||||||
return $query;
|
return $query;
|
||||||
@@ -248,7 +263,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
/**
|
/**
|
||||||
* Номера телефонов
|
* Номера телефонов
|
||||||
*
|
*
|
||||||
* @return array|null
|
* @return array<int, array<string, string>>
|
||||||
* @example [
|
* @example [
|
||||||
* [
|
* [
|
||||||
* "canonical" => "+79161234567",
|
* "canonical" => "+79161234567",
|
||||||
@@ -267,7 +282,7 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
* СНИЛС
|
* СНИЛС
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
* @example 123-123-123 56
|
* @example 123-456-789 01
|
||||||
*/
|
*/
|
||||||
public function getSnils(): ?string
|
public function getSnils(): ?string
|
||||||
{
|
{
|
||||||
@@ -296,6 +311,18 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
return $this->getField('timezone');
|
return $this->getField('timezone');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID адреса
|
||||||
|
*
|
||||||
|
* @return int|null
|
||||||
|
* @example 12345
|
||||||
|
*/
|
||||||
|
public function getAddressID(): ?int
|
||||||
|
{
|
||||||
|
$id = $this->getField('address.id');
|
||||||
|
return ((bool) $id) ? ((int) $id) : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID страны адреса
|
* ID страны адреса
|
||||||
*
|
*
|
||||||
@@ -330,7 +357,106 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Почтовый адрес в строку
|
* Район
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Октябрьский район
|
||||||
|
*/
|
||||||
|
public function getAddressArea(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.area');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Город
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Муром
|
||||||
|
*/
|
||||||
|
public function getAddressCity(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.city');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Улица
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example ул. Профсоюзная
|
||||||
|
*/
|
||||||
|
public function getAddressStreet(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.street');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Здание, сооружение, дом, владение, объект незавершенного строительства
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example д. 5
|
||||||
|
*/
|
||||||
|
public function getAddressHouse(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.house');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Строение
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example стр. 5
|
||||||
|
*/
|
||||||
|
public function getAddressBuilding(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.building');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Помещение в пределах здания, сооружения (Квартира, офис, помещение и т.д.)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example кв. 1б | оф. 13 | помещ. 17
|
||||||
|
*/
|
||||||
|
public function getAddressFlat(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.flat');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* До востребования
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
* @example true
|
||||||
|
*/
|
||||||
|
public function isAddressGeneralDelivery(): bool
|
||||||
|
{
|
||||||
|
return (bool) $this->getField('address.general_delivery');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Абонентский ящик (А/Я)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example а/я 123
|
||||||
|
*/
|
||||||
|
public function getAddressPostalBox(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.postal_box');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Организация по адресу
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Школа №5
|
||||||
|
*/
|
||||||
|
public function getAddressOrganization(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.organization');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Почтовый адрес в строку (без индекса)
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
* @example ул. Гагарина, д.5, кв. 21, Нижний Новгород
|
* @example ул. Гагарина, д.5, кв. 21, Нижний Новгород
|
||||||
@@ -410,9 +536,9 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
* Элемент массива данных о пользователе
|
* Элемент массива данных о пользователе
|
||||||
*
|
*
|
||||||
* @param string $key Ключ поля (например: email или name.first — вложенность оформляется точкой)
|
* @param string $key Ключ поля (например: email или name.first — вложенность оформляется точкой)
|
||||||
* @return mixed|null
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function getField(string $key)
|
protected function getField(string $key): mixed
|
||||||
{
|
{
|
||||||
return static::getFieldFromArray($key, $this->data);
|
return static::getFieldFromArray($key, $this->data);
|
||||||
}
|
}
|
||||||
@@ -421,11 +547,12 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
* Значение массива (многомерного)
|
* Значение массива (многомерного)
|
||||||
*
|
*
|
||||||
* @param string $key Ключ поля (например: `email` или `name.first` — вложенность оформляется точкой)
|
* @param string $key Ключ поля (например: `email` или `name.first` — вложенность оформляется точкой)
|
||||||
* @return mixed|null
|
* @param mixed[] $array
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function getFieldFromArray(string $key, ?array $array)
|
public static function getFieldFromArray(string $key, ?array $array): mixed
|
||||||
{
|
{
|
||||||
if (strpos($key, '.')) { // key.subKey.subSubKey
|
if ((bool) strpos($key, '.')) { // key.subKey.subSubKey
|
||||||
list ($key, $subKey) = explode('.', $key, 2);
|
list ($key, $subKey) = explode('.', $key, 2);
|
||||||
return isset($array[$key]) ? static::getFieldFromArray($subKey, $array[$key]) : null;
|
return isset($array[$key]) ? static::getFieldFromArray($subKey, $array[$key]) : null;
|
||||||
}
|
}
|
||||||
|
|||||||
22
tests/UserTest.php
Normal file
22
tests/UserTest.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Sept\OAuth2\Client\Test;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\Attributes\CoversMethod;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Sept\OAuth2\Client\Provider\SeptemberFirstUser;
|
||||||
|
|
||||||
|
#[CoversMethod(SeptemberFirstUser::class, 'getFirstName')]
|
||||||
|
final class UserTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreate(): void
|
||||||
|
{
|
||||||
|
$name = 'Alex';
|
||||||
|
$user = new SeptemberFirstUser([
|
||||||
|
'personal_name' => [
|
||||||
|
'name' => $name,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
self::assertSame($name, $user->getFirstName());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user