1 | <?php |
||
15 | /** |
||
16 | * ID of the sessionDataCookie |
||
17 | */ |
||
18 | const cookieName = "azine_hybridauth_session"; |
||
19 | |||
20 | /** |
||
21 | * @var ObjectManager |
||
22 | */ |
||
23 | private $objectManager; |
||
24 | |||
25 | /** |
||
26 | * @var UserInterface |
||
27 | */ |
||
28 | private $currentUser; |
||
29 | |||
30 | /** |
||
31 | * @var bool |
||
32 | */ |
||
33 | private $storeForUser; |
||
34 | |||
35 | /** |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $storeAsCookie; |
||
39 | |||
40 | /** |
||
41 | * @var int |
||
42 | */ |
||
43 | private $expiresInDays; |
||
44 | |||
45 | /** |
||
46 | * Configured Instances of HybridAuth |
||
47 | * @var array or HybridAuth |
||
48 | */ |
||
49 | private $instances = array(); |
||
50 | |||
51 | /** |
||
52 | * HybridAuth configuration |
||
53 | * @var array |
||
54 | */ |
||
55 | private $config; |
||
56 | |||
57 | /** |
||
58 | * |
||
59 | * @param UrlGeneratorInterface $router |
||
60 | * @param TokenStorageInterface $tokenStorage |
||
61 | * @param ObjectManager $manager |
||
62 | * @param array $config |
||
63 | * @param bool $storeForUser |
||
64 | * @param $storeAsCookie |
||
65 | * @param $expiresInDays |
||
66 | */ |
||
67 | public function __construct(UrlGeneratorInterface $router, TokenStorageInterface $tokenStorage, ObjectManager $manager, $config, $storeForUser, $storeAsCookie, $expiresInDays){ |
||
68 | $base_url = $router->generate($config[AzineHybridAuthExtension::ENDPOINT_ROUTE], array(), UrlGeneratorInterface::ABSOLUTE_URL); |
||
81 | |||
82 | /** |
||
83 | * Get a Hybrid_Auth instance initialised for the given provider. |
||
84 | * HybridAuthSessions will be restored from DB and/or cookies, according to the bundle configuration. |
||
85 | * |
||
86 | * @param $cookieSessionData |
||
87 | * @param $provider |
||
88 | * @return \Hybrid_Auth |
||
89 | */ |
||
90 | public function getInstance($cookieSessionData, $provider){ |
||
91 | if(array_key_exists($provider, $this->instances)){ |
||
136 | * @param $provider |
||
137 | * @param $sessionData |
||
138 | * @return Cookie | null |
||
139 | */ |
||
140 | public function storeHybridAuthSessionData(Request $request, $provider, $sessionData){ |
||
141 | $this->saveAuthSessionData($sessionData, $provider); |
||
142 | |||
143 | if($this->storeAsCookie){ |
||
151 | * @param $provider |
||
152 | */ |
||
153 | public function deleteSession($provider){ |
||
154 | if($this->currentUser instanceof UserInterface) { |
||
155 | $result = $this->objectManager->getRepository("AzineHybridAuthBundle:HybridAuthSessionData")->findOneBy(array('username' => $this->currentUser->getUsername(), 'provider' => $provider)); |
||
156 | if ($result) { |
||
165 | * Checks the bundle configuration before saving. |
||
166 | * @param $sessionData |
||
167 | * @param $provider |
||
168 | */ |
||
169 | private function saveAuthSessionData($sessionData, $provider){ |
||
170 | if($this->storeForUser && $this->currentUser instanceof UserInterface) { |
||
171 | $hybridAuthData = $this->objectManager->getRepository("AzineHybridAuthBundle:HybridAuthSessionData")->findOneBy(array('username' => $this->currentUser->getUsername(), 'provider' => strtolower($provider))); |
||
172 | if (!$hybridAuthData) { |
||
190 | * |
||
191 | * Calling this method will log the user in (make a roundtrip to the providers site and back to your site again) |
||
194 | * When logged (allready) it will return the hybridAuth provider. |
||
195 | * |
||
196 | * @param $authSessionData |
||
197 | * @param string $provider_id |
||
198 | * @param boolean $require_login |
||
199 | * @return \Hybrid_Provider_Model |
||
200 | */ |
||
201 | public function getProvider($authSessionData, $provider_id, $require_login = true){ |
||
202 | $adapter = $this->getInstance($authSessionData, $provider_id)->getAdapter($provider_id); |
||
203 | if($require_login && !$adapter->isUserConnected()){ |
||
204 | $adapter->login(); |
||
205 | } |
||
206 | return $adapter; |
||
207 | } |
||
208 | |||
215 | public function isConnected(Request $request, $provider_id){ |
||
216 | $sessionData = $request->cookies->get($this->getCookieName($provider_id)); |
||
217 | $adapter = $this->getInstance($sessionData, $provider_id)->getAdapter($provider_id); |
||
218 | $connected = $adapter->isUserConnected(); |
||
219 | return $connected; |
||
220 | } |
||
221 | |||
222 | /** |
||
228 | } |
||
229 | |||
230 | /** |
||
231 | * Get the Xing api (OAuthClient) |
||
232 | * |
||
233 | * @return \OAuth1Client |
||
236 | return $this->getXing()->api(); |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Get the LinkedIn Adapter |
||
241 | * |
||
242 | * @return \Hybrid_Providers_LinkedIn |
||
245 | return $this->getProvider(null, "linkedin"); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * Get the LinkedIn api (LinkedIn PHP-client) |
||
250 | * |
||
251 | * @return \LinkedIn |
||
254 | return $this->getLinkedIn()->api(); |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * Get if auth token is expired |
||
259 | * @param HybridAuthSessionData $data |
||
260 | * |
||
263 | public function isExpiredSession(HybridAuthSessionData $data) |
||
264 | { |
||
265 | if($data->getExpiresAt() < new \DateTime()){ |
||
266 | |||
267 | return true; |
||
268 | } |
||
269 | |||
270 | return false; |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: