Conversation
eldadfux
approved these changes
Jan 3, 2022
Comment on lines
+12
to
+50
| private static $params = null; | ||
|
|
||
| /** | ||
| * Get Param | ||
| * | ||
| * Get param by current method name | ||
| * | ||
| * @param string $key | ||
| * @param mixed $default | ||
| * @return mixed | ||
| */ | ||
| public function getParam(string $key, $default = null): mixed | ||
| { | ||
| if($this::_hasParams() && \in_array($key, $this::_getParams())) { | ||
| return $this::_getParams()[$key]; | ||
| } | ||
|
|
||
| return parent::getParam($key, $default); | ||
| } | ||
|
|
||
| /** | ||
| * Get Params | ||
| * | ||
| * Get all params of current method | ||
| * | ||
| * @return array | ||
| */ | ||
| public function getParams(): array | ||
| { | ||
| $paramsArray = []; | ||
|
|
||
| if($this::_hasParams()) { | ||
| $paramsArray = $this::_getParams(); | ||
| } | ||
|
|
||
| return \array_merge($paramsArray, parent::getParams()); | ||
| } | ||
|
|
||
|
|
Contributor
There was a problem hiding this comment.
If you are extending the request class only to add a setParams function, we only need to override the setParams method. Is there a reason you have implemented all the other methods as well ?
christyjacob4
approved these changes
Jan 4, 2022
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This allows running code that required
->match()before Utopia gets parameters. This is important, because you cannot write such a code before running->run(), because at the top ofrunwe do some sorting of$routes, and for that to work properly, we need to run->match()after running this sorting.Opened questions
Not sure how to re-write tests. A lot of tests send empty args array, some send specific args that we test. I also removed the default value that can cause some troubles.