1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SocialiteProviders\Generators\Contexts; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
|
7
|
|
|
class Stub |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Create a new stub instance. |
11
|
|
|
* |
12
|
|
|
* @param $properties |
13
|
|
|
*/ |
14
|
|
|
public function __construct($properties) |
15
|
|
|
{ |
16
|
|
|
$this->properties = new Collection($properties); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Author name. |
21
|
|
|
* |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
public function authorName() |
25
|
|
|
{ |
26
|
|
|
return $this->properties->get('authorName'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Author email. |
31
|
|
|
* |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
public function authorMail() |
35
|
|
|
{ |
36
|
|
|
return $this->properties->get('authorMail'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Name in lowercase. |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function nameLowerCase() |
45
|
|
|
{ |
46
|
|
|
return strtolower($this->properties->get('name')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Name in StudlyCase. |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function nameStudlyCase() |
55
|
|
|
{ |
56
|
|
|
return studly_case($this->properties->get('name')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Name in UPPERCASE. |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function nameUpperCase() |
65
|
|
|
{ |
66
|
|
|
return strtoupper($this->properties->get('name')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* OAuth Version. |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function oauthVersion() |
75
|
|
|
{ |
76
|
|
|
return ($this->properties->get('oauthVersion') === 'oauth1') ? 'OAuth1' : 'OAuth2'; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Scopes. |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function scopes() |
85
|
|
|
{ |
86
|
|
|
$scopes = $this->properties->get('scopes'); |
87
|
|
|
|
88
|
|
|
if (str_contains($scopes, ',')) { |
89
|
|
|
$scopes = explode(',', $this->properties->get('scopes')); |
90
|
|
|
|
91
|
|
|
return implode("', '", $scopes); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $scopes; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Request Token Url. |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function requestTokenUrl() |
103
|
|
|
{ |
104
|
|
|
return $this->properties->get('requestTokenUrl'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Authorize Url. |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function authorizeUrl() |
113
|
|
|
{ |
114
|
|
|
return $this->properties->get('authorizeUrl'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Access Token Url. |
119
|
|
|
* |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function accessTokenUrl() |
123
|
|
|
{ |
124
|
|
|
return $this->properties->get('accessTokenUrl'); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* User Info Url. |
129
|
|
|
* |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
public function userDetailsUrl() |
133
|
|
|
{ |
134
|
|
|
return $this->properties->get('userDetailsUrl'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
|
public function toArray() |
141
|
|
|
{ |
142
|
|
|
return [ |
143
|
|
|
'authorName' => $this->authorName(), |
144
|
|
|
'authorMail' => $this->authorMail(), |
145
|
|
|
'nameLowerCase' => $this->nameLowerCase(), |
146
|
|
|
'nameStudlyCase' => $this->nameStudlyCase(), |
147
|
|
|
'nameUpperCase' => $this->nameUpperCase(), |
148
|
|
|
'oauthVersion' => $this->oauthVersion(), |
149
|
|
|
'scopes' => $this->scopes(), |
150
|
|
|
'requestTokenUrl' => $this->requestTokenUrl(), |
151
|
|
|
'authorizeUrl' => $this->authorizeUrl(), |
152
|
|
|
'accessTokenUrl' => $this->accessTokenUrl(), |
153
|
|
|
'userDetailsUrl' => $this->userDetailsUrl(), |
154
|
|
|
]; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: