Class bedezign\yii2\audit\Audit

Inheritancebedezign\yii2\audit\Audit » yii\base\Module

Audit main module.

This module is also responsible for starting the audit process. To configure it you need to do 2 things:

  • add a module configuration entry: 'modules' => [
     'audit' => 'bedezign\yii2\audit\Audit',
    

    ] or optionally with configuration: 'modules' => [

     'audit' => [
         'class' => 'bedezign\yii2\audit\Audit',
         'ignoreActions' => ['debug/*']
    

    ]

  • If you want to auto track actions, be sure to add the module to the application bootstrapping: 'bootstrap' => ['audit'],

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$accessIps string[] IP address or list of IP addresses with access to the viewer, null for everyone (if the IP matches) An IP address can contain the wildcard * at the end so that it matches IP addresses with the same prefix. bedezign\yii2\audit\Audit
$accessRoles string[] Role or list of roles with access to the viewer, null for everyone (if the user matches) bedezign\yii2\audit\Audit
$accessUsers int User ID or list of user IDs with access to the viewer, null for everyone (if the role matches) bedezign\yii2\audit\Audit
$batchSave bool The module does batch saving of the data records by default. bedezign\yii2\audit\Audit
$compressData bool Compress extra data generated or just keep in text? For people who don't like binary data in the DB bedezign\yii2\audit\Audit
$db string Name of the component to use for database access bedezign\yii2\audit\Audit
$ignoreActions string[] Action or list of actions to ignore. bedezign\yii2\audit\Audit
$layout string|boolean The layout that should be applied for views within this module. bedezign\yii2\audit\Audit
$logTarget bedezign\yii2\audit\LogTarget bedezign\yii2\audit\Audit
$maxAge int Maximum age (in days) of the audit entries before they are truncated bedezign\yii2\audit\Audit
$panels array|bedezign\yii2\audit\components\panels\Panel[] List of panels that should be active/tracking/available during the auditing phase. bedezign\yii2\audit\Audit
$panelsMerge Everything you add in here will be merged with the basic panel configuration. bedezign\yii2\audit\Audit
$trackActions string[] Action or list of actions to track. bedezign\yii2\audit\Audit
$userFilterCallback string Will be called to translate text in the user filter into a (or more) user id's bedezign\yii2\audit\Audit
$userIdentifierCallback string The callback to use to convert a user id into an identifier (username, email, . bedezign\yii2\audit\Audit

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
normalizePanelConfiguration() Make sure the configured panels array is a uniform set of => entries. bedezign\yii2\audit\Audit
routeMatches() Verifies a route against a given list and returns whether it matches or not. bedezign\yii2\audit\Audit

Property Details

$accessIps public property

IP address or list of IP addresses with access to the viewer, null for everyone (if the IP matches) An IP address can contain the wildcard * at the end so that it matches IP addresses with the same prefix. For example, '192.168.*' matches all IP addresses in the segment '192.168.'.

public string[] $accessIps null
$accessRoles public property

Role or list of roles with access to the viewer, null for everyone (if the user matches)

public string[] $accessRoles = ['admin']
$accessUsers public property

User ID or list of user IDs with access to the viewer, null for everyone (if the role matches)

public int $accessUsers null
$batchSave public property

The module does batch saving of the data records by default. You can disable this if you are experiencing max_allowed_packet errors when logging huge data quantities. Records will be saved per piece instead of all at once

public bool $batchSave true
$compressData public property

Compress extra data generated or just keep in text? For people who don't like binary data in the DB

public bool $compressData true
$db public property

Name of the component to use for database access

public string $db 'db'
$ignoreActions public property

Action or list of actions to ignore. '' is allowed as the last character to use as wildcard (eg 'debug/').

public string[] $ignoreActions = []
$layout public property

The layout that should be applied for views within this module. This refers to a view name relative to \bedezign\yii2\audit\layoutPath. If this is not set, it means the layout value of the \bedezign\yii2\audit\module will be taken. If this is false, layout will be disabled within this module.

public string|boolean $layout 'main'
$logTarget public property
$maxAge public property

Maximum age (in days) of the audit entries before they are truncated

public int $maxAge null
$panels public property

List of panels that should be active/tracking/available during the auditing phase. If the value is a simple string, it is the identifier of an internal panel to activate (with default settings) If the entry is a '' => '|' it is either a new panel or a panel override (if you specify a core id). It is important that the key is unique, as this is the identifier used to store any data associated with the panel.

Please note:

  • If you just want to change the configuration for a core panel, use the $panelConfiguration, it will be merged into this one
  • If you add custom panels, please namespace them ("mynamespace/panelname").
public array|bedezign\yii2\audit\components\panels\Panel[] $panels = ['audit/request''audit/db''audit/log''audit/mail''audit/profiling''audit/trail''audit/javascript''audit/error''audit/extra''audit/curl']
$panelsMerge public property

This gives you an easy way to just add or modify panels/configurations without having to re-specify every panel. This only accepts regular definitions ('' => ''), but the core class will be added if needed Take a look at the module configuration for more information.

public $panelsMerge = []
$trackActions public property

Action or list of actions to track. '*' is allowed as the last character to use as wildcard.

public string[] $trackActions = ['*']
$userFilterCallback public property

Will be called to translate text in the user filter into a (or more) user id's

public string $userFilterCallback false
$userIdentifierCallback public property

The callback to use to convert a user id into an identifier (username, email, ...). Can also be html.

Method Details

__call() public method

public mixed __call ( $name, $params )
$name string
$params array
findModuleIdentifier() public static method

public static int|null|string findModuleIdentifier ( )
findPanelIdentifier() public static method

public static bool|string findPanelIdentifier ( $className )
$className string
getDb() public method

public \yii\db\Connection getDb ( )
return \yii\db\Connection

The database connection.

getEntry() public method

public bedezign\yii2\audit\models\AuditEntry|static getEntry ( $create false, $new false )
$create bool
$new bool
getPanel() public method

public null|bedezign\yii2\audit\components\panels\Panel getPanel ( $identifier )
$identifier string
throws \yii\base\InvalidConfigException
getPanelIdentifiers() public method

Returns a list of all available panel identifiers

public string[] getPanelIdentifiers ( )
getUserIdentifier() public method

public string getUserIdentifier ( $user_id )
$user_id
init() public method

public void init ( )
throws \yii\base\InvalidConfigException
loadPanels() public method

Tries to assemble the configuration for the panels that the user wants for auditing

public bedezign\yii2\audit\components\panels\Panel[] loadPanels ( $list )
$list
normalizePanelConfiguration() protected method

Make sure the configured panels array is a uniform set of => entries.

protected void normalizePanelConfiguration ( )
throws \yii\base\InvalidConfigException
onAfterRequest() public method

public void onAfterRequest ( )
onBeforeAction() public method

Called to evaluate if the current request should be logged

public void onBeforeAction ( $event )
$event \yii\base\ActionEvent
registerFunction() public method

Allows panels to register functions that can be called directly on the module

public void registerFunction ( $name, $callback )
$name string
$callback callable
registerPanel() public method

public void registerPanel ( \yii\debug\Panel $panel )
$panel \yii\debug\Panel
routeMatches() protected method

Verifies a route against a given list and returns whether it matches or not.

Entries in the list are allowed to end with a '*', which means that a substring will be used for the match instead of a full compare.

protected bool routeMatches ( $route, $list )
$route string

An application rout

$list string[]

List of routes to compare against.