Skip to content

Commit

Permalink
Merge pull request #149 from aldinokemal/feat/compatible-php-8
Browse files Browse the repository at this point in the history
feat: add compatible with php 8
  • Loading branch information
jasny authored Aug 9, 2023
2 parents 9469117 + 7504a16 commit ef9f917
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 36 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ jobs:
fail-fast: false
matrix:
include:
- php: 7.3
- php: 7.4
coverage: '--coverage --coverage-xml'
- php: 8.0
- php: 8.1
- php: 8.2
coverage: '--coverage --coverage-xml'
name: PHP ${{ matrix.php }}

steps:
- uses: actions/checkout@v2

with:
fetch-depth: 10

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -39,7 +41,7 @@ jobs:

- name: Upload coverage to Scrutinizer
if: ${{ matrix.coverage }}
run: >
wget https://scrutinizer-ci.com/ocular.phar -O "/tmp/ocular.phar" &&
php "/tmp/ocular.phar" code-coverage:upload --format=php-clover tests/_output/coverage.xml
uses: sudo-bot/action-scrutinizer@latest
with:
cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ tests/_output/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
/tests/_support/_generated/
.idea
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build:
nodes:
analysis:
environment:
php: 7.4
php: 8.2
postgresql: false
redis: false
mongodb: false
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"source": "https://github.com/jasny/sso"
},
"require": {
"php": ">=7.3.0",
"php": "^8.0",
"ext-json": "*",
"jasny/immutable": "^2.1",
"psr/simple-cache": "^1.0",
Expand Down
46 changes: 19 additions & 27 deletions src/Broker/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,17 @@
class Cookies implements \ArrayAccess
{
/** @var int */
protected $ttl;
protected int $ttl;

/** @var string */
protected $path;
protected string $path;

/** @var string */
protected $domain;
protected string $domain;

/** @var bool */
protected $secure;
protected bool $secure;

/**
* Cookies constructor.
*
* @param int $ttl Cookie TTL in seconds
* @param string $path
* @param string $domain
* @param bool $secure
*/
public function __construct(int $ttl = 3600, string $path = '', string $domain = '', bool $secure = false)
{
$this->ttl = $ttl;
Expand All @@ -43,39 +35,39 @@ public function __construct(int $ttl = 3600, string $path = '', string $domain =
/**
* @inheritDoc
*/
public function offsetSet($name, $value)
public function offsetExists(mixed $offset): bool
{
$success = setcookie($name, $value, time() + $this->ttl, $this->path, $this->domain, $this->secure, true);

if (!$success) {
throw new \RuntimeException("Failed to set cookie '$name'");
}

$_COOKIE[$name] = $value;
return isset($_COOKIE[$offset]);
}

/**
* @inheritDoc
*/
public function offsetUnset($name): void
public function offsetGet(mixed $offset): mixed
{
setcookie($name, '', 1, $this->path, $this->domain, $this->secure, true);
unset($_COOKIE[$name]);
return $_COOKIE[$offset] ?? null;
}

/**
* @inheritDoc
*/
public function offsetGet($name)
public function offsetSet(mixed $offset, mixed $value): void
{
return $_COOKIE[$name] ?? null;
$success = setcookie($offset, $value, time() + $this->ttl, $this->path, $this->domain, $this->secure, true);

if (!$success) {
throw new \RuntimeException("Failed to set cookie '$offset'");
}

$_COOKIE[$offset] = $value;
}

/**
* @inheritDoc
*/
public function offsetExists($name)
public function offsetUnset(mixed $offset): void
{
return isset($_COOKIE[$name]);
setcookie($offset, '', 1, $this->path, $this->domain, $this->secure, true);
unset($_COOKIE[$offset]);
}
}

0 comments on commit ef9f917

Please sign in to comment.