-
Notifications
You must be signed in to change notification settings - Fork 784
[11.x] Custom authorization view response #1629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
taylorotwell
merged 20 commits into
laravel:11.x
from
jonerickson:authorize-view-reponse
Feb 16, 2023
Merged
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
75f8d36
Implements authorization view response contract that allows for being…
jonerickson 56c6b8e
Updated namespace
jonerickson 69c0af5
Updated namespace
jonerickson 9b005f4
Moved individual arguments to an array of parameters and one argument
jonerickson d2a2955
Removed authorize return type
jonerickson 061f2b3
Remove old return statement
jonerickson 8c570c6
Add IntelliJ IDE files to gitignore
jonerickson 6807208
Merge remote-tracking branch 'origin/11.x' into authorize-view-reponse
jonerickson a101db4
Formatting
jonerickson b9bc70a
Update tests
jonerickson 7da24a2
Update rest of tests with new response class
jonerickson 39b07c1
Style fixes and make sure parameters pushed to authorization view are…
jonerickson af62ae8
Remove parameters from authorization view function
jonerickson 4b0fbcb
Update .gitignore
driesvints 56f5e96
Update src/Contracts/AuthorizationViewResponse.php
jonerickson 5994cd6
Update src/Http/Responses/AuthorizationViewResponse.php
jonerickson b4e7cf2
Updated doc block return types
jonerickson 2eadf1e
Merge branch '11.x' into authorize-view-reponse
jonerickson 91bdd57
formatting
taylorotwell 254b425
remove extra line
taylorotwell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Laravel\Passport\Contracts; | ||
|
||
use Illuminate\Contracts\Support\Responsable; | ||
|
||
interface AuthorizationViewResponse extends Responsable | ||
{ | ||
/** | ||
* @param array $parameters | ||
* @return mixed | ||
*/ | ||
public function withParameters($parameters = []); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Laravel\Passport\Http\Responses; | ||
|
||
use Illuminate\Contracts\Support\Responsable; | ||
use Laravel\Passport\Contracts\AuthorizationViewResponse as AuthorizationViewResponseContract; | ||
|
||
class AuthorizationViewResponse implements AuthorizationViewResponseContract | ||
{ | ||
/** | ||
* The name of the view or the callable used to generate the view. | ||
* | ||
* @var string | ||
*/ | ||
protected $view; | ||
|
||
/** | ||
* An array of arguments that may be passed to the view response and used in the view. | ||
* | ||
* @var string | ||
*/ | ||
protected $parameters; | ||
|
||
/** | ||
* Create a new response instance. | ||
* | ||
* @param callable|string $view | ||
* @return void | ||
*/ | ||
public function __construct($view) | ||
{ | ||
$this->view = $view; | ||
} | ||
|
||
/** | ||
* Add parameters to response. | ||
* | ||
* @param $parameters | ||
* @return $this | ||
*/ | ||
public function withParameters($parameters = []) | ||
{ | ||
$this->parameters = $parameters; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Create an HTTP response that represents the object. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function toResponse($request) | ||
{ | ||
if (! is_callable($this->view) || is_string($this->view)) { | ||
return view($this->view, [...$this->parameters]); | ||
} | ||
|
||
$response = call_user_func($this->view, ...$this->parameters); | ||
|
||
if ($response instanceof Responsable) { | ||
return $response->toResponse($request); | ||
} | ||
|
||
return $response; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.