<?php
    namespace common\modules\comment;

    /**
     * Class Module
     * @package common\modules\comment
     */
    class Module extends \yii\base\Module
    {

        /**
         * @var string Module name
         */
        public static $moduleName = 'artbox_comment';

        /**
         * @var bool Wheather to use Rbac system
         * @link http://www.yiiframework.com/doc-2.0/guide-security-authorization.html#rbac
         * @see \yii\rbac\ManagerInterface
         */
        public $useRbac = false;

        /**
         * Array of RBAC rules and permissions that can be used by install command.
         *
         * Currently supports associative array, of such view:
         *
         * <code>
         * [
         *  'rules' => [
         *      \full\namapaced\ClassName,
         *      \another\one\ClassName,
         *  ],
         *  'permissions' => [
         *      [
         *          'name' => stringName,
         *          'description' => descriptionText,
         *          'ruleName' => (new \full\namespaced\ClassName())->name (optional)
         *      ],
         *      [
         *          'name' => stringName2,
         *          'description' => descriptionText2,
         *          'ruleName' => (new \another\one\ClassName())->name (optional)
         *      ],
         *  ]
         * ]
         * </code>
         *
         * @var array
         * @see \common\modules\comment\commands\RbacController
         */
        public $rbac = [];

        /**
         * @var \yii\db\Connection Connection to the db
         */
        public $db = null;

        /**
         * @inheritdoc
         */
        public function init()
        {
            parent::init();
            if(\Yii::$app instanceof \yii\console\Application) {
                $this->controllerNamespace = 'common\modules\comment\commands';
            }
            if($this->db === null) {
                $this->db = \Yii::$app->db;
            } elseif(!$this->db instanceof \yii\db\Connection) {
                throw new \yii\base\InvalidConfigException('Конфиг db обязан наследоваться от'.\yii\db\Connection::className());
            }
        }
    }