-
Notifications
You must be signed in to change notification settings - Fork 1
/
swaggerUiBehavior.php
67 lines (65 loc) · 2.1 KB
/
swaggerUiBehavior.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace yiiisoft\yii2SwaggerUi;
use developit\slug\helpers\Inflector;
use Yii;
use yii\base\InvalidConfigException;
use yii\behaviors\SluggableBehavior;
use yii\db\BaseActiveRecord;
use yii\helpers\ArrayHelper;
use yii\validators\UniqueValidator;
/**
* PesianSluggableBehavior automatically fills the specified attribute with a value that can be used a slug in a URL.
*
* To use SluggableBehavior, insert the following code to your ActiveRecord class:
*
* ```php
* use developit\slug\PesianSluggableBehavior;
*
* public function behaviors()
* {
* return [
* [
* 'class' => PesianSluggableBehavior::className(),
* 'attribute' => 'title',
* // 'slugAttribute' => 'slug',
* ],
* ];
* }
* ```
*
* By default, SluggableBehavior will fill the `slug` attribute with a value that can be used a slug in a URL
* when the associated AR object is being validated.
*
* Because attribute values will be set automatically by this behavior, they are usually not user input and should therefore
* not be validated, i.e. the `slug` attribute should not appear in the [[\yii\base\Model::rules()|rules()]] method of the model.
*
* If your attribute name is different, you may configure the [[slugAttribute]] property like the following:
*
* ```php
* public function behaviors()
* {
* return [
* [
* 'class' => PesianSluggableBehavior::className(),
* 'slugAttribute' => 'alias',
* ],
* ];
* }
* ```
*
*/
class swaggerUiBehavior extends SluggableBehavior
{
/**
* This method is called by [[getValue]] to generate the slug.
* You may override it to customize slug generation.
* The default implementation calls [[\yii\helpers\Inflector::slug()]] on the input strings
* concatenated by dashes (`-`).
* @param array $slugParts an array of strings that should be concatenated and converted to generate the slug value.
* @return string the conversion result.
*/
protected function generateSlug($slugParts)
{
return Inflector::slug(implode('-', $slugParts));
}
}