ServiceMap
API reference › PHPStan › ServiceMap
Maps and normalizes service and component definitions from Yii Application configuration for static analysis.
Loads, validates, and processes configuration files, exposing lookup methods to resolve class names and configuration
arrays by identifier. Registers the class of every definition form Yii accepts when it can be determined statically:
class name strings, arrays with a class or __class key, closures returning a single class, and object instances.
Definitions whose class can’t be determined, such as untyped closures, are skipped and flagged as unresolved, so the
lookups return null and the consumers type them as object.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a new instance of the ServiceMap class. | ServiceMap |
getApplicationType() | Retrieves the fully qualified class name of the application type for PHPStan analysis. | ServiceMap |
getBehaviorsByClassName() | Retrieves the behavior class names associated with the specified class. | ServiceMap |
getComponentClassById() | Retrieves the fully qualified class name of a Yii Application component by its identifier. | ServiceMap |
getComponentDefinitionById() | Retrieves the component definition array by its identifier. | ServiceMap |
getParams() | Retrieves the application params map for PHPStan type inference. | ServiceMap |
getServiceById() | Retrieves the fully qualified class name of a Yii Service by its identifier. | ServiceMap |
isComponentWithoutClass() | Returns whether a component is defined by an array without a class or __class key. | ServiceMap |
isUnresolvedComponent() | Returns whether a component is defined in the configuration but its class can’t be determined. | ServiceMap |
isUnresolvedService() | Returns whether a container service is defined in the configuration but its class can’t be determined. | ServiceMap |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(string $configPath = '')Creates a new instance of the ServiceMap class.
Parameters
| Parameter | Type | Description |
|---|---|---|
$configPath | string | Path to the Yii Application configuration file (default: ''). If provided, the configuration file must exist and be valid. If empty or not provided, operates with empty service/component maps. |
Throws
yii\base\InvalidArgumentException: if one or more arguments are invalid, of incorrect type or format.RuntimeException: if a runtime error prevents the operation from completing successfully.
getApplicationType()
Section titled “getApplicationType() ”public function getApplicationType(): stringRetrieves the fully qualified class name of the application type for PHPStan analysis.
Returns
string: Fully qualified class name of the application type.
getBehaviorsByClassName()
Section titled “getBehaviorsByClassName() ”public function getBehaviorsByClassName(string $class): string[]Retrieves the behavior class names associated with the specified class.
Looks up the internal behavior definitions map for the provided fully qualified class name and return an array of associated behavior class names.
Parameters
| Parameter | Type | Description |
|---|---|---|
$class | string | Fully qualified class name for which to retrieve behavior class names. |
Returns
string[]: Array of behavior class names, or an empty array if none are defined.
getComponentClassById()
Section titled “getComponentClassById() ”public function getComponentClassById(string $id): string|nullRetrieves the fully qualified class name of a Yii Application component by its identifier.
Looks up the component class name registered under the specified component ID in the internal component map.
Parameters
| Parameter | Type | Description |
|---|---|---|
$id | string | Component identifier to look up in the component map. |
Returns
string|null: Fully qualified class name of the component, or null if not found.
getComponentDefinitionById()
Section titled “getComponentDefinitionById() ”public function getComponentDefinitionById(string $id): arrayRetrieves the component definition array by its identifier.
Looks up the component definition registered under the specified component ID in the internal component definitions map.
Parameters
| Parameter | Type | Description |
|---|---|---|
$id | string | Component identifier to look up in the component definitions map. |
Returns
array: Component definition array with configuration options, or empty array if not found.
getParams()
Section titled “getParams() ”public function getParams(): array<array-key, mixed>Retrieves the application params map for PHPStan type inference.
Returns the params key-value pairs extracted from the Yii Application configuration file, enabling static
analysis tools to infer precise array shape types for Yii::$app->params access.
Returns
array<array-key, mixed>: Params key-value pairs from configuration.
getServiceById()
Section titled “getServiceById() ”public function getServiceById(string $id): string|nullRetrieves the fully qualified class name of a Yii Service by its identifier.
Looks up the service class name registered under the specified service ID in the internal service map.
Parameters
| Parameter | Type | Description |
|---|---|---|
$id | string | Service identifier to look up in the service map. |
Returns
string|null: Fully qualified class name of the service, or null if not found.
isComponentWithoutClass()
Section titled “isComponentWithoutClass() ”public function isComponentWithoutClass(string $id): boolReturns whether a component is defined by an array without a class or __class key.
Application::preInit() completes such a definition with the class of the matching core
component, so the type the application class declares for the component still applies. Such a component is also
unresolved.
Parameters
| Parameter | Type | Description |
|---|---|---|
$id | string | Component identifier to look up. |
Returns
bool: true if the component is defined by an array without a class key; false otherwise.
isUnresolvedComponent()
Section titled “isUnresolvedComponent() ”public function isUnresolvedComponent(string $id): boolReturns whether a component is defined in the configuration but its class can’t be determined.
Covers closures without a single class return type, array callables, arrays without a class key, and classes
naming a container ID on a cycle or a container ID whose class can’t be determined. Components that are absent or
set to null aren’t unresolved, and an Instance reference is the component itself, since
ServiceLocator::get() returns it without resolving it.
Parameters
| Parameter | Type | Description |
|---|---|---|
$id | string | Component identifier to look up. |
Returns
bool: true if the component is defined with an unknown class; false otherwise.
isUnresolvedService()
Section titled “isUnresolvedService() ”public function isUnresolvedService(string $id): boolReturns whether a container service is defined in the configuration but its class can’t be determined.
Covers factories without a single class return type, array callables, arrays without a class key under an ID
that doesn’t name an instantiable class, and definitions, Instance references included, naming a container
ID on a cycle or a container ID whose class can’t be determined. Services that are absent, or defined empty,
aren’t unresolved, since Yii then uses the ID itself as the class.
Parameters
| Parameter | Type | Description |
|---|---|---|
$id | string | Service identifier to look up. |
Returns
bool: true if the service is defined with an unknown class; false otherwise.