-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
test/UserRepository/HtpasswdFactoryTest/ConfigImplementingArrayAccess.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MezzioTest\Authentication\UserRepository\HtpasswdFactoryTest; | ||
|
||
use ArrayAccess; | ||
use OutOfBoundsException; | ||
|
||
use function array_key_exists; | ||
use function assert; | ||
use function is_string; | ||
|
||
/** | ||
* @template-implements ArrayAccess<string,mixed> | ||
*/ | ||
final class ConfigImplementingArrayAccess implements ArrayAccess | ||
{ | ||
/** @var array<array-key,mixed> */ | ||
private $data; | ||
|
||
/** | ||
* @param array<string,mixed> $data | ||
*/ | ||
public function __construct(array $data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
/** | ||
* @psalm-param array-key $offset | ||
* @return bool | ||
*/ | ||
public function offsetExists($offset) | ||
{ | ||
return array_key_exists($offset, $this->data); | ||
} | ||
|
||
/** | ||
* @psalm-param array-key $offset | ||
* @return mixed | ||
*/ | ||
public function offsetGet($offset) | ||
{ | ||
if (! $this->offsetExists($offset)) { | ||
throw new OutOfBoundsException(); | ||
} | ||
|
||
return $this->data[$offset]; | ||
} | ||
|
||
/** | ||
* @psalm-param array-key $offset | ||
*/ | ||
public function offsetSet($offset, $value) | ||
{ | ||
assert(is_string($offset)); | ||
$this->data[$offset] = $value; | ||
} | ||
|
||
/** | ||
* @psalm-param array-key $offset | ||
*/ | ||
public function offsetUnset($offset) | ||
{ | ||
unset($this->data[$offset]); | ||
} | ||
} |