# Manager

> Server-side Yii adapter registered as the inertia application component.

[API reference](/docs/api/index.md) › [Inertia](/docs/extensions/inertia/reference/index.md) › Manager

| final class | `yii\inertia\Manager` |
| --- | --- |
| Extends | [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Source | [`src/Manager.php`](https://github.com/yii2-extensions/inertia/blob/main/src/Manager.php#L30) |

Server-side Yii adapter registered as the `inertia` application component.

Adapts Yii requests, application state, views, sessions, and responses to the framework-agnostic protocol core.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-clearHistory"></span>`$clearHistory` | `bool` | Whether rendered pages clear the client-side history. Default: `false`. | `Manager` |
| <span id="property-encryptHistory"></span>`$encryptHistory` | `bool` | Whether rendered pages encrypt their client-side history state. Default: `false`. | `Manager` |
| <span id="property-errorFlashKey"></span>`$errorFlashKey` | `string` | Session flash key exposed as `props.errors` in every page payload. Default: `'errors'`. | `Manager` |
| [`$eventDispatcher`](#property-eventDispatcher) | `Psr\EventDispatcher\EventDispatcherInterface\|null` | PSR-14 dispatcher the default protocol emits `ProtocolResultCreated` through, or `null` to emit no events. Default: `null`. | `Manager` |
| <span id="property-exposeSharedProps"></span>`$exposeSharedProps` | `bool` | Whether rendered pages expose shared-prop metadata. Default: `true`. | `Manager` |
| <span id="property-id"></span>`$id` | `string` | Root element DOM `id` used by the default root view. Default: `'app'`. | `Manager` |
| <span id="property-pageObserver"></span>`$pageObserver` | `PHPForge\Inertia\ResolvedPageObserver\|null` | Optional portable observer notified after page resolution and before response serialization. Default: `null`. | `Manager` |
| <span id="property-preserveFragment"></span>`$preserveFragment` | `bool` | Whether rendered pages preserve the URL fragment. Default: `false`. | `Manager` |
| [`$protocol`](#property-protocol) | `PHPForge\Inertia\Protocol\|null` | Protocol service, or `null` to build the default one with [`$eventDispatcher`](/docs/extensions/inertia/reference/manager/index.md#property-eventDispatcher). Default: `null`. | `Manager` |
| <span id="property-rootView"></span>`$rootView` | `string` | Root view file rendered for the initial HTML response. Default: `'@inertia/views/app.php'`. | `Manager` |
| <span id="property-shared"></span>`$shared` | `array<string, mixed>` | Shared props applied to every rendered page in the current request. Default: `[]`. | `Manager` |
| <span id="property-version"></span>`$version` | [`Closure`](https://www.php.net/manual/en/class.closure.php)`(): int\|string\|null\|`[`Closure`](https://www.php.net/manual/en/class.closure.php)`(`[`yii\web\Request`](/docs/api/yii/web/request/index.md)`): int\|string\|null\|int\|string\|null` | Asset version used for client-side mismatch detection through the page `version` field. Default: `null`. | `Manager` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`flushShared()`](#method-flushShared) | Removes all shared props. | `Manager` |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`getShared()`](#method-getShared) | Returns all shared props or a nested value using dot notation. | `Manager` |
| [`getVersion()`](#method-getVersion) | Resolves the configured asset version. | `Manager` |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`isInertiaRequest()`](#method-isInertiaRequest) | Returns whether a request carries the Inertia request marker. | `Manager` |
| [`location()`](#method-location) | Returns an Inertia location response or a standard redirect response. | `Manager` |
| [`normalizeResponse()`](#method-normalizeResponse) | Normalizes a Yii response immediately before it is sent to an Inertia client. | `Manager` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`render()`](#method-render) | Renders an Inertia page through the framework-agnostic protocol core. | `Manager` |
| [`share()`](#method-share) | Registers props shared with subsequent page responses in the current request. | `Manager` |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |

## Property details

### $eventDispatcher <span id="property-eventDispatcher"></span>

```php
public Psr\EventDispatcher\EventDispatcherInterface|null $eventDispatcher = null
```

PSR-14 dispatcher the default protocol emits `ProtocolResultCreated` through, or `null` to emit no events.

Ignored when [`$protocol`](/docs/extensions/inertia/reference/manager/index.md#property-protocol) is configured. A debugger registers its collector here.

### $protocol <span id="property-protocol"></span>

```php
public PHPForge\Inertia\Protocol|null $protocol = null
```

Protocol service, or `null` to build the default one with [`$eventDispatcher`](/docs/extensions/inertia/reference/manager/index.md#property-eventDispatcher).

Configure this property to inject a custom core clock for deterministic tests.

## Method details

### flushShared() <span id="method-flushShared"></span>

```php
public function flushShared(): void
```

Removes all shared props.

### getShared() <span id="method-getShared"></span>

```php
public function getShared(string|null $key = null, mixed $default = null): mixed
```

Returns all shared props or a nested value using dot notation.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|null` | Dot-notated key to retrieve, or `null` to return every shared prop. |
| `$default` | `mixed` | Value returned when `$key` does not exist. |

**Returns**

`mixed`: Shared value at `$key`, or `$default` when the key does not exist.

### getVersion() <span id="method-getVersion"></span>

```php
public function getVersion(): int|string
```

Resolves the configured asset version.

**Returns**

`int|string`: Resolved version, or an empty `string` when no version is configured.

### isInertiaRequest() <span id="method-isInertiaRequest"></span>

```php
public function isInertiaRequest(yii\web\Request|null $request = null): bool
```

Returns whether a request carries the Inertia request marker.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$request` | [`yii\web\Request`](/docs/api/yii/web/request/index.md)`\|null` | Request to inspect, or `null` to use the current application request. |

**Returns**

`bool`: `true` when the request is Inertia-driven; otherwise, `false`.

### location() <span id="method-location"></span>

```php
public function location(array<array-key, mixed>|string $url): yii\web\Response
```

Returns an Inertia location response or a standard redirect response.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$url` | `array<array-key, mixed>\|string` | Destination URL or route array accepted by `Url::to()`. |

**Returns**

[`yii\web\Response`](/docs/api/yii/web/response/index.md): Yii response containing the protocol location or redirect result.

**Throws**

- [`yii\web\BadRequestHttpException`](/docs/api/yii/web/badrequesthttpexception/index.md): if the request context is invalid.

### normalizeResponse() <span id="method-normalizeResponse"></span>

```php
public function normalizeResponse(yii\web\Response $response): void
```

Normalizes a Yii response immediately before it is sent to an Inertia client.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$response` | [`yii\web\Response`](/docs/api/yii/web/response/index.md) | Outgoing Yii response to normalize. |

**Throws**

- [`yii\web\BadRequestHttpException`](/docs/api/yii/web/badrequesthttpexception/index.md): if a redirect request context is invalid.

### render() <span id="method-render"></span>

```php
public function render(string $component, array<string, mixed> $props = [], array<string, mixed> $viewData = []): yii\web\Response
```

Renders an Inertia page through the framework-agnostic protocol core.

Returns a JSON page payload for Inertia requests or the initial HTML document for standard browser requests.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$component` | `string` | Client-side component name. |
| `$props` | `array<string, mixed>` | Page-specific props. |
| `$viewData` | `array<string, mixed>` | Additional data available to the initial root view. |

**Returns**

[`yii\web\Response`](/docs/api/yii/web/response/index.md): Yii response containing the initial HTML document or Inertia JSON page.

**Throws**

- [`yii\web\BadRequestHttpException`](/docs/api/yii/web/badrequesthttpexception/index.md): if the request context is invalid.

### share() <span id="method-share"></span>

```php
public function share(array<string, mixed>|string $key, mixed $value = null): void
```

Registers props shared with subsequent page responses in the current request.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `array<string, mixed>\|string` | Shared values or a dot-notated prop key. |
| `$value` | `mixed` | Value registered when `$key` is a string. |