/** * current - get current active Auth instance * @static * @return Auth|null */ public static function current() { if (static::$_current === null) { if ($token = AuthToken::current()) { // // TODO: (known bug) // When accessing $token->auth inside an observer other than `auth`, // the table name of the query is being equals to the observer itself. // $token->auth(); // this resets the target querying table name static::$_current = $token->auth; } } return static::$_current; }
public function init() { static::$_current = $this; parent::init(); // Allow the users to specify a simple string if there is only 1 entry $this->trackActions = ArrayHelper::toArray($this->trackActions); $this->ignoreActions = ArrayHelper::toArray($this->ignoreActions); if ($this->accessRoles) { $this->accessRoles = ArrayHelper::toArray($this->accessRoles); } if ($this->accessUsers) { $this->accessUsers = ArrayHelper::toArray($this->accessUsers); } // Before action triggers a new audit entry \Yii::$app->on(Application::EVENT_BEFORE_ACTION, [$this, 'onApplicationAction']); // After request finalizes the audit entry and optionally does truncating \Yii::$app->on(Application::EVENT_AFTER_REQUEST, [$this, 'onAfterRequest']); // Register translation $app = \Yii::$app; if ($app->has('i18n')) { $app->i18n->translations['audit'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'sourceLanguage' => 'en', 'basePath' => '@bedezign/yii2/audit/messages']; } }
/** * Unregisters the given view-mode, or all of them if first parameter is null. * * @param string|null $slug View mode's slug * @return void */ public static function remove($slug = null) { if ($slug === null) { static::$_current = null; static::$_modes = []; } else { if (isset(static::$_modes[$slug])) { unset(static::$_modes[$slug]); } } }
/** * Creates, modifies or switches to an existing environment configuration. To create a new * configuration, or to update an existing configuration, pass an environment name and an array * that defines its configuration: * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testModifyEnvironmentConfig(1-1) }}} * * You can then add to an existing configuration by calling the `set()` method again with the * same environment name: * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testModifyEnvironmentConfig(6-6) }}} * * The settings for the environment will then be the aggregate of all `set()` calls: * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testModifyEnvironmentConfig(7-7) }}} * * The `set()` method can also be called to manually set which environment to operate in: * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testSetAndGetCurrentEnvironment(5-5) }}} * * Finally, `set()` can accept a `Request` object, or the `$_SERVER` or `$_ENV` superglobals, to * automatically detect the correct environment. * * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testEnvironmentDetection(9-10) }}} * * For more information on defining custom rules to automatically detect your application's * environment, see the documentation for `Environment::is()`. * * @see lithium\http\Request * @see lithium\core\Environment::is() * @param mixed $env The name of the environment you wish to create, update or switch to * (string), or a `Request` object or `$_SERVER` / `$_ENV` array used to detect * (and switch to) the application's current environment. * @param array $config If creating or updating a configuration, accepts an array of settings. * If the environment name specified in `$env` already exists, the values in * `$config` will be recursively merged with any pre-existing settings. * @return array If creating or updating a configuration, returns an array of the environment's * settings. If updating an existing configuration, this will be the newly-applied * configuration merged with the pre-existing values. If setting the environment * itself (i.e. `$config` is unspecified), returns `null`. */ public static function set($env, $config = null) { if (is_null($config)) { switch (true) { case is_object($env) || is_array($env): static::$_current = static::_detector()->__invoke($env); break; case isset(static::$_configurations[$env]): static::$_current = $env; break; } return; } $env = $env === true ? static::$_current : $env; $base = isset(static::$_configurations[$env]) ? static::$_configurations[$env] : array(); return static::$_configurations[$env] = Set::merge($base, $config); }
/** * Creates, modifies or switches to an existing environment configuration. To create a new * configuration, or to update an existing configuration, pass an environment name and an array * that defines its configuration: * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testModifyEnvironmentConfig(1-1) }}} * * You can then add to an existing configuration by calling the `set()` method again with the * same environment name: * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testModifyEnvironmentConfig(6-6) }}} * * The settings for the environment will then be the aggregate of all `set()` calls: * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testModifyEnvironmentConfig(7-7) }}} * * By passing an array to `$env`, you can assign the same configuration to multiple * environments: * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testSetMultipleEnvironments(5-7) }}} * * The `set()` method can also be called to manually set which environment to operate in: * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testSetAndGetCurrentEnvironment(5-5) }}} * * Finally, `set()` can accept a `Request` object, to automatically detect the correct * environment. * * {{{ embed:lithium\tests\cases\core\EnvironmentTest::testEnvironmentDetection(9-10) }}} * * For more information on defining custom rules to automatically detect your application's * environment, see the documentation for `Environment::is()`. * * @see lithium\action\Request * @see lithium\core\Environment::is() * @param mixed $env The name(s) of the environment(s) you wish to create, update or switch to * (string/array), or a `Request` object or `$_SERVER` / `$_ENV` array used to * detect (and switch to) the application's current environment. * @param array $config If creating or updating a configuration, accepts an array of settings. * If the environment name specified in `$env` already exists, the values in * `$config` will be recursively merged with any pre-existing settings. * @return array If creating or updating a configuration, returns an array of the environment's * settings. If updating an existing configuration, this will be the newly-applied * configuration merged with the pre-existing values. If setting the environment * itself (i.e. `$config` is unspecified), returns `null`. */ public static function set($env, $config = null) { if ($config === null) { if (is_object($env) || is_array($env)) { static::$_current = static::_detector()->__invoke($env); } elseif (isset(static::$_configurations[$env])) { static::$_current = $env; } return; } if (is_array($env)) { foreach ($env as $name) { static::set($name, $config); } return; } $env = $env === true ? static::$_current : $env; $base = isset(static::$_configurations[$env]) ? static::$_configurations[$env] : array(); return static::$_configurations[$env] = Set::merge($base, $config); }
/** * @event register pages ( menus ) */ public static function registerPages() { static::$_current = static::_registerPages(static::$_admins); // register simwp styles only when registered section found // or a page that's handled by Simwp's auto-rendering feature static::_registerStyles(static::$_current); }
public static function setCurrent($auth_token) { static::$_current = $auth_token; }
/** * Returns the current module instance. * Since we don't know how the module was linked into the application, this function allows us to retrieve * the instance without that information. As soon as an instance was initialized, it is linked. * @return static */ public static function current() { if (!static::$_current) { static::$_current = Yii::$app->getModule('audit'); } return static::$_current; }
public static function set($environment) { static::$_current = $environment; }