Test Failed
Branch master (f4ffe3)
by Sergio
08:47 queued 04:26
created

Module.php (1 issue)

Severity
1
<?php
2
/*
3
 * @copyright Copyright (C) 2019 Sergio coderius <coderius>
4
 * @license This program is free software: the MIT License (MIT)
5
 */
6
7
namespace coderius\hitCounter;
8
9
use Yii;
10
use yii\web\GroupUrlRule;
11
use \yii\base\Application;
12
use yii\base\Model;
13
14
class Module extends \yii\base\Module
15
{
16
    /** @var string module name */
17
    public static $moduleName = 'hitCounter';
18
19
    /** @var string|null */
20
    public $userIdentityClass = null;
21
22
    public $controllerNamespace = 'coderius\hitCounter\controllers';
23
24
    public function init()
25
    {
26
        parent::init();
27
28
        \Yii::configure($this, require __DIR__ . '/config/main.php');
29
        
30
        //иначе ломает консольные комманды
31
        if (Yii::$app instanceof yii\web\Application) {
32
            if ($this->userIdentityClass === null) {
33
                $this->userIdentityClass = \Yii::$app->getUser()->identityClass;
34
            }
35
        }
36
        
37
//        var_dump(Module::t('messages', 'No comments yet.'));die;
38
    }
39
40
    /**
41
     * Adds UrlManager rules.
42
     *
43
     * @param Application $app the application currently running
44
     */
45
    public function addUrlManagerRules(Application $app)
46
    {
47
        $app->urlManager->addRules([new GroupUrlRule([
48
            'prefix' => $this->id,
49
            'rules' => require __DIR__ . '/config/_routes.php',
50
        ])], true);
51
52
        // var_dump(\Yii::$app->urlManager);
53
        // var_dump($this->id.'s');
54
        // die;
55
    }
56
57
    /**
58
     * @return static
59
     */
60
    public static function selfInstance()
61
    {
62
        return \Yii::$app->getModule(static::$moduleName);
63
    }
64
65
    /**
66
     * Get default model classes.
67
     */
68
    public function getDefaultModels()
69
    {
70
        return [
71
            'HitCounter' => \coderius\hitCounter\models\HitCounterModel::className(),
0 ignored issues
show
Deprecated Code introduced by
The function yii\base\BaseObject::className() has been deprecated: since 2.0.14. On PHP >=5.5, use `::class` instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

71
            'HitCounter' => /** @scrutinizer ignore-deprecated */ \coderius\hitCounter\models\HitCounterModel::className(),

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
72
        ];
73
    }
74
75
    public function model(Model $name)
76
    {
77
        $models = $this->getDefaultModels();
78
        if (array_key_exists($name, $models)) {
79
            return $models[$name];
80
        }
81
82
        return false;
83
    }
84
}
85