diff --git a/.github/workflows/branch_alias.yml b/.github/workflows/branch_alias.yml deleted file mode 100644 index d92f3e5..0000000 --- a/.github/workflows/branch_alias.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: Update branch alias - -on: - push: - tags: ['*'] - -jobs: - branch-alias: - name: Update branch alias - runs-on: ubuntu-latest - - steps: - - name: Set up PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.0 - coverage: none - - - name: Find branch alias - id: find_alias - run: | - TAG=$(echo $GITHUB_REF | cut -d'/' -f 3) - echo "Last tag was $TAG" - ARR=(${TAG//./ }) - ARR[1]=$((${ARR[1]}+1)) - echo ::set-output name=alias::${ARR[0]}.${ARR[1]} - - - name: Checkout main repo - run: | - git clone --branch master https://${{ secrets.BOT_GITHUB_TOKEN }}:x-oauth-basic@github.com/async-aws/aws aws - - - name: Update branch alias - run: | - cd aws/src/Integration/Aws/DynamoDbSession - CURRENT_ALIAS=$(composer config extra.branch-alias.dev-master | cut -d'-' -f 1) - - # If there is a current value on the branch alias - if [ ! -z $CURRENT_ALIAS ]; then - NEW_ALIAS=${{ steps.find_alias.outputs.alias }} - CURRENT_ARR=(${CURRENT_ALIAS//./ }) - NEW_ARR=(${NEW_ALIAS//./ }) - - if [ ${CURRENT_ARR[0]} -gt ${NEW_ARR[0]} ]; then - echo "The current value for major version is larger" - exit 1; - fi - - if [ ${CURRENT_ARR[0]} -eq ${NEW_ARR[0]} ] && [ ${CURRENT_ARR[1]} -gt ${NEW_ARR[1]} ]; then - echo "The current value for minor version is larger" - exit 1; - fi - fi - - composer config extra.branch-alias.dev-master ${{ steps.find_alias.outputs.alias }}-dev - - - name: Commit & push the new files - run: | - echo "::group::git status" - cd aws - git status - echo "::endgroup::" - - git add -N . - if [[ $(git diff --numstat | wc -l) -eq 0 ]]; then - echo "No changes found. Exiting." - exit 0; - fi - - git config --local user.email "github@async-aws.com" - git config --local user.name "AsyncAws Bot" - - echo "::group::git push" - git add . - git commit -m "Update branch alias" - git push - echo "::endgroup::" diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 1a72276..b9c47e8 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -12,7 +12,9 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Modify composer.json run: | @@ -23,5 +25,14 @@ jobs: git config --local user.name "AsyncAws Bot" git commit -am "Allow unstable dependencies" + - name: Install PHP with extensions + uses: shivammathur/setup-php@v2 + with: + php-version: 8.3 + tools: composer:v2 + + - name: Install roave/backward-compatibility-check + run: composer require --dev roave/backward-compatibility-check + - name: Roave BC Check - uses: docker://nyholm/roave-bc-check-ga + run: vendor/bin/roave-backward-compatibility-check diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a382c27..944db96 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: max-parallel: 10 matrix: - php: ['7.2', '7.3', '7.4', '8.0'] + php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] steps: - name: Set up PHP @@ -23,7 +23,7 @@ jobs: coverage: none - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Download dependencies run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 117594f..f63d6bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,33 @@ ## NOT RELEASED +## 1.1.1 + +### Changed + +- Enable compiler optimization for the `sprintf` function. + +## 1.1.0 + +### Added + +- Added support for `async-aws/dynamo-db` 2.0 and 3.0 + +## 1.0.2 + +### Changed + +- Improve parameter type and return type in phpdoc + ## 1.0.1 -### Updated +### Changed - Fix deprecations triggered by php 8.1 ## 1.0.0 -### Updated +### Changed - Use async-aws/dynamo-db: ^1.0 diff --git a/composer.json b/composer.json index 17e7aa4..c7bf0b3 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { "name": "async-aws/dynamo-db-session", - "type": "library", "description": "AsyncAws DynamoDB integration for PHP Sessions.", + "license": "MIT", + "type": "library", "keywords": [ "aws", "amazon", @@ -10,15 +11,9 @@ "dynamo-db", "session" ], - "license": "MIT", "require": { "php": "^7.2.5 || ^8.0", - "async-aws/dynamo-db": "^1.0" - }, - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - } + "async-aws/dynamo-db": "^1.0 || ^2.0 || ^3.0" }, "autoload": { "psr-4": { @@ -29,5 +24,10 @@ "psr-4": { "AsyncAws\\DynamoDbSession\\Tests\\": "tests/" } + }, + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } } } diff --git a/src/SessionHandler.php b/src/SessionHandler.php index 5ccd62d..fecf954 100644 --- a/src/SessionHandler.php +++ b/src/SessionHandler.php @@ -16,7 +16,15 @@ class SessionHandler implements \SessionHandlerInterface private $client; /** - * @var array + * @var array{ + * consistent_read?: bool, + * data_attribute: string, + * hash_key: string, + * session_lifetime?: int, + * session_lifetime_attribute: string, + * table_name: string, + * id_separator: string + * } */ private $options; @@ -54,11 +62,11 @@ class SessionHandler implements \SessionHandlerInterface public function __construct(DynamoDbClient $client, array $options) { $this->client = $client; + $options['data_attribute'] = $options['data_attribute'] ?? 'data'; + $options['hash_key'] = $options['hash_key'] ?? 'id'; + $options['session_lifetime_attribute'] = $options['session_lifetime_attribute'] ?? 'expires'; + $options['id_separator'] = $options['id_separator'] ?? '_'; $this->options = $options; - $this->options['data_attribute'] = $this->options['data_attribute'] ?? 'data'; - $this->options['hash_key'] = $this->options['hash_key'] ?? 'id'; - $this->options['session_lifetime_attribute'] = $this->options['session_lifetime_attribute'] ?? 'expires'; - $this->options['id_separator'] = $this->options['id_separator'] ?? '_'; } public function setUp(): void @@ -83,7 +91,7 @@ public function setUp(): void $response = $this->client->tableExists(['TableName' => $this->options['table_name']]); $response->wait(100, 3); if (!$response->isSuccess()) { - throw new RuntimeException(sprintf('Could not create table %s', $this->options['table_name'])); + throw new RuntimeException(\sprintf('Could not create table %s', $this->options['table_name'])); } $this->client->updateTimeToLive([ @@ -104,7 +112,7 @@ public function close() $id = session_id(); // Make sure the expiration time is updated, even if the write did not occur - if ($this->sessionId !== $id || !$this->sessionWritten) { + if (false !== $id && ($this->sessionId !== $id || !$this->sessionWritten)) { $this->sessionWritten = $this->doWrite($id, false); } @@ -193,7 +201,7 @@ public function write($sessionId, $sessionData) private function doWrite(string $id, bool $updateData, string $data = ''): bool { - $expires = time() + ($this->options['session_lifetime'] ?? (int) ini_get('session.gc_maxlifetime')); + $expires = time() + ($this->options['session_lifetime'] ?? (int) \ini_get('session.gc_maxlifetime')); $attributes = [ $this->options['session_lifetime_attribute'] => ['Value' => ['N' => (string) $expires]], @@ -223,6 +231,9 @@ private function formatId(string $id): string return trim($this->sessionName . $this->options['id_separator'] . $id, $this->options['id_separator']); } + /** + * @return array + */ private function formatKey(string $key): array { return [$this->options['hash_key'] => ['S' => $key]];