# AccessGuard

> Decides whether a request may reach the debugger.

[API reference](/docs/api/index.md) › [Debug](/docs/extensions/debug/reference/index.md) › [service](/docs/extensions/debug/reference/service/index.md) › AccessGuard

| class | `yii\debug\service\AccessGuard` |
| --- | --- |
| Source | [`src/service/AccessGuard.php`](https://github.com/yii2-extensions/debug/blob/main/src/service/AccessGuard.php#L17) |

Decides whether a request may reach the debugger.

The IP and host allowlists are evaluated first, so a denial by address never runs the application callback.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-module"></span>`$module` protected readonly constructor | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md) | Debug module read for the access configuration at call time. | `AccessGuard` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Binds access checks to the debug module. | `AccessGuard` |
| [`allows()`](#method-allows) | Returns whether the request is allowed to reach the debugger. | `AccessGuard` |

## Method details

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

```php
public function __construct(yii\debug\Module $module)
```

Binds access checks to the debug module.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$module` | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md) | Debug module read for the access configuration at call time. |

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

```php
public function allows(string $ip, yii\base\Action|null $action = null): bool
```

Returns whether the request is allowed to reach the debugger.

Checks [`Module::$allowedIPs`](/docs/extensions/debug/reference/module/index.md#property-allowedIPs) and [`Module::$allowedHosts`](/docs/extensions/debug/reference/module/index.md#property-allowedHosts), then the optional
[`Module::$checkAccessCallback`](/docs/extensions/debug/reference/module/index.md#property-checkAccessCallback), which grants access only by returning `true`. A denial is reported through
[`Yii::warning()`](/docs/api/yii/baseyii/index.md#method-warning) unless the matching `disable*RestrictionWarning` flag is set.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$ip` | `string` | Requesting IP address, or `''` when the request carries none. |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`\|null` | Action being dispatched, or `null` outside an action context. |

**Returns**

`bool`: `true` when the request may reach the debugger; `false` otherwise.