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