Skip to content

Commit

Permalink
Request Setter.
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jan 7, 2016
1 parent 30d7f00 commit df59605
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,42 @@ The `$user->getOriginal()` method will return an array of the API raw response.

You can get the access token instance of current session by call `$user->getToken` or `$user->getAccessToken()` or `$user['token']` .


### Custom Session or Request instance.

You can set the request with your custom `Request` instance which instanceof `Symfony\Component\HttpFoundation\Request`.


```php

$request = new Request(); // or use AnotherCustomRequest.

$socialite = new SocialiteManager($config, $request);
```

Or set request to `SocialiteManager` instance:

```php
$socialite->setRequest($request);
```

You can get the request from `SocialiteManager` instance by `getRequest()`:

```php
$request = $socialite->getRequest();
```

#### Set custom session manager.

By default, the `SocialiteManager` use `Symfony\Component\HttpFoundation\Session\Session` instance as session manager, you can change it as following lines:

```php
$session = new YouCustomSessionManager();
$socialite->getRequest()->setSession($session);
```

> Your custom session manager must be implement the `[Symfony\Component\HttpFoundation\Session\SessionInterface](http://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Session/SessionInterface.html)`.
Enjoy it! :heart:

# Reference
Expand Down
22 changes: 22 additions & 0 deletions src/SocialiteManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,26 @@ public function __call($method, $parameters)
{
return call_user_func_array([$this->driver(), $method], $parameters);
}

/**
* Set Request instance.
*
* @param Request $request
*/
public function setRequest(Request $request)
{
$this->request = $request;

return $this;
}

/**
* Return the request instance.
*
* @return \Symfony\Component\HttpFoundation\Request
*/
public function getRequest()
{
return $this->request;
}
}

0 comments on commit df59605

Please sign in to comment.