Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 3bc0faa

Browse files
committed
Fixed phpdoc
1 parent 48c1086 commit 3bc0faa

File tree

9 files changed

+125
-15
lines changed

9 files changed

+125
-15
lines changed

src/Adapter/BasicAccess.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,41 @@
1515

1616
class BasicAccess implements AuthenticationInterface
1717
{
18-
protected $register;
18+
/**
19+
* @var UserRepositoryInterface
20+
*/
21+
protected $repository;
22+
23+
/**
24+
* @var string
25+
*/
1926
protected $realm;
27+
28+
/**
29+
* @var ResponseInterface
30+
*/
2031
protected $responsePrototype;
2132

33+
/**
34+
* Constructor
35+
*
36+
* @param UserRepositoryInterface $repository
37+
* @param string $realm
38+
* @param ResponseInterface $responsePrototype
39+
*/
2240
public function __construct(
23-
UserRepositoryInterface $register,
41+
UserRepositoryInterface $repository,
2442
string $realm,
2543
ResponseInterface $responsePrototype
2644
) {
27-
$this->register = $register;
45+
$this->repository = $repository;
2846
$this->realm = $realm;
2947
$this->responsePrototype = $responsePrototype;
3048
}
3149

50+
/**
51+
* {@inheritDoc}
52+
*/
3253
public function authenticate(ServerRequestInterface $request): ?UserInterface
3354
{
3455
$authHeader = $request->getHeader('Authorization');
@@ -40,9 +61,12 @@ public function authenticate(ServerRequestInterface $request): ?UserInterface
4061
}
4162
[$username, $password] = explode(':', base64_decode($match[1]));
4263

43-
return $this->register->authenticate($username, $password);
64+
return $this->repository->authenticate($username, $password);
4465
}
4566

67+
/**
68+
* {@inheritDoc}
69+
*/
4670
public function unauthorizedResponse(ServerRequestInterface $request): ResponseInterface
4771
{
4872
return $this->responsePrototype->withHeader(

src/Adapter/PhpSession.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,41 @@
1515

1616
class PhpSession implements AuthenticationInterface
1717
{
18-
protected $register;
18+
/**
19+
* @var UserRepositoryInterface
20+
*/
21+
protected $repository;
22+
23+
/**
24+
* @var array
25+
*/
1926
protected $config;
27+
28+
/**
29+
* @var ResponseInterface
30+
*/
2031
protected $responsePrototype;
2132

33+
/**
34+
* Constructor
35+
*
36+
* @param UserRepositoryInterface $repository
37+
* @param array $config
38+
* @param ResponseInterface $responsePrototype
39+
*/
2240
public function __construct(
23-
UserRepositoryInterface $register,
41+
UserRepositoryInterface $repository,
2442
array $config,
2543
ResponseInterface $responsePrototype
2644
) {
27-
$this->register = $register;
45+
$this->repository = $repository;
2846
$this->config = $config;
2947
$this->responsePrototype = $responsePrototype;
3048
}
3149

50+
/**
51+
* {@inheritDoc}
52+
*/
3253
public function authenticate(ServerRequestInterface $request): ?UserInterface
3354
{
3455
$cookies = $request->getCookieParams();
@@ -47,7 +68,7 @@ public function authenticate(ServerRequestInterface $request): ?UserInterface
4768
if (!isset($params[$username]) || !isset($params[$password])) {
4869
return null;
4970
}
50-
$user = $this->register->authenticate(
71+
$user = $this->repository->authenticate(
5172
$params[$username],
5273
$params[$password]
5374
);
@@ -60,6 +81,9 @@ public function authenticate(ServerRequestInterface $request): ?UserInterface
6081
return null;
6182
}
6283

84+
/**
85+
* {@inheritDoc}
86+
*/
6387
public function unauthorizedResponse(ServerRequestInterface $request): ResponseInterface
6488
{
6589
return $this->responsePrototype->withHeader(
@@ -68,6 +92,12 @@ public function unauthorizedResponse(ServerRequestInterface $request): ResponseI
6892
)->withStatus(301);
6993
}
7094

95+
/**
96+
* Set the PHP SESSION ID
97+
*
98+
* @param string $id
99+
* @return void
100+
*/
71101
private function setSessionId(string $id): void
72102
{
73103
session_name(AuthenticationInterface::class);

src/Adapter/ZendAuthentication.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,28 @@ class ZendAuthentication implements AuthenticationInterface
1818
{
1919
use UserTrait;
2020

21+
/**
22+
* @var AuthenticationService
23+
*/
2124
protected $auth;
25+
26+
/**
27+
* @var array
28+
*/
2229
protected $config;
30+
31+
/**
32+
* @var ResponseInterface
33+
*/
2334
protected $responsePrototype;
2435

36+
/**
37+
* Constructor
38+
*
39+
* @param AuthenticationService $auth
40+
* @param array $config
41+
* @param ResponseInterface $responsePrototype
42+
*/
2543
public function __construct(
2644
AuthenticationService $auth,
2745
array $config,
@@ -32,6 +50,9 @@ public function __construct(
3250
$this->responsePrototype = $responsePrototype;
3351
}
3452

53+
/**
54+
* {@inheritDoc}
55+
*/
3556
public function authenticate(ServerRequestInterface $request): ?UserInterface
3657
{
3758
if ('POST' === $request->getMethod()) {
@@ -56,6 +77,9 @@ public function authenticate(ServerRequestInterface $request): ?UserInterface
5677
null;
5778
}
5879

80+
/**
81+
* {@inheritDoc}
82+
*/
5983
public function unauthorizedResponse(ServerRequestInterface $request): ResponseInterface
6084
{
6185
return $this->responsePrototype->withHeader(

src/ConfigProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function getDependencies() : array
2727
{
2828
return [
2929
'aliases' => [
30-
// Change the alias value for Authentication adapter and
30+
// Change the alias values for Authentication adapter and
3131
// UserRepository adapter
3232
AuthenticationInterface::class => Adapter\BasicAccess::class,
3333
UserRepositoryInterface::class => UserRepository\Htpasswd::class

src/ResponsePrototypeTrait.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313
trait ResponsePrototypeTrait
1414
{
15+
/**
16+
* Return a ResponseInterface service if present or Zend\Diactoros\Response
17+
*
18+
* @param ContainerInterface $container
19+
* @throws Exception\InvalidConfigException
20+
* @return ResponseInterface
21+
*/
1522
protected function getResponsePrototype(ContainerInterface $container): ResponseInterface
1623
{
1724
if (! $container->has(ResponseInterface::class)
@@ -20,7 +27,7 @@ protected function getResponsePrototype(ContainerInterface $container): Response
2027
throw new Exception\InvalidConfigException(sprintf(
2128
'Cannot create %s service; dependency %s is missing. Either define the service, '
2229
. 'or install zendframework/zend-diactoros',
23-
OAuth2Middleware::class,
30+
static::class,
2431
ResponseInterface::class
2532
));
2633
}

src/UserRepository/Htpasswd.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
/**
1414
* Adapter for Apache htpasswd file
1515
* It supports only bcrypt hash password for security reason
16+
* @see https://httpd.apache.org/docs/2.4/programs/htpasswd.html
1617
*/
17-
1818
class Htpasswd implements UserRepositoryInterface
1919
{
20-
protected $authenticatedUser = null;
21-
2220
use UserTrait;
2321

22+
/**
23+
* Constructor
24+
*
25+
* @param string $filename
26+
*/
2427
public function __construct(string $filename)
2528
{
2629
if (! file_exists($filename)) {

src/UserRepository/PdoDatabase.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ class PdoDatabase implements UserRepositoryInterface
1919
{
2020
use UserTrait;
2121

22+
/**
23+
* Constructor
24+
*
25+
* @param PDO $pdo
26+
* @param array $config
27+
*/
2228
public function __construct(PDO $pdo, array $config)
2329
{
2430
$this->pdo = $pdo;

src/UserRepository/PdoDatabaseFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ public function __invoke(ContainerInterface $container) : PdoDatabase
4242
);
4343
}
4444
return new PdoDatabase(
45-
new PDO($pdo['dsn'], $pdo['username'] ?? null, $pdo['password'] ?? null),
45+
new PDO(
46+
$pdo['dsn'],
47+
$pdo['username'] ?? null,
48+
$pdo['password'] ?? null
49+
),
4650
$pdo
4751
);
4852
}

src/UserRepository/UserTrait.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive-authentication for the canonical source repository
4+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive-authentication/blob/master/LICENSE.md New BSD License
6+
*/
7+
28
namespace Zend\Expressive\Authentication\UserRepository;
39

410
use Zend\Expressive\Authentication\UserInterface;
511

612
trait UserTrait
713
{
14+
/**
15+
* Generate a user from $username and $role
16+
*
17+
* @param string $username
18+
* @param string $role
19+
* @return UserInterface
20+
*/
821
protected function generateUser(string $username, string $role): UserInterface
922
{
1023
return new class($username, $role) implements UserInterface {
11-
1224
public function __construct($username, $role)
1325
{
1426
$this->username = $username;

0 commit comments

Comments
 (0)