1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Retour plugin for Craft CMS |
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) 2019 nystudio107 |
|
|
|
|
10
|
|
|
*/ |
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace nystudio107\retour\gql\interfaces; |
13
|
|
|
|
14
|
|
|
use craft\gql\base\InterfaceType as BaseInterfaceType; |
15
|
|
|
|
16
|
|
|
use craft\gql\GqlEntityRegistry; |
17
|
|
|
use GraphQL\Type\Definition\InterfaceType; |
18
|
|
|
|
19
|
|
|
use GraphQL\Type\Definition\Type; |
20
|
|
|
use nystudio107\retour\gql\types\generators\RetourGenerator; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class RetourInterface |
24
|
|
|
* |
25
|
|
|
* @author nystudio107 |
|
|
|
|
26
|
|
|
* @package Retour |
|
|
|
|
27
|
|
|
* @since 3.1.26 |
|
|
|
|
28
|
|
|
*/ |
|
|
|
|
29
|
|
|
class RetourInterface extends BaseInterfaceType |
30
|
|
|
{ |
31
|
|
|
/** |
|
|
|
|
32
|
|
|
* @inheritdoc |
33
|
|
|
*/ |
|
|
|
|
34
|
|
|
public static function getTypeGenerator(): string |
35
|
|
|
{ |
36
|
|
|
return RetourGenerator::class; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
|
|
|
|
40
|
|
|
* @inheritdoc |
41
|
|
|
*/ |
|
|
|
|
42
|
|
|
public static function getType($fields = null): Type |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
if ($type = GqlEntityRegistry::getEntity(self::class)) { |
45
|
|
|
return $type; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$type = GqlEntityRegistry::createEntity(self::class, new InterfaceType([ |
|
|
|
|
49
|
|
|
'name' => static::getName(), |
50
|
|
|
'fields' => self::class . '::getFieldDefinitions', |
51
|
|
|
'description' => 'This is the interface implemented by Retour.', |
52
|
|
|
'resolveType' => function(array $value) { |
|
|
|
|
53
|
|
|
return GqlEntityRegistry::getEntity(RetourGenerator::getName()); |
54
|
|
|
}, |
55
|
|
|
])); |
|
|
|
|
56
|
|
|
RetourGenerator::generateTypes(); |
57
|
|
|
|
58
|
|
|
return $type; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
|
|
|
|
62
|
|
|
* @inheritdoc |
63
|
|
|
*/ |
|
|
|
|
64
|
|
|
public static function getName(): string |
65
|
|
|
{ |
66
|
|
|
return 'RetourInterface'; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
|
|
|
|
70
|
|
|
* @inheritdoc |
71
|
|
|
*/ |
|
|
|
|
72
|
|
|
public static function getFieldDefinitions(): array |
73
|
|
|
{ |
74
|
|
|
return array_merge(parent::getFieldDefinitions(), [ |
|
|
|
|
75
|
|
|
'id' => [ |
76
|
|
|
'name' => 'id', |
77
|
|
|
'type' => Type::int(), |
78
|
|
|
'description' => 'The id of the redirect.', |
79
|
|
|
], |
80
|
|
|
'site' => [ |
81
|
|
|
'name' => 'site', |
82
|
|
|
'type' => Type::string(), |
83
|
|
|
'description' => 'The site handle of the redirect (or null for all sites).', |
84
|
|
|
], |
85
|
|
|
'siteId' => [ |
86
|
|
|
'name' => 'siteId', |
87
|
|
|
'type' => Type::int(), |
88
|
|
|
'description' => 'The siteId of the redirect (0 or null for all sites).', |
89
|
|
|
], |
90
|
|
|
'associatedElementId' => [ |
91
|
|
|
'name' => 'associatedElementId', |
92
|
|
|
'type' => Type::int(), |
93
|
|
|
'description' => 'The id of the Element associated with this redirect (unused/vestigial).', |
94
|
|
|
], |
95
|
|
|
'enabled' => [ |
96
|
|
|
'name' => 'enabled', |
97
|
|
|
'type' => Type::boolean(), |
98
|
|
|
'description' => 'Whether the redirect is enabled or not.', |
99
|
|
|
], |
100
|
|
|
'redirectSrcUrl' => [ |
101
|
|
|
'name' => 'redirectSrcUrl', |
102
|
|
|
'type' => Type::string(), |
103
|
|
|
'description' => 'The unparsed URL pattern that Retour should match.', |
104
|
|
|
], |
105
|
|
|
'redirectSrcUrlParsed' => [ |
106
|
|
|
'name' => 'redirectSrcUrlParsed', |
107
|
|
|
'type' => Type::string(), |
108
|
|
|
'description' => 'The parsed URL pattern that Retour should match.', |
109
|
|
|
], |
110
|
|
|
'redirectSrcMatch' => [ |
111
|
|
|
'name' => 'redirectSrcMatch', |
112
|
|
|
'type' => Type::string(), |
113
|
|
|
'description' => 'Should the legacy URL be matched by path or by full URL?', |
114
|
|
|
], |
115
|
|
|
'redirectMatchType' => [ |
116
|
|
|
'name' => 'redirectMatchType', |
117
|
|
|
'type' => Type::string(), |
118
|
|
|
'description' => 'Whether an `exactmatch` or `regexmatch` should be used when matching the URL.', |
119
|
|
|
], |
120
|
|
|
'redirectDestUrl' => [ |
121
|
|
|
'name' => 'redirectDestUrl', |
122
|
|
|
'type' => Type::string(), |
123
|
|
|
'description' => 'The URL that should be redirected to.', |
124
|
|
|
], |
125
|
|
|
'redirectHttpCode' => [ |
126
|
|
|
'name' => 'redirectHttpCode', |
127
|
|
|
'type' => Type::int(), |
128
|
|
|
'description' => 'The http status code that should be used for the redirect.', |
129
|
|
|
], |
130
|
|
|
'hitCount' => [ |
131
|
|
|
'name' => 'hitCount', |
132
|
|
|
'type' => Type::int(), |
133
|
|
|
'description' => 'The number of times this redirect has been hit.', |
134
|
|
|
], |
135
|
|
|
'hitLastTime' => [ |
136
|
|
|
'name' => 'hitLastTime', |
137
|
|
|
'type' => Type::string(), |
138
|
|
|
'description' => 'A datetime string of when this redirect was last hit.', |
139
|
|
|
], |
140
|
|
|
]); |
|
|
|
|
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|