Passed
Push — v3 ( 2b006a...43f239 )
by Andrew
33:34 queued 16:32
created

src/models/Settings.php (1 issue)

1
<?php
2
/**
3
 * Retour plugin for Craft CMS 3.x
4
 *
5
 * Retour allows you to intelligently redirect legacy URLs, so that you don't
6
 * lose SEO value when rebuilding & restructuring a website
7
 *
8
 * @link      https://nystudio107.com/
9
 * @copyright Copyright (c) 2018 nystudio107
10
 */
11
12
namespace nystudio107\retour\models;
13
14
use nystudio107\retour\Retour;
15
16
use craft\base\Model;
17
use craft\behaviors\EnvAttributeParserBehavior;
18
use craft\validators\ArrayValidator;
19
20
use yii\behaviors\AttributeTypecastBehavior;
21
22
/**
23
 * @author    nystudio107
24
 * @package   Retour
25
 * @since     3.0.0
26
 */
27
class Settings extends Model
28
{
29
    // Public Properties
30
    // =========================================================================
31
32
    /**
33
     * @var string The public-facing name of the plugin
34
     */
35
    public $pluginName = 'Retour';
36
37
    /**
38
     * @var bool Controls whether Retour automatically creates static redirects
39
     *      when an entry's URI changes.
40
     */
41
    public $createUriChangeRedirects = true;
42
43
    /**
44
     * @var string Should the legacy URL be matched by path (e.g.
45
     *      `/new-recipes/`) or by full URL (e.g.:
46
     *      `http://example.com/de/new-recipes/`)?
47
     */
48
    public $uriChangeRedirectSrcMatch = 'pathonly';
49
50
    /**
51
     * @var bool Should the query string be stripped from all 404 URLs before
52
     *      their evaluation?
53
     */
54
    public $alwaysStripQueryString = false;
55
56
    /**
57
     * @var bool Should the query string be preserved and passed along to the
58
     *      redirected URL?
59
     */
60
    public $preserveQueryString = false;
61
62
    /**
63
     * @var bool Should the anonymous ip address of the client causing a 404 be
64
     *      recorded?
65
     */
66
    public $recordRemoteIp = true;
67
68
    /**
69
     * @var int How many static redirects to display in the Control Panel
70
     */
71
    public $staticRedirectDisplayLimit = 100;
72
73
    /**
74
     * @var int How many dynamic redirects to display in the Control Panel
75
     */
76
    public $dynamicRedirectDisplayLimit = 100;
77
78
    /**
79
     * @var bool Should the query string be stripped from the saved statistics
80
     *      source URLs?
81
     */
82
    public $stripQueryStringFromStats = true;
83
84
    /**
85
     * @var int How many stats should be stored
86
     */
87
    public $statsStoredLimit = 1000;
88
89
    /**
90
     * @var int Dashboard data live refresh interval
91
     */
92
    public $refreshIntervalSecs = 5;
93
94
    /**
95
     * @var bool Whether the Statistics should be trimmed after each new
96
     *      statistic is recorded
97
     */
98
    public $automaticallyTrimStatistics = true;
99
100
    /**
101
     * @var int The number of milliseconds required between trimming of
102
     *      statistics
103
     */
104
    public $statisticsRateLimitMs = 3600000;
105
106
    /**
107
     * @var int How many stats to display in the Control Panel
108
     */
109
    public $statsDisplayLimit = 1000;
110
111
    /**
112
     * @var bool Determines whether the Retour API endpoint should be enabled for anonymous frontend access
113
     */
114
    public $enableApiEndpoint = false;
115
116
    /**
117
     * @var array [Regular expressions](https://regexr.com/) to match URLs to
118
     *      exclude from Retour
119
     */
120
    public $excludePatterns = [
121
    ];
122
123
    /**
124
     * @var array Additional headers to add to redirected requests
125
     */
126
    public $additionalHeaders = [
127
    ];
128
129
    /**
130
     * @var string The delimiter between data column values for importing CSV files (normally `,`)
131
     */
132
    public $csvColumnDelimiter = ',';
133
134
    // Public Methods
135
    // =========================================================================
136
137
    /**
138
     * @inheritdoc
139
     */
140
    public function rules()
141
    {
142
        return [
143
            ['pluginName', 'string'],
144
            ['pluginName', 'default', 'value' => 'Retour'],
145
            [
146
                [
147
                    'createUriChangeRedirects',
148
                    'alwaysStripQueryString',
149
                    'preserveQueryString',
150
                    'stripQueryStringFromStats',
151
                    'recordRemoteIp',
152
                ],
153
                'boolean',
154
            ],
155
            ['uriChangeRedirectSrcMatch', 'default', 'value' => 'pathonly'],
156
            ['uriChangeRedirectSrcMatch', 'string'],
157
            ['uriChangeRedirectSrcMatch', 'in', 'range' => [
158
                'pathonly',
159
                'fullurl'
160
            ]],
161
            ['staticRedirectDisplayLimit', 'integer', 'min' => 1],
162
            ['staticRedirectDisplayLimit', 'default', 'value' => 100],
163
            ['dynamicRedirectDisplayLimit', 'integer', 'min' => 1],
164
            ['dynamicRedirectDisplayLimit', 'default', 'value' => 100],
165
            ['statsStoredLimit', 'integer', 'min' => 1],
166
            ['statsStoredLimit', 'default', 'value' => 1000],
167
            ['refreshIntervalSecs', 'integer', 'min' => 0],
168
            ['refreshIntervalSecs', 'default', 'value' => 3],
169
            ['statsDisplayLimit', 'integer', 'min' => 1],
170
            ['statsDisplayLimit', 'default', 'value' => 1000],
171
            [
172
                [
173
                    'excludePatterns',
174
                    'additionalHeaders',
175
                ],
176
                ArrayValidator::class
177
            ],
178
        ];
179
    }
180
181
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
182
     * @return array
183
     */
184
    public function behaviors()
185
    {
186
        $craft31Behaviors = [];
187
        if (Retour::$craft31) {
188
            $craft31Behaviors = [
189
                'parser' => [
190
                    'class' => EnvAttributeParserBehavior::class,
191
                    'attributes' => [
192
                    ],
193
                ],
194
            ];
195
        }
196
197
        return array_merge($craft31Behaviors, [
198
            'typecast' => [
199
                'class' => AttributeTypecastBehavior::class,
200
                // 'attributeTypes' will be composed automatically according to `rules()`
201
            ],
202
        ]);
203
    }
204
}
205