@@ -24,245 +24,245 @@ |
||
24 | 24 | */ |
25 | 25 | class Hybridauth |
26 | 26 | { |
27 | - /** |
|
28 | - * Hybridauth config. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $config; |
|
33 | - |
|
34 | - /** |
|
35 | - * Storage. |
|
36 | - * |
|
37 | - * @var StorageInterface |
|
38 | - */ |
|
39 | - protected $storage; |
|
40 | - |
|
41 | - /** |
|
42 | - * HttpClient. |
|
43 | - * |
|
44 | - * @var HttpClientInterface |
|
45 | - */ |
|
46 | - protected $httpClient; |
|
47 | - |
|
48 | - /** |
|
49 | - * Logger. |
|
50 | - * |
|
51 | - * @var LoggerInterface |
|
52 | - */ |
|
53 | - protected $logger; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param array|string $config Array with configuration or Path to PHP file that will return array |
|
57 | - * @param HttpClientInterface $httpClient |
|
58 | - * @param StorageInterface $storage |
|
59 | - * @param LoggerInterface $logger |
|
60 | - * |
|
61 | - * @throws InvalidArgumentException |
|
62 | - */ |
|
63 | - public function __construct( |
|
64 | - $config, |
|
65 | - HttpClientInterface $httpClient = null, |
|
66 | - StorageInterface $storage = null, |
|
67 | - LoggerInterface $logger = null |
|
68 | - ) { |
|
69 | - if (is_string($config) && file_exists($config)) { |
|
70 | - $config = include $config; |
|
71 | - } elseif (!is_array($config)) { |
|
72 | - throw new InvalidArgumentException('Hybridauth config does not exist on the given path.'); |
|
73 | - } |
|
74 | - |
|
75 | - $this->config = $config + [ |
|
76 | - 'debug_mode' => Logger::NONE, |
|
77 | - 'debug_file' => '', |
|
78 | - 'curl_options' => null, |
|
79 | - 'providers' => [] |
|
80 | - ]; |
|
81 | - $this->storage = $storage; |
|
82 | - $this->logger = $logger; |
|
83 | - $this->httpClient = $httpClient; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Instantiate the given provider and authentication or authorization protocol. |
|
88 | - * |
|
89 | - * If not authenticated yet, the user will be redirected to the provider's site for |
|
90 | - * authentication/authorisation, otherwise it will simply return an instance of |
|
91 | - * provider's adapter. |
|
92 | - * |
|
93 | - * @param string $name adapter's name (case insensitive) |
|
94 | - * |
|
95 | - * @return \Hybridauth\Adapter\AdapterInterface |
|
96 | - * @throws InvalidArgumentException |
|
97 | - * @throws UnexpectedValueException |
|
98 | - */ |
|
99 | - public function authenticate($name) |
|
100 | - { |
|
101 | - $adapter = $this->getAdapter($name); |
|
102 | - |
|
103 | - $adapter->authenticate(); |
|
104 | - |
|
105 | - return $adapter; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns a new instance of a provider's adapter by name |
|
110 | - * |
|
111 | - * @param string $name adapter's name (case insensitive) |
|
112 | - * |
|
113 | - * @return \Hybridauth\Adapter\AdapterInterface |
|
114 | - * @throws InvalidArgumentException |
|
115 | - * @throws UnexpectedValueException |
|
116 | - */ |
|
117 | - public function getAdapter($name) |
|
118 | - { |
|
119 | - $config = $this->getProviderConfig($name); |
|
120 | - |
|
121 | - $adapter = isset($config['adapter']) ? $config['adapter'] : sprintf('Hybridauth\\Provider\\%s', $name); |
|
122 | - |
|
123 | - if (!class_exists($adapter)) { |
|
124 | - $adapter = null; |
|
125 | - $fs = new \FilesystemIterator(__DIR__ . '/Provider/'); |
|
126 | - /** @var \SplFileInfo $file */ |
|
127 | - foreach ($fs as $file) { |
|
128 | - if (!$file->isDir()) { |
|
129 | - $provider = strtok($file->getFilename(), '.'); |
|
130 | - if ($name === mb_strtolower($provider)) { |
|
131 | - $adapter = sprintf('Hybridauth\\Provider\\%s', $provider); |
|
132 | - break; |
|
133 | - } |
|
134 | - } |
|
135 | - } |
|
136 | - if ($adapter === null) { |
|
137 | - throw new InvalidArgumentException('Unknown Provider.'); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - return new $adapter($config, $this->httpClient, $this->storage, $this->logger); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Get provider config by name. |
|
146 | - * |
|
147 | - * @param string $name adapter's name (case insensitive) |
|
148 | - * |
|
149 | - * @throws UnexpectedValueException |
|
150 | - * @throws InvalidArgumentException |
|
151 | - * |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - public function getProviderConfig($name) |
|
155 | - { |
|
156 | - $name = strtolower($name); |
|
157 | - |
|
158 | - $providersConfig = array_change_key_case($this->config['providers'], CASE_LOWER); |
|
159 | - |
|
160 | - if (!isset($providersConfig[$name])) { |
|
161 | - throw new InvalidArgumentException('Unknown Provider.'); |
|
162 | - } |
|
163 | - |
|
164 | - if (!$providersConfig[$name]['enabled']) { |
|
165 | - throw new UnexpectedValueException('Disabled Provider.'); |
|
166 | - } |
|
167 | - |
|
168 | - $config = $providersConfig[$name]; |
|
169 | - $config += [ |
|
170 | - 'debug_mode' => $this->config['debug_mode'], |
|
171 | - 'debug_file' => $this->config['debug_file'], |
|
172 | - ]; |
|
173 | - |
|
174 | - if (!isset($config['callback']) && isset($this->config['callback'])) { |
|
175 | - $config['callback'] = $this->config['callback']; |
|
176 | - } |
|
177 | - |
|
178 | - return $config; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Returns a boolean of whether the user is connected with a provider |
|
183 | - * |
|
184 | - * @param string $name adapter's name (case insensitive) |
|
185 | - * |
|
186 | - * @return bool |
|
187 | - * @throws InvalidArgumentException |
|
188 | - * @throws UnexpectedValueException |
|
189 | - */ |
|
190 | - public function isConnectedWith($name) |
|
191 | - { |
|
192 | - return $this->getAdapter($name)->isConnected(); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Returns a list of enabled adapters names |
|
197 | - * |
|
198 | - * @return array |
|
199 | - */ |
|
200 | - public function getProviders() |
|
201 | - { |
|
202 | - $providers = []; |
|
203 | - |
|
204 | - foreach ($this->config['providers'] as $name => $config) { |
|
205 | - if ($config['enabled']) { |
|
206 | - $providers[] = $name; |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - return $providers; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Returns a list of currently connected adapters names |
|
215 | - * |
|
216 | - * @return array |
|
217 | - * @throws InvalidArgumentException |
|
218 | - * @throws UnexpectedValueException |
|
219 | - */ |
|
220 | - public function getConnectedProviders() |
|
221 | - { |
|
222 | - $providers = []; |
|
223 | - |
|
224 | - foreach ($this->getProviders() as $name) { |
|
225 | - if ($this->isConnectedWith($name)) { |
|
226 | - $providers[] = $name; |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - return $providers; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Returns a list of new instances of currently connected adapters |
|
235 | - * |
|
236 | - * @return \Hybridauth\Adapter\AdapterInterface[] |
|
237 | - * @throws InvalidArgumentException |
|
238 | - * @throws UnexpectedValueException |
|
239 | - */ |
|
240 | - public function getConnectedAdapters() |
|
241 | - { |
|
242 | - $adapters = []; |
|
243 | - |
|
244 | - foreach ($this->getProviders() as $name) { |
|
245 | - $adapter = $this->getAdapter($name); |
|
246 | - |
|
247 | - if ($adapter->isConnected()) { |
|
248 | - $adapters[$name] = $adapter; |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - return $adapters; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Disconnect all currently connected adapters at once |
|
257 | - */ |
|
258 | - public function disconnectAllAdapters() |
|
259 | - { |
|
260 | - foreach ($this->getProviders() as $name) { |
|
261 | - $adapter = $this->getAdapter($name); |
|
262 | - |
|
263 | - if ($adapter->isConnected()) { |
|
264 | - $adapter->disconnect(); |
|
265 | - } |
|
266 | - } |
|
267 | - } |
|
27 | + /** |
|
28 | + * Hybridauth config. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $config; |
|
33 | + |
|
34 | + /** |
|
35 | + * Storage. |
|
36 | + * |
|
37 | + * @var StorageInterface |
|
38 | + */ |
|
39 | + protected $storage; |
|
40 | + |
|
41 | + /** |
|
42 | + * HttpClient. |
|
43 | + * |
|
44 | + * @var HttpClientInterface |
|
45 | + */ |
|
46 | + protected $httpClient; |
|
47 | + |
|
48 | + /** |
|
49 | + * Logger. |
|
50 | + * |
|
51 | + * @var LoggerInterface |
|
52 | + */ |
|
53 | + protected $logger; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param array|string $config Array with configuration or Path to PHP file that will return array |
|
57 | + * @param HttpClientInterface $httpClient |
|
58 | + * @param StorageInterface $storage |
|
59 | + * @param LoggerInterface $logger |
|
60 | + * |
|
61 | + * @throws InvalidArgumentException |
|
62 | + */ |
|
63 | + public function __construct( |
|
64 | + $config, |
|
65 | + HttpClientInterface $httpClient = null, |
|
66 | + StorageInterface $storage = null, |
|
67 | + LoggerInterface $logger = null |
|
68 | + ) { |
|
69 | + if (is_string($config) && file_exists($config)) { |
|
70 | + $config = include $config; |
|
71 | + } elseif (!is_array($config)) { |
|
72 | + throw new InvalidArgumentException('Hybridauth config does not exist on the given path.'); |
|
73 | + } |
|
74 | + |
|
75 | + $this->config = $config + [ |
|
76 | + 'debug_mode' => Logger::NONE, |
|
77 | + 'debug_file' => '', |
|
78 | + 'curl_options' => null, |
|
79 | + 'providers' => [] |
|
80 | + ]; |
|
81 | + $this->storage = $storage; |
|
82 | + $this->logger = $logger; |
|
83 | + $this->httpClient = $httpClient; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Instantiate the given provider and authentication or authorization protocol. |
|
88 | + * |
|
89 | + * If not authenticated yet, the user will be redirected to the provider's site for |
|
90 | + * authentication/authorisation, otherwise it will simply return an instance of |
|
91 | + * provider's adapter. |
|
92 | + * |
|
93 | + * @param string $name adapter's name (case insensitive) |
|
94 | + * |
|
95 | + * @return \Hybridauth\Adapter\AdapterInterface |
|
96 | + * @throws InvalidArgumentException |
|
97 | + * @throws UnexpectedValueException |
|
98 | + */ |
|
99 | + public function authenticate($name) |
|
100 | + { |
|
101 | + $adapter = $this->getAdapter($name); |
|
102 | + |
|
103 | + $adapter->authenticate(); |
|
104 | + |
|
105 | + return $adapter; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns a new instance of a provider's adapter by name |
|
110 | + * |
|
111 | + * @param string $name adapter's name (case insensitive) |
|
112 | + * |
|
113 | + * @return \Hybridauth\Adapter\AdapterInterface |
|
114 | + * @throws InvalidArgumentException |
|
115 | + * @throws UnexpectedValueException |
|
116 | + */ |
|
117 | + public function getAdapter($name) |
|
118 | + { |
|
119 | + $config = $this->getProviderConfig($name); |
|
120 | + |
|
121 | + $adapter = isset($config['adapter']) ? $config['adapter'] : sprintf('Hybridauth\\Provider\\%s', $name); |
|
122 | + |
|
123 | + if (!class_exists($adapter)) { |
|
124 | + $adapter = null; |
|
125 | + $fs = new \FilesystemIterator(__DIR__ . '/Provider/'); |
|
126 | + /** @var \SplFileInfo $file */ |
|
127 | + foreach ($fs as $file) { |
|
128 | + if (!$file->isDir()) { |
|
129 | + $provider = strtok($file->getFilename(), '.'); |
|
130 | + if ($name === mb_strtolower($provider)) { |
|
131 | + $adapter = sprintf('Hybridauth\\Provider\\%s', $provider); |
|
132 | + break; |
|
133 | + } |
|
134 | + } |
|
135 | + } |
|
136 | + if ($adapter === null) { |
|
137 | + throw new InvalidArgumentException('Unknown Provider.'); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + return new $adapter($config, $this->httpClient, $this->storage, $this->logger); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Get provider config by name. |
|
146 | + * |
|
147 | + * @param string $name adapter's name (case insensitive) |
|
148 | + * |
|
149 | + * @throws UnexpectedValueException |
|
150 | + * @throws InvalidArgumentException |
|
151 | + * |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + public function getProviderConfig($name) |
|
155 | + { |
|
156 | + $name = strtolower($name); |
|
157 | + |
|
158 | + $providersConfig = array_change_key_case($this->config['providers'], CASE_LOWER); |
|
159 | + |
|
160 | + if (!isset($providersConfig[$name])) { |
|
161 | + throw new InvalidArgumentException('Unknown Provider.'); |
|
162 | + } |
|
163 | + |
|
164 | + if (!$providersConfig[$name]['enabled']) { |
|
165 | + throw new UnexpectedValueException('Disabled Provider.'); |
|
166 | + } |
|
167 | + |
|
168 | + $config = $providersConfig[$name]; |
|
169 | + $config += [ |
|
170 | + 'debug_mode' => $this->config['debug_mode'], |
|
171 | + 'debug_file' => $this->config['debug_file'], |
|
172 | + ]; |
|
173 | + |
|
174 | + if (!isset($config['callback']) && isset($this->config['callback'])) { |
|
175 | + $config['callback'] = $this->config['callback']; |
|
176 | + } |
|
177 | + |
|
178 | + return $config; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Returns a boolean of whether the user is connected with a provider |
|
183 | + * |
|
184 | + * @param string $name adapter's name (case insensitive) |
|
185 | + * |
|
186 | + * @return bool |
|
187 | + * @throws InvalidArgumentException |
|
188 | + * @throws UnexpectedValueException |
|
189 | + */ |
|
190 | + public function isConnectedWith($name) |
|
191 | + { |
|
192 | + return $this->getAdapter($name)->isConnected(); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Returns a list of enabled adapters names |
|
197 | + * |
|
198 | + * @return array |
|
199 | + */ |
|
200 | + public function getProviders() |
|
201 | + { |
|
202 | + $providers = []; |
|
203 | + |
|
204 | + foreach ($this->config['providers'] as $name => $config) { |
|
205 | + if ($config['enabled']) { |
|
206 | + $providers[] = $name; |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + return $providers; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Returns a list of currently connected adapters names |
|
215 | + * |
|
216 | + * @return array |
|
217 | + * @throws InvalidArgumentException |
|
218 | + * @throws UnexpectedValueException |
|
219 | + */ |
|
220 | + public function getConnectedProviders() |
|
221 | + { |
|
222 | + $providers = []; |
|
223 | + |
|
224 | + foreach ($this->getProviders() as $name) { |
|
225 | + if ($this->isConnectedWith($name)) { |
|
226 | + $providers[] = $name; |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + return $providers; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Returns a list of new instances of currently connected adapters |
|
235 | + * |
|
236 | + * @return \Hybridauth\Adapter\AdapterInterface[] |
|
237 | + * @throws InvalidArgumentException |
|
238 | + * @throws UnexpectedValueException |
|
239 | + */ |
|
240 | + public function getConnectedAdapters() |
|
241 | + { |
|
242 | + $adapters = []; |
|
243 | + |
|
244 | + foreach ($this->getProviders() as $name) { |
|
245 | + $adapter = $this->getAdapter($name); |
|
246 | + |
|
247 | + if ($adapter->isConnected()) { |
|
248 | + $adapters[$name] = $adapter; |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + return $adapters; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Disconnect all currently connected adapters at once |
|
257 | + */ |
|
258 | + public function disconnectAllAdapters() |
|
259 | + { |
|
260 | + foreach ($this->getProviders() as $name) { |
|
261 | + $adapter = $this->getAdapter($name); |
|
262 | + |
|
263 | + if ($adapter->isConnected()) { |
|
264 | + $adapter->disconnect(); |
|
265 | + } |
|
266 | + } |
|
267 | + } |
|
268 | 268 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if (version_compare(PHP_VERSION, '5.4.0', '<')) { |
10 | - throw new Exception('Hybridauth 3 requires PHP version 5.4 or higher.'); |
|
10 | + throw new Exception('Hybridauth 3 requires PHP version 5.4 or higher.'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -21,33 +21,33 @@ discard block |
||
21 | 21 | * @return void |
22 | 22 | */ |
23 | 23 | spl_autoload_register( |
24 | - function ($class) { |
|
25 | - // project-specific namespace prefix. Will only kicks in for Hybridauth's namespace. |
|
26 | - $prefix = 'Hybridauth\\'; |
|
24 | + function ($class) { |
|
25 | + // project-specific namespace prefix. Will only kicks in for Hybridauth's namespace. |
|
26 | + $prefix = 'Hybridauth\\'; |
|
27 | 27 | |
28 | - // base directory for the namespace prefix. |
|
29 | - $base_dir = __DIR__; // By default, it points to this same folder. |
|
30 | - // You may change this path if having trouble detecting the path to |
|
31 | - // the source files. |
|
28 | + // base directory for the namespace prefix. |
|
29 | + $base_dir = __DIR__; // By default, it points to this same folder. |
|
30 | + // You may change this path if having trouble detecting the path to |
|
31 | + // the source files. |
|
32 | 32 | |
33 | - // does the class use the namespace prefix? |
|
34 | - $len = strlen($prefix); |
|
35 | - if (strncmp($prefix, $class, $len) !== 0) { |
|
36 | - // no, move to the next registered autoloader. |
|
37 | - return; |
|
38 | - } |
|
33 | + // does the class use the namespace prefix? |
|
34 | + $len = strlen($prefix); |
|
35 | + if (strncmp($prefix, $class, $len) !== 0) { |
|
36 | + // no, move to the next registered autoloader. |
|
37 | + return; |
|
38 | + } |
|
39 | 39 | |
40 | - // get the relative class name. |
|
41 | - $relative_class = substr($class, $len); |
|
40 | + // get the relative class name. |
|
41 | + $relative_class = substr($class, $len); |
|
42 | 42 | |
43 | - // replace the namespace prefix with the base directory, replace namespace |
|
44 | - // separators with directory separators in the relative class name, append |
|
45 | - // with .php |
|
46 | - $file = $base_dir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php'; |
|
43 | + // replace the namespace prefix with the base directory, replace namespace |
|
44 | + // separators with directory separators in the relative class name, append |
|
45 | + // with .php |
|
46 | + $file = $base_dir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php'; |
|
47 | 47 | |
48 | - // if the file exists, require it |
|
49 | - if (file_exists($file)) { |
|
50 | - require $file; |
|
51 | - } |
|
52 | - } |
|
48 | + // if the file exists, require it |
|
49 | + if (file_exists($file)) { |
|
50 | + require $file; |
|
51 | + } |
|
52 | + } |
|
53 | 53 | ); |
@@ -12,39 +12,39 @@ |
||
12 | 12 | */ |
13 | 13 | interface StorageInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * Retrieve a item from storage |
|
17 | - * |
|
18 | - * @param string $key |
|
19 | - * |
|
20 | - * @return mixed |
|
21 | - */ |
|
22 | - public function get($key); |
|
15 | + /** |
|
16 | + * Retrieve a item from storage |
|
17 | + * |
|
18 | + * @param string $key |
|
19 | + * |
|
20 | + * @return mixed |
|
21 | + */ |
|
22 | + public function get($key); |
|
23 | 23 | |
24 | - /** |
|
25 | - * Add or Update an item to storage |
|
26 | - * |
|
27 | - * @param string $key |
|
28 | - * @param string $value |
|
29 | - */ |
|
30 | - public function set($key, $value); |
|
24 | + /** |
|
25 | + * Add or Update an item to storage |
|
26 | + * |
|
27 | + * @param string $key |
|
28 | + * @param string $value |
|
29 | + */ |
|
30 | + public function set($key, $value); |
|
31 | 31 | |
32 | - /** |
|
33 | - * Delete an item from storage |
|
34 | - * |
|
35 | - * @param string $key |
|
36 | - */ |
|
37 | - public function delete($key); |
|
32 | + /** |
|
33 | + * Delete an item from storage |
|
34 | + * |
|
35 | + * @param string $key |
|
36 | + */ |
|
37 | + public function delete($key); |
|
38 | 38 | |
39 | - /** |
|
40 | - * Delete a item from storage |
|
41 | - * |
|
42 | - * @param string $key |
|
43 | - */ |
|
44 | - public function deleteMatch($key); |
|
39 | + /** |
|
40 | + * Delete a item from storage |
|
41 | + * |
|
42 | + * @param string $key |
|
43 | + */ |
|
44 | + public function deleteMatch($key); |
|
45 | 45 | |
46 | - /** |
|
47 | - * Clear all items in storage |
|
48 | - */ |
|
49 | - public function clear(); |
|
46 | + /** |
|
47 | + * Clear all items in storage |
|
48 | + */ |
|
49 | + public function clear(); |
|
50 | 50 | } |
@@ -14,177 +14,177 @@ |
||
14 | 14 | */ |
15 | 15 | final class Profile |
16 | 16 | { |
17 | - /** |
|
18 | - * The Unique user's ID on the connected provider |
|
19 | - * |
|
20 | - * @var int|null |
|
21 | - */ |
|
22 | - public $identifier = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * User website, blog, web page |
|
26 | - * |
|
27 | - * @var string|null |
|
28 | - */ |
|
29 | - public $webSiteURL = null; |
|
30 | - |
|
31 | - /** |
|
32 | - * URL link to profile page on the IDp web site |
|
33 | - * |
|
34 | - * @var string|null |
|
35 | - */ |
|
36 | - public $profileURL = null; |
|
37 | - |
|
38 | - /** |
|
39 | - * URL link to user photo or avatar |
|
40 | - * |
|
41 | - * @var string|null |
|
42 | - */ |
|
43 | - public $photoURL = null; |
|
44 | - |
|
45 | - /** |
|
46 | - * User displayName provided by the IDp or a concatenation of first and last name. |
|
47 | - * |
|
48 | - * @var string|null |
|
49 | - */ |
|
50 | - public $displayName = null; |
|
51 | - |
|
52 | - /** |
|
53 | - * A short about_me |
|
54 | - * |
|
55 | - * @var string|null |
|
56 | - */ |
|
57 | - public $description = null; |
|
58 | - |
|
59 | - /** |
|
60 | - * User's first name |
|
61 | - * |
|
62 | - * @var string|null |
|
63 | - */ |
|
64 | - public $firstName = null; |
|
65 | - |
|
66 | - /** |
|
67 | - * User's last name |
|
68 | - * |
|
69 | - * @var string|null |
|
70 | - */ |
|
71 | - public $lastName = null; |
|
72 | - |
|
73 | - /** |
|
74 | - * male or female |
|
75 | - * |
|
76 | - * @var string|null |
|
77 | - */ |
|
78 | - public $gender = null; |
|
79 | - |
|
80 | - /** |
|
81 | - * Language |
|
82 | - * |
|
83 | - * @var string|null |
|
84 | - */ |
|
85 | - public $language = null; |
|
86 | - |
|
87 | - /** |
|
88 | - * User age, we don't calculate it. we return it as is if the IDp provide it. |
|
89 | - * |
|
90 | - * @var int|null |
|
91 | - */ |
|
92 | - public $age = null; |
|
93 | - |
|
94 | - /** |
|
95 | - * User birth Day |
|
96 | - * |
|
97 | - * @var int|null |
|
98 | - */ |
|
99 | - public $birthDay = null; |
|
100 | - |
|
101 | - /** |
|
102 | - * User birth Month |
|
103 | - * |
|
104 | - * @var int|null |
|
105 | - */ |
|
106 | - public $birthMonth = null; |
|
107 | - |
|
108 | - /** |
|
109 | - * User birth Year |
|
110 | - * |
|
111 | - * @var int|null |
|
112 | - */ |
|
113 | - public $birthYear = null; |
|
114 | - |
|
115 | - /** |
|
116 | - * User email. Note: not all of IDp grant access to the user email |
|
117 | - * |
|
118 | - * @var string|null |
|
119 | - */ |
|
120 | - public $email = null; |
|
121 | - |
|
122 | - /** |
|
123 | - * Verified user email. Note: not all of IDp grant access to verified user email |
|
124 | - * |
|
125 | - * @var string|null |
|
126 | - */ |
|
127 | - public $emailVerified = null; |
|
128 | - |
|
129 | - /** |
|
130 | - * Phone number |
|
131 | - * |
|
132 | - * @var string|null |
|
133 | - */ |
|
134 | - public $phone = null; |
|
135 | - |
|
136 | - /** |
|
137 | - * Complete user address |
|
138 | - * |
|
139 | - * @var string|null |
|
140 | - */ |
|
141 | - public $address = null; |
|
142 | - |
|
143 | - /** |
|
144 | - * User country |
|
145 | - * |
|
146 | - * @var string|null |
|
147 | - */ |
|
148 | - public $country = null; |
|
149 | - |
|
150 | - /** |
|
151 | - * Region |
|
152 | - * |
|
153 | - * @var string|null |
|
154 | - */ |
|
155 | - public $region = null; |
|
156 | - |
|
157 | - /** |
|
158 | - * City |
|
159 | - * |
|
160 | - * @var string|null |
|
161 | - */ |
|
162 | - public $city = null; |
|
163 | - |
|
164 | - /** |
|
165 | - * Postal code |
|
166 | - * |
|
167 | - * @var string|null |
|
168 | - */ |
|
169 | - public $zip = null; |
|
170 | - |
|
171 | - /** |
|
172 | - * An extra data which is related to the user |
|
173 | - * |
|
174 | - * @var array |
|
175 | - */ |
|
176 | - public $data = []; |
|
177 | - |
|
178 | - /** |
|
179 | - * Prevent the providers adapters from adding new fields. |
|
180 | - * |
|
181 | - * @throws UnexpectedValueException |
|
182 | - * @var mixed $value |
|
183 | - * |
|
184 | - * @var string $name |
|
185 | - */ |
|
186 | - public function __set($name, $value) |
|
187 | - { |
|
188 | - throw new UnexpectedValueException(sprintf('Adding new property "%s" to %s is not allowed.', $name, __CLASS__)); |
|
189 | - } |
|
17 | + /** |
|
18 | + * The Unique user's ID on the connected provider |
|
19 | + * |
|
20 | + * @var int|null |
|
21 | + */ |
|
22 | + public $identifier = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * User website, blog, web page |
|
26 | + * |
|
27 | + * @var string|null |
|
28 | + */ |
|
29 | + public $webSiteURL = null; |
|
30 | + |
|
31 | + /** |
|
32 | + * URL link to profile page on the IDp web site |
|
33 | + * |
|
34 | + * @var string|null |
|
35 | + */ |
|
36 | + public $profileURL = null; |
|
37 | + |
|
38 | + /** |
|
39 | + * URL link to user photo or avatar |
|
40 | + * |
|
41 | + * @var string|null |
|
42 | + */ |
|
43 | + public $photoURL = null; |
|
44 | + |
|
45 | + /** |
|
46 | + * User displayName provided by the IDp or a concatenation of first and last name. |
|
47 | + * |
|
48 | + * @var string|null |
|
49 | + */ |
|
50 | + public $displayName = null; |
|
51 | + |
|
52 | + /** |
|
53 | + * A short about_me |
|
54 | + * |
|
55 | + * @var string|null |
|
56 | + */ |
|
57 | + public $description = null; |
|
58 | + |
|
59 | + /** |
|
60 | + * User's first name |
|
61 | + * |
|
62 | + * @var string|null |
|
63 | + */ |
|
64 | + public $firstName = null; |
|
65 | + |
|
66 | + /** |
|
67 | + * User's last name |
|
68 | + * |
|
69 | + * @var string|null |
|
70 | + */ |
|
71 | + public $lastName = null; |
|
72 | + |
|
73 | + /** |
|
74 | + * male or female |
|
75 | + * |
|
76 | + * @var string|null |
|
77 | + */ |
|
78 | + public $gender = null; |
|
79 | + |
|
80 | + /** |
|
81 | + * Language |
|
82 | + * |
|
83 | + * @var string|null |
|
84 | + */ |
|
85 | + public $language = null; |
|
86 | + |
|
87 | + /** |
|
88 | + * User age, we don't calculate it. we return it as is if the IDp provide it. |
|
89 | + * |
|
90 | + * @var int|null |
|
91 | + */ |
|
92 | + public $age = null; |
|
93 | + |
|
94 | + /** |
|
95 | + * User birth Day |
|
96 | + * |
|
97 | + * @var int|null |
|
98 | + */ |
|
99 | + public $birthDay = null; |
|
100 | + |
|
101 | + /** |
|
102 | + * User birth Month |
|
103 | + * |
|
104 | + * @var int|null |
|
105 | + */ |
|
106 | + public $birthMonth = null; |
|
107 | + |
|
108 | + /** |
|
109 | + * User birth Year |
|
110 | + * |
|
111 | + * @var int|null |
|
112 | + */ |
|
113 | + public $birthYear = null; |
|
114 | + |
|
115 | + /** |
|
116 | + * User email. Note: not all of IDp grant access to the user email |
|
117 | + * |
|
118 | + * @var string|null |
|
119 | + */ |
|
120 | + public $email = null; |
|
121 | + |
|
122 | + /** |
|
123 | + * Verified user email. Note: not all of IDp grant access to verified user email |
|
124 | + * |
|
125 | + * @var string|null |
|
126 | + */ |
|
127 | + public $emailVerified = null; |
|
128 | + |
|
129 | + /** |
|
130 | + * Phone number |
|
131 | + * |
|
132 | + * @var string|null |
|
133 | + */ |
|
134 | + public $phone = null; |
|
135 | + |
|
136 | + /** |
|
137 | + * Complete user address |
|
138 | + * |
|
139 | + * @var string|null |
|
140 | + */ |
|
141 | + public $address = null; |
|
142 | + |
|
143 | + /** |
|
144 | + * User country |
|
145 | + * |
|
146 | + * @var string|null |
|
147 | + */ |
|
148 | + public $country = null; |
|
149 | + |
|
150 | + /** |
|
151 | + * Region |
|
152 | + * |
|
153 | + * @var string|null |
|
154 | + */ |
|
155 | + public $region = null; |
|
156 | + |
|
157 | + /** |
|
158 | + * City |
|
159 | + * |
|
160 | + * @var string|null |
|
161 | + */ |
|
162 | + public $city = null; |
|
163 | + |
|
164 | + /** |
|
165 | + * Postal code |
|
166 | + * |
|
167 | + * @var string|null |
|
168 | + */ |
|
169 | + public $zip = null; |
|
170 | + |
|
171 | + /** |
|
172 | + * An extra data which is related to the user |
|
173 | + * |
|
174 | + * @var array |
|
175 | + */ |
|
176 | + public $data = []; |
|
177 | + |
|
178 | + /** |
|
179 | + * Prevent the providers adapters from adding new fields. |
|
180 | + * |
|
181 | + * @throws UnexpectedValueException |
|
182 | + * @var mixed $value |
|
183 | + * |
|
184 | + * @var string $name |
|
185 | + */ |
|
186 | + public function __set($name, $value) |
|
187 | + { |
|
188 | + throw new UnexpectedValueException(sprintf('Adding new property "%s" to %s is not allowed.', $name, __CLASS__)); |
|
189 | + } |
|
190 | 190 | } |
@@ -14,60 +14,60 @@ |
||
14 | 14 | */ |
15 | 15 | final class Activity |
16 | 16 | { |
17 | - /** |
|
18 | - * activity id on the provider side, usually given as integer |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $id = null; |
|
17 | + /** |
|
18 | + * activity id on the provider side, usually given as integer |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $id = null; |
|
23 | 23 | |
24 | - /** |
|
25 | - * activity date of creation |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - public $date = null; |
|
24 | + /** |
|
25 | + * activity date of creation |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + public $date = null; |
|
30 | 30 | |
31 | - /** |
|
32 | - * activity content as a string |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $text = null; |
|
31 | + /** |
|
32 | + * activity content as a string |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $text = null; |
|
37 | 37 | |
38 | - /** |
|
39 | - * user who created the activity |
|
40 | - * |
|
41 | - * @var object |
|
42 | - */ |
|
43 | - public $user = null; |
|
38 | + /** |
|
39 | + * user who created the activity |
|
40 | + * |
|
41 | + * @var object |
|
42 | + */ |
|
43 | + public $user = null; |
|
44 | 44 | |
45 | - /** |
|
46 | - * |
|
47 | - */ |
|
48 | - public function __construct() |
|
49 | - { |
|
50 | - $this->user = new \stdClass(); |
|
45 | + /** |
|
46 | + * |
|
47 | + */ |
|
48 | + public function __construct() |
|
49 | + { |
|
50 | + $this->user = new \stdClass(); |
|
51 | 51 | |
52 | - // typically, we should have a few information about the user who created the event from social apis |
|
53 | - $this->user->identifier = null; |
|
54 | - $this->user->displayName = null; |
|
55 | - $this->user->profileURL = null; |
|
56 | - $this->user->photoURL = null; |
|
57 | - } |
|
52 | + // typically, we should have a few information about the user who created the event from social apis |
|
53 | + $this->user->identifier = null; |
|
54 | + $this->user->displayName = null; |
|
55 | + $this->user->profileURL = null; |
|
56 | + $this->user->photoURL = null; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Prevent the providers adapters from adding new fields. |
|
61 | - * |
|
62 | - * @throws UnexpectedValueException |
|
63 | - * @var string $name |
|
64 | - * |
|
65 | - * @var mixed $value |
|
66 | - * |
|
67 | - */ |
|
68 | - public function __set($name, $value) |
|
69 | - { |
|
70 | - // phpcs:ignore |
|
71 | - throw new UnexpectedValueException(sprintf('Adding new property "%s\' to %s is not allowed.', $name, __CLASS__)); |
|
72 | - } |
|
59 | + /** |
|
60 | + * Prevent the providers adapters from adding new fields. |
|
61 | + * |
|
62 | + * @throws UnexpectedValueException |
|
63 | + * @var string $name |
|
64 | + * |
|
65 | + * @var mixed $value |
|
66 | + * |
|
67 | + */ |
|
68 | + public function __set($name, $value) |
|
69 | + { |
|
70 | + // phpcs:ignore |
|
71 | + throw new UnexpectedValueException(sprintf('Adding new property "%s\' to %s is not allowed.', $name, __CLASS__)); |
|
72 | + } |
|
73 | 73 | } |
@@ -14,65 +14,65 @@ |
||
14 | 14 | */ |
15 | 15 | final class Contact |
16 | 16 | { |
17 | - /** |
|
18 | - * The Unique contact user ID |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $identifier = null; |
|
17 | + /** |
|
18 | + * The Unique contact user ID |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $identifier = null; |
|
23 | 23 | |
24 | - /** |
|
25 | - * User website, blog, web page |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - public $webSiteURL = null; |
|
24 | + /** |
|
25 | + * User website, blog, web page |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + public $webSiteURL = null; |
|
30 | 30 | |
31 | - /** |
|
32 | - * URL link to profile page on the IDp web site |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $profileURL = null; |
|
31 | + /** |
|
32 | + * URL link to profile page on the IDp web site |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $profileURL = null; |
|
37 | 37 | |
38 | - /** |
|
39 | - * URL link to user photo or avatar |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - public $photoURL = null; |
|
38 | + /** |
|
39 | + * URL link to user photo or avatar |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + public $photoURL = null; |
|
44 | 44 | |
45 | - /** |
|
46 | - * User displayName provided by the IDp or a concatenation of first and last name |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - public $displayName = null; |
|
45 | + /** |
|
46 | + * User displayName provided by the IDp or a concatenation of first and last name |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + public $displayName = null; |
|
51 | 51 | |
52 | - /** |
|
53 | - * A short about_me |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public $description = null; |
|
52 | + /** |
|
53 | + * A short about_me |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public $description = null; |
|
58 | 58 | |
59 | - /** |
|
60 | - * User email. Not all of IDp grant access to the user email |
|
61 | - * |
|
62 | - * @var string |
|
63 | - */ |
|
64 | - public $email = null; |
|
59 | + /** |
|
60 | + * User email. Not all of IDp grant access to the user email |
|
61 | + * |
|
62 | + * @var string |
|
63 | + */ |
|
64 | + public $email = null; |
|
65 | 65 | |
66 | - /** |
|
67 | - * Prevent the providers adapters from adding new fields. |
|
68 | - * |
|
69 | - * @param string $name |
|
70 | - * @param mixed $value |
|
71 | - * |
|
72 | - * @throws UnexpectedValueException |
|
73 | - */ |
|
74 | - public function __set($name, $value) |
|
75 | - { |
|
76 | - throw new UnexpectedValueException(sprintf('Adding new property "%s" to %s is not allowed.', $name, __CLASS__)); |
|
77 | - } |
|
66 | + /** |
|
67 | + * Prevent the providers adapters from adding new fields. |
|
68 | + * |
|
69 | + * @param string $name |
|
70 | + * @param mixed $value |
|
71 | + * |
|
72 | + * @throws UnexpectedValueException |
|
73 | + */ |
|
74 | + public function __set($name, $value) |
|
75 | + { |
|
76 | + throw new UnexpectedValueException(sprintf('Adding new property "%s" to %s is not allowed.', $name, __CLASS__)); |
|
77 | + } |
|
78 | 78 | } |
@@ -14,117 +14,117 @@ |
||
14 | 14 | */ |
15 | 15 | class Session implements StorageInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * Namespace |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $storeNamespace = 'HYBRIDAUTH::STORAGE'; |
|
23 | - |
|
24 | - /** |
|
25 | - * Key prefix |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $keyPrefix = ''; |
|
30 | - |
|
31 | - /** |
|
32 | - * Initiate a new session |
|
33 | - * |
|
34 | - * @throws RuntimeException |
|
35 | - */ |
|
36 | - public function __construct() |
|
37 | - { |
|
38 | - if (session_id()) { |
|
39 | - return; |
|
40 | - } |
|
41 | - |
|
42 | - if (headers_sent()) { |
|
43 | - // phpcs:ignore |
|
44 | - throw new RuntimeException('HTTP headers already sent to browser and Hybridauth won\'t be able to start/resume PHP session. To resolve this, session_start() must be called before outputing any data.'); |
|
45 | - } |
|
46 | - |
|
47 | - if (!session_start()) { |
|
48 | - throw new RuntimeException('PHP session failed to start.'); |
|
49 | - } |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * {@inheritdoc} |
|
54 | - */ |
|
55 | - public function get($key) |
|
56 | - { |
|
57 | - $key = $this->keyPrefix . strtolower($key); |
|
58 | - |
|
59 | - if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) { |
|
60 | - $value = $_SESSION[$this->storeNamespace][$key]; |
|
61 | - |
|
62 | - if (is_array($value) && array_key_exists('lateObject', $value)) { |
|
63 | - $value = unserialize($value['lateObject']); |
|
64 | - } |
|
65 | - |
|
66 | - return $value; |
|
67 | - } |
|
68 | - |
|
69 | - return null; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * {@inheritdoc} |
|
74 | - */ |
|
75 | - public function set($key, $value) |
|
76 | - { |
|
77 | - $key = $this->keyPrefix . strtolower($key); |
|
78 | - |
|
79 | - if (is_object($value)) { |
|
80 | - // We encapsulate as our classes may be defined after session is initialized. |
|
81 | - $value = ['lateObject' => serialize($value)]; |
|
82 | - } |
|
83 | - |
|
84 | - $_SESSION[$this->storeNamespace][$key] = $value; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * {@inheritdoc} |
|
89 | - */ |
|
90 | - public function clear() |
|
91 | - { |
|
92 | - $_SESSION[$this->storeNamespace] = []; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * {@inheritdoc} |
|
97 | - */ |
|
98 | - public function delete($key) |
|
99 | - { |
|
100 | - $key = $this->keyPrefix . strtolower($key); |
|
101 | - |
|
102 | - if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) { |
|
103 | - $tmp = $_SESSION[$this->storeNamespace]; |
|
104 | - |
|
105 | - unset($tmp[$key]); |
|
106 | - |
|
107 | - $_SESSION[$this->storeNamespace] = $tmp; |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * {@inheritdoc} |
|
113 | - */ |
|
114 | - public function deleteMatch($key) |
|
115 | - { |
|
116 | - $key = $this->keyPrefix . strtolower($key); |
|
117 | - |
|
118 | - if (isset($_SESSION[$this->storeNamespace]) && count($_SESSION[$this->storeNamespace])) { |
|
119 | - $tmp = $_SESSION[$this->storeNamespace]; |
|
120 | - |
|
121 | - foreach ($tmp as $k => $v) { |
|
122 | - if (strstr($k, $key)) { |
|
123 | - unset($tmp[$k]); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - $_SESSION[$this->storeNamespace] = $tmp; |
|
128 | - } |
|
129 | - } |
|
17 | + /** |
|
18 | + * Namespace |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $storeNamespace = 'HYBRIDAUTH::STORAGE'; |
|
23 | + |
|
24 | + /** |
|
25 | + * Key prefix |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $keyPrefix = ''; |
|
30 | + |
|
31 | + /** |
|
32 | + * Initiate a new session |
|
33 | + * |
|
34 | + * @throws RuntimeException |
|
35 | + */ |
|
36 | + public function __construct() |
|
37 | + { |
|
38 | + if (session_id()) { |
|
39 | + return; |
|
40 | + } |
|
41 | + |
|
42 | + if (headers_sent()) { |
|
43 | + // phpcs:ignore |
|
44 | + throw new RuntimeException('HTTP headers already sent to browser and Hybridauth won\'t be able to start/resume PHP session. To resolve this, session_start() must be called before outputing any data.'); |
|
45 | + } |
|
46 | + |
|
47 | + if (!session_start()) { |
|
48 | + throw new RuntimeException('PHP session failed to start.'); |
|
49 | + } |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * {@inheritdoc} |
|
54 | + */ |
|
55 | + public function get($key) |
|
56 | + { |
|
57 | + $key = $this->keyPrefix . strtolower($key); |
|
58 | + |
|
59 | + if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) { |
|
60 | + $value = $_SESSION[$this->storeNamespace][$key]; |
|
61 | + |
|
62 | + if (is_array($value) && array_key_exists('lateObject', $value)) { |
|
63 | + $value = unserialize($value['lateObject']); |
|
64 | + } |
|
65 | + |
|
66 | + return $value; |
|
67 | + } |
|
68 | + |
|
69 | + return null; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * {@inheritdoc} |
|
74 | + */ |
|
75 | + public function set($key, $value) |
|
76 | + { |
|
77 | + $key = $this->keyPrefix . strtolower($key); |
|
78 | + |
|
79 | + if (is_object($value)) { |
|
80 | + // We encapsulate as our classes may be defined after session is initialized. |
|
81 | + $value = ['lateObject' => serialize($value)]; |
|
82 | + } |
|
83 | + |
|
84 | + $_SESSION[$this->storeNamespace][$key] = $value; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * {@inheritdoc} |
|
89 | + */ |
|
90 | + public function clear() |
|
91 | + { |
|
92 | + $_SESSION[$this->storeNamespace] = []; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * {@inheritdoc} |
|
97 | + */ |
|
98 | + public function delete($key) |
|
99 | + { |
|
100 | + $key = $this->keyPrefix . strtolower($key); |
|
101 | + |
|
102 | + if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) { |
|
103 | + $tmp = $_SESSION[$this->storeNamespace]; |
|
104 | + |
|
105 | + unset($tmp[$key]); |
|
106 | + |
|
107 | + $_SESSION[$this->storeNamespace] = $tmp; |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * {@inheritdoc} |
|
113 | + */ |
|
114 | + public function deleteMatch($key) |
|
115 | + { |
|
116 | + $key = $this->keyPrefix . strtolower($key); |
|
117 | + |
|
118 | + if (isset($_SESSION[$this->storeNamespace]) && count($_SESSION[$this->storeNamespace])) { |
|
119 | + $tmp = $_SESSION[$this->storeNamespace]; |
|
120 | + |
|
121 | + foreach ($tmp as $k => $v) { |
|
122 | + if (strstr($k, $key)) { |
|
123 | + unset($tmp[$k]); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + $_SESSION[$this->storeNamespace] = $tmp; |
|
128 | + } |
|
129 | + } |
|
130 | 130 | } |
@@ -17,72 +17,72 @@ |
||
17 | 17 | */ |
18 | 18 | class Medium extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'basicProfile'; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'basicProfile'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://api.medium.com/v1/'; |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://api.medium.com/v1/'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl = 'https://medium.com/m/oauth/authorize'; |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl = 'https://medium.com/m/oauth/authorize'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://api.medium.com/v1/tokens'; |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://api.medium.com/v1/tokens'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://github.com/Medium/medium-api-docs'; |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://github.com/Medium/medium-api-docs'; |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - protected function initialize() |
|
49 | - { |
|
50 | - parent::initialize(); |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + protected function initialize() |
|
49 | + { |
|
50 | + parent::initialize(); |
|
51 | 51 | |
52 | - if ($this->isRefreshTokenAvailable()) { |
|
53 | - $this->tokenRefreshParameters += [ |
|
54 | - 'client_id' => $this->clientId, |
|
55 | - 'client_secret' => $this->clientSecret, |
|
56 | - ]; |
|
57 | - } |
|
58 | - } |
|
52 | + if ($this->isRefreshTokenAvailable()) { |
|
53 | + $this->tokenRefreshParameters += [ |
|
54 | + 'client_id' => $this->clientId, |
|
55 | + 'client_secret' => $this->clientSecret, |
|
56 | + ]; |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritdoc} |
|
62 | - * |
|
63 | - * See: https://github.com/Medium/medium-api-docs#getting-the-authenticated-users-details |
|
64 | - */ |
|
65 | - public function getUserProfile() |
|
66 | - { |
|
67 | - $response = $this->apiRequest('me'); |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + * |
|
63 | + * See: https://github.com/Medium/medium-api-docs#getting-the-authenticated-users-details |
|
64 | + */ |
|
65 | + public function getUserProfile() |
|
66 | + { |
|
67 | + $response = $this->apiRequest('me'); |
|
68 | 68 | |
69 | - $data = new Data\Collection($response); |
|
69 | + $data = new Data\Collection($response); |
|
70 | 70 | |
71 | - $userProfile = new User\Profile(); |
|
72 | - $data = $data->filter('data'); |
|
71 | + $userProfile = new User\Profile(); |
|
72 | + $data = $data->filter('data'); |
|
73 | 73 | |
74 | - $full_name = explode(' ', $data->get('name')); |
|
75 | - if (count($full_name) < 2) { |
|
76 | - $full_name[1] = ''; |
|
77 | - } |
|
74 | + $full_name = explode(' ', $data->get('name')); |
|
75 | + if (count($full_name) < 2) { |
|
76 | + $full_name[1] = ''; |
|
77 | + } |
|
78 | 78 | |
79 | - $userProfile->identifier = $data->get('id'); |
|
80 | - $userProfile->displayName = $data->get('username'); |
|
81 | - $userProfile->profileURL = $data->get('imageUrl'); |
|
82 | - $userProfile->firstName = $full_name[0]; |
|
83 | - $userProfile->lastName = $full_name[1]; |
|
84 | - $userProfile->profileURL = $data->get('url'); |
|
79 | + $userProfile->identifier = $data->get('id'); |
|
80 | + $userProfile->displayName = $data->get('username'); |
|
81 | + $userProfile->profileURL = $data->get('imageUrl'); |
|
82 | + $userProfile->firstName = $full_name[0]; |
|
83 | + $userProfile->lastName = $full_name[1]; |
|
84 | + $userProfile->profileURL = $data->get('url'); |
|
85 | 85 | |
86 | - return $userProfile; |
|
87 | - } |
|
86 | + return $userProfile; |
|
87 | + } |
|
88 | 88 | } |
@@ -16,140 +16,140 @@ |
||
16 | 16 | */ |
17 | 17 | interface AdapterInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * Initiate the appropriate protocol and process/automate the authentication or authorization flow. |
|
21 | - * |
|
22 | - * @return bool|null |
|
23 | - */ |
|
24 | - public function authenticate(); |
|
25 | - |
|
26 | - /** |
|
27 | - * Returns TRUE if the user is connected |
|
28 | - * |
|
29 | - * @return bool |
|
30 | - */ |
|
31 | - public function isConnected(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Clear all access token in storage |
|
35 | - */ |
|
36 | - public function disconnect(); |
|
37 | - |
|
38 | - /** |
|
39 | - * Retrieve the connected user profile |
|
40 | - * |
|
41 | - * @return \Hybridauth\User\Profile |
|
42 | - */ |
|
43 | - public function getUserProfile(); |
|
44 | - |
|
45 | - /** |
|
46 | - * Retrieve the connected user contacts list |
|
47 | - * |
|
48 | - * @return \Hybridauth\User\Contact[] |
|
49 | - */ |
|
50 | - public function getUserContacts(); |
|
51 | - |
|
52 | - /** |
|
53 | - * Retrieve the connected user pages|companies|groups list |
|
54 | - * |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function getUserPages(); |
|
58 | - |
|
59 | - /** |
|
60 | - * Retrieve the user activity stream |
|
61 | - * |
|
62 | - * @param string $stream |
|
63 | - * |
|
64 | - * @return \Hybridauth\User\Activity[] |
|
65 | - */ |
|
66 | - public function getUserActivity($stream); |
|
67 | - |
|
68 | - /** |
|
69 | - * Post a status on user wall|timeline|blog|website|etc. |
|
70 | - * |
|
71 | - * @param string|array $status |
|
72 | - * |
|
73 | - * @return mixed API response |
|
74 | - */ |
|
75 | - public function setUserStatus($status); |
|
76 | - |
|
77 | - /** |
|
78 | - * Post a status on page|company|group wall. |
|
79 | - * |
|
80 | - * @param string|array $status |
|
81 | - * @param string $pageId |
|
82 | - * |
|
83 | - * @return mixed API response |
|
84 | - */ |
|
85 | - public function setPageStatus($status, $pageId); |
|
86 | - |
|
87 | - /** |
|
88 | - * Send a signed request to provider API |
|
89 | - * |
|
90 | - * @param string $url |
|
91 | - * @param string $method |
|
92 | - * @param array $parameters |
|
93 | - * @param array $headers |
|
94 | - * @param bool $multipart |
|
95 | - * |
|
96 | - * @return mixed |
|
97 | - */ |
|
98 | - public function apiRequest($url, $method = 'GET', $parameters = [], $headers = [], $multipart = false); |
|
99 | - |
|
100 | - /** |
|
101 | - * Do whatever may be necessary to make sure tokens do not expire. |
|
102 | - * Intended to be be called frequently, e.g. via Cron. |
|
103 | - */ |
|
104 | - public function maintainToken(); |
|
105 | - |
|
106 | - /** |
|
107 | - * Return oauth access tokens. |
|
108 | - * |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public function getAccessToken(); |
|
112 | - |
|
113 | - /** |
|
114 | - * Set oauth access tokens. |
|
115 | - * |
|
116 | - * @param array $tokens |
|
117 | - */ |
|
118 | - public function setAccessToken($tokens = []); |
|
119 | - |
|
120 | - /** |
|
121 | - * Set http client instance. |
|
122 | - * |
|
123 | - * @param HttpClientInterface $httpClient |
|
124 | - */ |
|
125 | - public function setHttpClient(HttpClientInterface $httpClient = null); |
|
126 | - |
|
127 | - /** |
|
128 | - * Return http client instance. |
|
129 | - */ |
|
130 | - public function getHttpClient(); |
|
131 | - |
|
132 | - /** |
|
133 | - * Set storage instance. |
|
134 | - * |
|
135 | - * @param StorageInterface $storage |
|
136 | - */ |
|
137 | - public function setStorage(StorageInterface $storage = null); |
|
138 | - |
|
139 | - /** |
|
140 | - * Return storage instance. |
|
141 | - */ |
|
142 | - public function getStorage(); |
|
143 | - |
|
144 | - /** |
|
145 | - * Set Logger instance. |
|
146 | - * |
|
147 | - * @param LoggerInterface $logger |
|
148 | - */ |
|
149 | - public function setLogger(LoggerInterface $logger = null); |
|
150 | - |
|
151 | - /** |
|
152 | - * Return logger instance. |
|
153 | - */ |
|
154 | - public function getLogger(); |
|
19 | + /** |
|
20 | + * Initiate the appropriate protocol and process/automate the authentication or authorization flow. |
|
21 | + * |
|
22 | + * @return bool|null |
|
23 | + */ |
|
24 | + public function authenticate(); |
|
25 | + |
|
26 | + /** |
|
27 | + * Returns TRUE if the user is connected |
|
28 | + * |
|
29 | + * @return bool |
|
30 | + */ |
|
31 | + public function isConnected(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Clear all access token in storage |
|
35 | + */ |
|
36 | + public function disconnect(); |
|
37 | + |
|
38 | + /** |
|
39 | + * Retrieve the connected user profile |
|
40 | + * |
|
41 | + * @return \Hybridauth\User\Profile |
|
42 | + */ |
|
43 | + public function getUserProfile(); |
|
44 | + |
|
45 | + /** |
|
46 | + * Retrieve the connected user contacts list |
|
47 | + * |
|
48 | + * @return \Hybridauth\User\Contact[] |
|
49 | + */ |
|
50 | + public function getUserContacts(); |
|
51 | + |
|
52 | + /** |
|
53 | + * Retrieve the connected user pages|companies|groups list |
|
54 | + * |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function getUserPages(); |
|
58 | + |
|
59 | + /** |
|
60 | + * Retrieve the user activity stream |
|
61 | + * |
|
62 | + * @param string $stream |
|
63 | + * |
|
64 | + * @return \Hybridauth\User\Activity[] |
|
65 | + */ |
|
66 | + public function getUserActivity($stream); |
|
67 | + |
|
68 | + /** |
|
69 | + * Post a status on user wall|timeline|blog|website|etc. |
|
70 | + * |
|
71 | + * @param string|array $status |
|
72 | + * |
|
73 | + * @return mixed API response |
|
74 | + */ |
|
75 | + public function setUserStatus($status); |
|
76 | + |
|
77 | + /** |
|
78 | + * Post a status on page|company|group wall. |
|
79 | + * |
|
80 | + * @param string|array $status |
|
81 | + * @param string $pageId |
|
82 | + * |
|
83 | + * @return mixed API response |
|
84 | + */ |
|
85 | + public function setPageStatus($status, $pageId); |
|
86 | + |
|
87 | + /** |
|
88 | + * Send a signed request to provider API |
|
89 | + * |
|
90 | + * @param string $url |
|
91 | + * @param string $method |
|
92 | + * @param array $parameters |
|
93 | + * @param array $headers |
|
94 | + * @param bool $multipart |
|
95 | + * |
|
96 | + * @return mixed |
|
97 | + */ |
|
98 | + public function apiRequest($url, $method = 'GET', $parameters = [], $headers = [], $multipart = false); |
|
99 | + |
|
100 | + /** |
|
101 | + * Do whatever may be necessary to make sure tokens do not expire. |
|
102 | + * Intended to be be called frequently, e.g. via Cron. |
|
103 | + */ |
|
104 | + public function maintainToken(); |
|
105 | + |
|
106 | + /** |
|
107 | + * Return oauth access tokens. |
|
108 | + * |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public function getAccessToken(); |
|
112 | + |
|
113 | + /** |
|
114 | + * Set oauth access tokens. |
|
115 | + * |
|
116 | + * @param array $tokens |
|
117 | + */ |
|
118 | + public function setAccessToken($tokens = []); |
|
119 | + |
|
120 | + /** |
|
121 | + * Set http client instance. |
|
122 | + * |
|
123 | + * @param HttpClientInterface $httpClient |
|
124 | + */ |
|
125 | + public function setHttpClient(HttpClientInterface $httpClient = null); |
|
126 | + |
|
127 | + /** |
|
128 | + * Return http client instance. |
|
129 | + */ |
|
130 | + public function getHttpClient(); |
|
131 | + |
|
132 | + /** |
|
133 | + * Set storage instance. |
|
134 | + * |
|
135 | + * @param StorageInterface $storage |
|
136 | + */ |
|
137 | + public function setStorage(StorageInterface $storage = null); |
|
138 | + |
|
139 | + /** |
|
140 | + * Return storage instance. |
|
141 | + */ |
|
142 | + public function getStorage(); |
|
143 | + |
|
144 | + /** |
|
145 | + * Set Logger instance. |
|
146 | + * |
|
147 | + * @param LoggerInterface $logger |
|
148 | + */ |
|
149 | + public function setLogger(LoggerInterface $logger = null); |
|
150 | + |
|
151 | + /** |
|
152 | + * Return logger instance. |
|
153 | + */ |
|
154 | + public function getLogger(); |
|
155 | 155 | } |