Skip to content

Commit

Permalink
Backporting pst/container#2.0 change from laminas/laminas-servicemana…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoelker committed Oct 17, 2023
1 parent b4f5470 commit 9a2cd5b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 42 deletions.
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"laminas/laminas-stdlib": "^3.17",
"psr/container": "^1.0"
"psr/container": "^1.1 || ^2.0"
},
"require-dev": {
"composer/package-versions-deprecated": "^1.11.99.5",
Expand All @@ -37,17 +37,14 @@
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.8.0"
},
"replace": {
"container-interop/container-interop": "^1.2.0"
},
"conflict": {
"ext-psr": "*",
"laminas/laminas-code": "<4.10.0",
"zendframework/zend-code": "<3.3.1",
"zendframework/zend-servicemanager": "*"
},
"provide": {
"psr/container-implementation": "^1.0"
"psr/container-implementation": "^1.0 || ^2.0"
},
"suggest": {
"friendsofphp/proxy-manager-lts": "ProxyManager ^2.1.1 to handle lazy initialization of services"
Expand Down
43 changes: 25 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@
<code>$factory</code>
<code><![CDATA[(callable(ContainerInterface,string,array<mixed>|null):object)|Factory\FactoryInterface]]></code>
</MixedReturnTypeCoercion>
<ParamNameMismatch>
<code>$name</code>
<code>$name</code>
</ParamNameMismatch>
<RedundantCastGivenDocblockType>
<code>(bool) $flag</code>
<code>(bool) $flag</code>
Expand Down
5 changes: 2 additions & 3 deletions src/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public function setService($name, $service)

/**
* @param class-string<InstanceType>|string $name Service name of plugin to retrieve.

Check failure on line 145 in src/AbstractPluginManager.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

UnusedDocblockParam

src/AbstractPluginManager.php:145:49: UnusedDocblockParam: Docblock parameter $name in docblock for Laminas\ServiceManager\AbstractPluginManager::get does not have a counterpart in signature parameter list (see https://psalm.dev/319)
* @param null|array<mixed> $options Options to use when creating the instance.
* @return mixed

Check failure on line 146 in src/AbstractPluginManager.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Method \Laminas\ServiceManager\AbstractPluginManager::get() has useless @return annotation.
* @psalm-return ($name is class-string<InstanceType> ? InstanceType : mixed)
* @throws Exception\ServiceNotFoundException If the manager does not have
Expand All @@ -152,7 +151,7 @@ public function setService($name, $service)
* @throws InvalidServiceException If the plugin created is invalid for the
* plugin context.
*/
public function get($name, ?array $options = null)
public function get(string $id): mixed

Check failure on line 154 in src/AbstractPluginManager.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

InvalidDocblock

src/AbstractPluginManager.php:154:5: InvalidDocblock: Unrecognized template '$name' in docblock for Laminas\ServiceManager\AbstractPluginManager::get (see https://psalm.dev/008)
{
if (! $this->has($name)) {

Check failure on line 156 in src/AbstractPluginManager.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

UndefinedVariable

src/AbstractPluginManager.php:156:26: UndefinedVariable: Cannot find referenced variable $name (see https://psalm.dev/024)

Check failure on line 156 in src/AbstractPluginManager.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

MixedArgument

src/AbstractPluginManager.php:156:26: MixedArgument: Argument 1 of Laminas\ServiceManager\AbstractPluginManager::has cannot be mixed, expecting string (see https://psalm.dev/030)
if (! $this->autoAddInvokableClass || ! class_exists($name)) {
Expand All @@ -166,7 +165,7 @@ public function get($name, ?array $options = null)
$this->setFactory($name, Factory\InvokableFactory::class);
}

$instance = ! $options ? parent::get($name) : $this->build($name, $options);
$instance = parent::get($id)
$this->validate($instance);

Check failure on line 169 in src/AbstractPluginManager.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

ParseError

src/AbstractPluginManager.php:169:9: ParseError: Syntax error, unexpected T_VARIABLE on line 169 (see https://psalm.dev/173)
return $instance;
}
Expand Down
24 changes: 12 additions & 12 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,34 +219,34 @@ public function getServiceLocator()
}

/** {@inheritDoc} */
public function get($name)
public function get(string $id): mixed
{
// We start by checking if we have cached the requested service;
// this is the fastest method.
if (isset($this->services[$name])) {
return $this->services[$name];
if (isset($this->services[$id])) {
return $this->services[$id];
}

// Determine if the service should be shared.
$sharedService = $this->shared[$name] ?? $this->sharedByDefault;
$sharedService = $this->shared[$id] ?? $this->sharedByDefault;

// We achieve better performance if we can let all alias
// considerations out.
if (! $this->aliases) {
$object = $this->doCreate($name);
$object = $this->doCreate($id);

// Cache the object for later, if it is supposed to be shared.
if ($sharedService) {
$this->services[$name] = $object;
$this->services[$id] = $object;
}
return $object;
}

// We now deal with requests which may be aliases.
$resolvedName = $this->aliases[$name] ?? $name;
$resolvedName = $this->aliases[$id] ?? $id;

// Update shared service information as we checked if the alias was shared before.
if ($resolvedName !== $name) {
if ($resolvedName !== $id) {
$sharedService = $this->shared[$resolvedName] ?? $sharedService;
}

Expand All @@ -255,7 +255,7 @@ public function get($name)

// If the alias is configured as a shared service, we are done.
if ($sharedAlias) {
$this->services[$name] = $this->services[$resolvedName];
$this->services[$id] = $this->services[$resolvedName];
return $this->services[$resolvedName];
}

Expand All @@ -271,7 +271,7 @@ public function get($name)
// Also cache under the alias name; this allows sharing based on the
// service name used.
if ($sharedAlias) {
$this->services[$name] = $object;
$this->services[$id] = $object;
}

return $object;
Expand All @@ -291,10 +291,10 @@ public function build($name, ?array $options = null)
* @param string|class-string $name

Check failure on line 291 in src/ServiceManager.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

UnusedDocblockParam

src/ServiceManager.php:291:35: UnusedDocblockParam: Docblock parameter $name in docblock for Laminas\ServiceManager\ServiceManager::has does not have a counterpart in signature parameter list (see https://psalm.dev/319)
* @return bool
*/
public function has($name)
public function has(string $id): bool
{
// Check static services and factories first to speedup the most common requests.
return $this->staticServiceOrFactoryCanCreate($name) || $this->abstractFactoryCanCreate($name);
return $this->staticServiceOrFactoryCanCreate($id) || $this->abstractFactoryCanCreate($id);
}

/**
Expand Down

0 comments on commit 9a2cd5b

Please sign in to comment.