Skip to content

Commit

Permalink
Merge pull request #1773 from XWB/update-resource-owner-map
Browse files Browse the repository at this point in the history
Use type hints and return types in ResourceOwnerMapInterface
  • Loading branch information
stloyd committed Aug 3, 2021
2 parents ec5c799 + 66fa03d commit e61c49c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 50 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Changelog
* BC Break: removed configuration option `fosub` from `oauth_user_provider`,
* BC Break: removed configuration options `hwi_oauth.fosub`, & all related DI parameters,
* BC Break: removed DI parameter `hwi_oauth.registration.form.factory` in favour of declaring form class name as DI parameter: `hwi_oauth.connect.registration_form`,
* BC Break: changed `ResourceOwnerMapInterface::hasResourceOwnerByName` signature, update if you use a custom resource owner,
* BC Break: changed `ResourceOwnerMapInterface::getResourceOwnerByName` signature, update if you use a custom resource owner,
* BC Break: changed `ResourceOwnerMapInterface::getResourceOwnerByRequest` signature, update if you use a custom resource owner,
* BC Break: changed `ResourceOwnerMapInterface::getResourceOwnerCheckPath` signature, update if you use a custom resource owner,

## 1.4.1 (2021-07-28)
* Bugfix: Define missing `hwi_oauth.connect.confirmation` parameter,
Expand Down
42 changes: 12 additions & 30 deletions Security/Http/ResourceOwnerMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,16 @@
*/
class ResourceOwnerMap implements ContainerAwareInterface, ResourceOwnerMapInterface
{
/**
* @var HttpUtils
*/
protected $httpUtils;

/**
* @var array
*/
protected $resourceOwners;

/**
* @var array
*/
protected $possibleResourceOwners;

/**
* @var ContainerInterface
*/
protected $container;
protected HttpUtils $httpUtils;
protected array $resourceOwners;
protected array $possibleResourceOwners;
protected ContainerInterface $container;

/**
* Constructor.
*
* @param HttpUtils $httpUtils HttpUtils
* @param array $possibleResourceOwners array with possible resource owners names
* @param array $resourceOwners array with configured resource owners
* @param array<string, string> $possibleResourceOwners array with possible resource owners names
* @param array<string, string> $resourceOwners array with configured resource owners
*/
public function __construct(HttpUtils $httpUtils, array $possibleResourceOwners, $resourceOwners)
public function __construct(HttpUtils $httpUtils, array $possibleResourceOwners, array $resourceOwners)
{
$this->httpUtils = $httpUtils;
$this->possibleResourceOwners = $possibleResourceOwners;
Expand All @@ -73,15 +55,15 @@ public function setContainer(ContainerInterface $container = null)
/**
* {@inheritdoc}
*/
public function hasResourceOwnerByName($name)
public function hasResourceOwnerByName(string $name): bool
{
return isset($this->resourceOwners[$name], $this->possibleResourceOwners[$name]);
}

/**
* {@inheritdoc}
*/
public function getResourceOwnerByName($name)
public function getResourceOwnerByName(string $name): ?ResourceOwnerInterface
{
if (!$this->hasResourceOwnerByName($name)) {
return null;
Expand All @@ -96,7 +78,7 @@ public function getResourceOwnerByName($name)
/**
* {@inheritdoc}
*/
public function getResourceOwnerByRequest(Request $request)
public function getResourceOwnerByRequest(Request $request): ?array
{
foreach ($this->resourceOwners as $name => $checkPath) {
if ($this->httpUtils->checkRequestPath($request, $checkPath)) {
Expand All @@ -117,7 +99,7 @@ public function getResourceOwnerByRequest(Request $request)
/**
* {@inheritdoc}
*/
public function getResourceOwnerCheckPath($name)
public function getResourceOwnerCheckPath(string $name): ?string
{
if (isset($this->resourceOwners[$name])) {
return $this->resourceOwners[$name];
Expand All @@ -129,7 +111,7 @@ public function getResourceOwnerCheckPath($name)
/**
* {@inheritdoc}
*/
public function getResourceOwners()
public function getResourceOwners(): array
{
return $this->resourceOwners;
}
Expand Down
26 changes: 6 additions & 20 deletions Security/Http/ResourceOwnerMapInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,28 @@ interface ResourceOwnerMapInterface
{
/**
* Check that resource owner with given name exists.
*
* @param string $name
*
* @return bool
*/
public function hasResourceOwnerByName($name);
public function hasResourceOwnerByName(string $name): bool;

/**
* Gets the appropriate resource owner given the name.
*
* @param string $name
*
* @return ResourceOwnerInterface|null
*/
public function getResourceOwnerByName($name);
public function getResourceOwnerByName(string $name): ?ResourceOwnerInterface;

/**
* Gets the appropriate resource owner for a request.
*
* @return array|null
*/
public function getResourceOwnerByRequest(Request $request);
public function getResourceOwnerByRequest(Request $request): ?array;

/**
* Gets the check path for given resource name.
*
* @param string $name
*
* @return string|null
*/
public function getResourceOwnerCheckPath($name);
public function getResourceOwnerCheckPath(string $name): ?string;

/**
* Get all the resource owners.
*
* @return ResourceOwnerInterface[]
* @return array<string, string>
*/
public function getResourceOwners();
public function getResourceOwners(): array;
}

0 comments on commit e61c49c

Please sign in to comment.