| 1 |
<?php |
| 2 |
|
| 3 |
namespace Intervention\HttpAuth\Token; |
| 4 |
|
| 5 |
use Intervention\HttpAuth\Key; |
| 6 |
|
| 7 |
class PhpAuthUser extends NullToken |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Parsed authentification username |
| 11 |
* |
| 12 |
* @var string |
| 13 |
*/ |
| 14 |
protected $username; |
| 15 |
|
| 16 |
/** |
| 17 |
* Parsed authentification password |
| 18 |
* |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
protected $password; |
| 22 |
|
| 23 |
/** |
| 24 |
* Transform current instance to key object |
| 25 |
* |
| 26 |
* @return Key |
| 27 |
*/ |
| 28 |
public function toKey(): Key |
| 29 |
{ |
| 30 |
$key = new Key(); |
| 31 |
$key->setProperty('username', $this->username); |
| 32 |
$key->setProperty('password', $this->password); |
| 33 |
|
| 34 |
return $key; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Parse environment variables and store value in object |
| 39 |
* |
| 40 |
* @return bool "true" if value was found or "false" |
| 41 |
*/ |
| 42 |
protected function parse(): bool |
| 43 |
{ |
| 44 |
if ($username = $this->getArrayValue($_SERVER, 'PHP_AUTH_USER')) { |
| 45 |
$this->username = $username; |
| 46 |
$this->password = array_key_exists('PHP_AUTH_PW', $_SERVER) ? $_SERVER['PHP_AUTH_PW'] : null; |
| 47 |
|
| 48 |
return true; |
| 49 |
} |
| 50 |
|
| 51 |
return false; |
| 52 |
} |
| 53 |
} |
| 54 |
|