Skip to content

Commit

Permalink
Merge pull request #21 from citrus-framework/fix_url_parse
Browse files Browse the repository at this point in the history
urlパース処理の修正とphp8.1化
  • Loading branch information
take64 authored Jul 18, 2023
2 parents 13e93a9 + bb187f6 commit 23c689e
Show file tree
Hide file tree
Showing 20 changed files with 218 additions and 485 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ define highlight
@echo "\033[1;32m$1\033[0m"
endef

.PHONY: test_all
test_all:
.PHONY: test
test:
@./vendor/bin/phpunit

.PHONY: composer_reload
Expand All @@ -17,7 +17,7 @@ composer_reload:

.PHONY: composer_develop
composer_develop:
@composer install -vv --dev --prefer-dist --optimize-autoloader
@composer install -vv --prefer-dist --optimize-autoloader

.PHONY: composer_public
composer_public:
Expand Down
23 changes: 16 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,31 @@
"citrus-framework/http": "^1.0",
"citrus-framework/logger": "^1.0",
"citrus-framework/sqlmap": "^1.0",
"citrus-framework/variables": "^1.1",
"citrus-framework/variables": "^1.1"
},
"require-dev": {
"php": "^8.1",
"phpunit/phpunit": "^9.5",
"nunomaduro/phpinsights": "^v2.0",
"ext-mbstring": "*",
"ext-posix": "*",
"ext-json": "*",
"ext-pdo": "*",
"ext-openssl": "*"
},
"require-dev": {
"php": "^7.3",
"phpunit/phpunit": "8.4.1",
"nunomaduro/phpinsights": "^1.10"
},
"autoload": {
"psr-4": {
"Citrus\\": "src/",
"Citrus\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Test\\": "tests/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
81 changes: 39 additions & 42 deletions phpinsights.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,56 @@
return [
'preset' => 'default',
'exclude' => [
// 'path/to/directory-or-file'
],
'add' => [
// ExampleMetric::class => [
// ExampleInsight::class,
// ]
NunoMaduro\PhpInsights\Domain\Metrics\Code\Code::class => [
// Code
SlevomatCodingStandard\Sniffs\ControlStructures\RequireYodaComparisonSniff::class,
],
],
'remove' => [
// ExampleInsight::class,
SlevomatCodingStandard\Sniffs\ControlStructures\DisallowShortTernaryOperatorSniff::class,
SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff::class,
SlevomatCodingStandard\Sniffs\PHP\UselessParenthesesSniff::class,
SlevomatCodingStandard\Sniffs\TypeHints\DisallowArrayTypeHintSyntaxSniff::class,
SlevomatCodingStandard\Sniffs\TypeHints\UselessConstantTypeHintSniff::class,
// Code
NunoMaduro\PhpInsights\Domain\Insights\ForbiddenGlobals::class,
SlevomatCodingStandard\Sniffs\Classes\ForbiddenPublicPropertySniff::class,
NunoMaduro\PhpInsights\Domain\Sniffs\ForbiddenSetterSniff::class,
PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer::class,
PhpCsFixer\Fixer\Operator\TernaryOperatorSpacesFixer::class,
PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagFixer::class,
PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer::class,
PhpCsFixer\Fixer\Phpdoc\AlignMultilineCommentFixer::class,
PHP_CodeSniffer\Standards\PSR2\Sniffs\ControlStructures\ElseIfDeclarationSniff::class,
PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\SpaceAfterCastSniff::class,
NunoMaduro\PhpInsights\Domain\Insights\ForbiddenTraits::class,
SlevomatCodingStandard\Sniffs\Classes\SuperfluousExceptionNamingSniff::class,
NunoMaduro\PhpInsights\Domain\Insights\ForbiddenNormalClasses::class,
PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UselessOverridingMethodSniff::class,
SlevomatCodingStandard\Sniffs\Commenting\UselessInheritDocCommentSniff::class,
SlevomatCodingStandard\Sniffs\TypeHints\DisallowMixedTypeHintSniff::class,
SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff::class,
SlevomatCodingStandard\Sniffs\ControlStructures\LanguageConstructWithParenthesesSniff::class,
SlevomatCodingStandard\Sniffs\Functions\StaticClosureSniff::class,
SlevomatCodingStandard\Sniffs\PHP\UselessParenthesesSniff::class,
SlevomatCodingStandard\Sniffs\TypeHints\DisallowArrayTypeHintSyntaxSniff::class,
SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff::class,
SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff::class,
SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff::class,

// Architecture
NunoMaduro\PhpInsights\Domain\Insights\ForbiddenNormalClasses::class,
NunoMaduro\PhpInsights\Domain\Insights\ForbiddenTraits::class,
SlevomatCodingStandard\Sniffs\Classes\SuperfluousExceptionNamingSniff::class,

// Style
PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\ArbitraryParenthesesSpacingSniff::class,
],
'config' => [
// ExampleInsight::class => [
// 'key' => 'value',
// ],
ObjectCalisthenics\Sniffs\NamingConventions\ElementNameMinimalLengthSniff::class => [
'minLength' => 3,
'allowedShortNames' => ['i', 'id', 'to', 'up', 'ky', 'vl', 'e'],
],
PhpCsFixer\Fixer\CastNotation\CastSpacesFixer::class => [
'space' => 'none',
// Architecture
SlevomatCodingStandard\Sniffs\Functions\FunctionLengthSniff::class => [
'maxLinesLength' => 32,
],

// Style
PhpCsFixer\Fixer\Basic\BracesFixer::class => [
'allow_single_line_closure' => false,
'position_after_anonymous_constructs' => 'same', // possible values ['same', 'next']
'position_after_control_structures' => 'next', // possible values ['same', 'next']
'position_after_functions_and_oop_constructs' => 'next', // possible values ['same', 'next']
'position_after_anonymous_constructs' => 'same',
'position_after_control_structures' => 'next',
'position_after_functions_and_oop_constructs' => 'next',
],
SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff::class => [
'linesCountBeforeFirstContent' => 0,
'linesCountBetweenDescriptionAndAnnotations' => 1,
'linesCountBetweenDifferentAnnotationsTypes' => 0,
'linesCountBetweenAnnotationsGroups' => 0,
'linesCountAfterLastContent' => 0,
'annotationsGroups' => [],
PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer::class => [
'operators' => [
'=>' => 'align_single_space',
],
'default' => 'single_space', // default fix strategy: possibles values ['align', 'align_single_space', 'align_single_space_minimal', 'single_space', 'no_space', null]
],
PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer::class => [
'tokens' => [], // possibles values ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']
Expand All @@ -72,8 +64,13 @@
'absoluteLineLimit' => 120,
'ignoreComments' => true,
],
\ObjectCalisthenics\Sniffs\Files\FunctionLengthSniff::class => [
'maxLength' => 32,
]
SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff::class => [
'linesCountBeforeFirstContent' => 0,
'linesCountBetweenDescriptionAndAnnotations' => 1,
'linesCountBetweenDifferentAnnotationsTypes' => 0,
'linesCountBetweenAnnotationsGroups' => 0,
'linesCountAfterLastContent' => 0,
'annotationsGroups' => [],
],
],
];
4 changes: 2 additions & 2 deletions src/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function deAuthorize(): bool
* @param AuthItem|null $item
* @return bool true:チェック成功, false:チェック失敗
*/
public function isAuthenticated(AuthItem $item = null): bool
public function isAuthenticated(AuthItem|null $item = null): bool
{
if (true === is_null($this->protocol))
{
Expand All @@ -129,7 +129,7 @@ public function isAuthenticated(AuthItem $item = null): bool
* @throws CitrusException
* @throws SessionException
*/
public static function generateToken(string $key = null): string
public static function generateToken(string|null $key = null): string
{
// セッションが無効 もしくは 存在しない場合
SessionException::exceptionIf(
Expand Down
56 changes: 25 additions & 31 deletions src/Authentication/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@
/**
* このモジュールを利用する場合は以下の構成のテーブルが必要です
*
CREATE TABLE IF NOT EXISTS users (
user_id CHARACTER VARYING(32) NOT NULL,
password CHARACTER VARYING(64) NOT NULL,
token TEXT,
expired_at TIMESTAMP WITHOUT TIME ZONE,
status INTEGER DEFAULT 0 NOT NULL,
created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT current_timestamp NOT NULL,
updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT current_timestamp NOT NULL,
rowid SERIAL NOT NULL,
rev INTEGER DEFAULT 1 NOT NULL
);
COMMENT ON COLUMN users.user_id IS 'ユーザーID';
COMMENT ON COLUMN users.paswword IS 'パスワードハッシュ';
COMMENT ON COLUMN users.token IS 'アクセストークン';
ALTER TABLE users ADD CONSTRAINT pk_users PRIMARY KEY (user_id);
CREATE INDEX IF NOT EXISTS idx_users_user_id_token ON users (user_id, token);
* CREATE TABLE IF NOT EXISTS users (
* user_id CHARACTER VARYING(32) NOT NULL,
* password CHARACTER VARYING(64) NOT NULL,
* token TEXT,
* expired_at TIMESTAMP WITHOUT TIME ZONE,
* status INTEGER DEFAULT 0 NOT NULL,
* created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT current_timestamp NOT NULL,
* updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT current_timestamp NOT NULL,
* rowid SERIAL NOT NULL,
* rev INTEGER DEFAULT 1 NOT NULL
* );
* COMMENT ON COLUMN users.user_id IS 'ユーザーID';
* COMMENT ON COLUMN users.paswword IS 'パスワードハッシュ';
* COMMENT ON COLUMN users.token IS 'アクセストークン';
*
* ALTER TABLE users ADD CONSTRAINT pk_users PRIMARY KEY (user_id);
* CREATE INDEX IF NOT EXISTS idx_users_user_id_token ON users (user_id, token);
*/
class Database extends Protocol
{
/** @var Connection */
public $connection;
public Connection $connection;



Expand All @@ -55,8 +55,6 @@ public function __construct(Connection $connection)
$this->connection = $connection;
}



/**
* 認証処理
*
Expand Down Expand Up @@ -107,7 +105,6 @@ public function authorize(AuthItem $item): bool
return true;
}


/**
* 認証解除処理
*
Expand All @@ -121,22 +118,17 @@ public function deAuthorize(): bool
return true;
}



/**
* 認証のチェック
* 認証できていれば期間の延長
*
* @param AuthItem|null $item
* @return bool true:チェック成功, false:チェック失敗
*/
public function isAuthenticated(AuthItem $item = null): bool
public function isAuthenticated(AuthItem|null $item = null): bool
{
// 指定されない場合はsessionから取得
if (true === is_null($item))
{
$item = Session::$session->call(Authentication::SESSION_KEY);
}
$item ??= Session::$session->call(Authentication::SESSION_KEY);
// 認証itemが無い
if (true === is_null($item))
{
Expand All @@ -147,11 +139,12 @@ public function isAuthenticated(AuthItem $item = null): bool
// ユーザーIDとトークン、認証期間があるか
if (true === is_null($item->user_id) or true === is_null($item->token) or true === is_null($item->expired_at))
{
Logger::debug('ログアウト:ユーザIDが無い(user_id=%s)、もしくはトークンが無い(token=%s)、もしくはタイムアウト(expired_at=%s)',
Logger::debug(
'ログアウト:ユーザIDが無い(user_id=%s)、もしくはトークンが無い(token=%s)、もしくはタイムアウト(expired_at=%s)',
$item->user_id,
$item->token,
$item->expired_at
);
);
return false;
}

Expand All @@ -160,7 +153,8 @@ public function isAuthenticated(AuthItem $item = null): bool
$now_ts = time();
if ($expired_ts < $now_ts)
{
Logger::debug('ログアウト:タイムアウト(%s) < 現在時間(%s)',
Logger::debug(
'ログアウト:タイムアウト(%s) < 現在時間(%s)',
$expired_ts,
$now_ts
);
Expand Down
Loading

0 comments on commit 23c689e

Please sign in to comment.