-
Notifications
You must be signed in to change notification settings - Fork 29
Feature: Add request context providers for long-lived runtimes #96
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
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0516984
Add request context interface
glensc ba08d51
Add request context value object
glensc fa24094
Add request context provider interface
glensc 3989357
Add default request context provider
glensc 0294991
Add request context factory
glensc 54c6bd6
Add request context provider hooks
glensc 21fbf02
Use request context in profiling data
glensc 1b3b284
Update autoload for request context classes
glensc 040484b
Document request context providers
glensc 122942b
Add createRequestContextObject helper to TestCase
glensc 26eec29
Tests: Adapt env tests to request context
glensc f6445ca
Test: Add TestProfilerStub stub
glensc 24d12ec
Test: Add setPrivateProperty, getPrivateProperty helpers
glensc d692834
Test: Add disable regression test
glensc 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
|
|
||
| namespace Xhgui\Profiler\RequestContext\Provider; | ||
|
|
||
| use Xhgui\Profiler\RequestContext\RequestContext; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| class DefaultProvider implements RequestContextProviderInterface | ||
| { | ||
| public function capture() | ||
| { | ||
| $server = $_SERVER; | ||
|
|
||
| // 'REQUEST_TIME_FLOAT' isn't available before 5.4.0 | ||
| // https://www.php.net/manual/en/reserved.variables.server.php | ||
| if (!isset($server['REQUEST_TIME_FLOAT'])) { | ||
| $server['REQUEST_TIME_FLOAT'] = microtime(true); | ||
| } | ||
| if (!isset($server['REQUEST_TIME'])) { | ||
| $server['REQUEST_TIME'] = (int) $server['REQUEST_TIME_FLOAT']; | ||
| } | ||
|
|
||
| if (array_key_exists('REQUEST_URI', $server)) { | ||
| return RequestContext::fromHttp( | ||
| $server['REQUEST_URI'], | ||
| $_GET, | ||
| $_ENV, | ||
| $server | ||
| ); | ||
| } | ||
|
|
||
| return RequestContext::fromCli( | ||
| $this->getCommand(isset($server['argv']) ? $server['argv'] : array()), | ||
| $_ENV, | ||
| $server | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param array $argv | ||
| * @return string | ||
| */ | ||
| private function getCommand(array $argv) | ||
| { | ||
| if (!isset($argv[0])) { | ||
| return ''; | ||
| } | ||
|
|
||
| $cmd = basename($argv[0]); | ||
| $args = array_slice($argv, 1); | ||
|
|
||
| if (!$args) { | ||
| return $cmd; | ||
| } | ||
|
|
||
| return $cmd . ' ' . implode(' ', $args); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/RequestContext/Provider/RequestContextProviderInterface.php
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,18 @@ | ||
| <?php | ||
|
|
||
| namespace Xhgui\Profiler\RequestContext\Provider; | ||
|
|
||
| use Xhgui\Profiler\RequestContext\RequestContextInterface; | ||
|
|
||
| interface RequestContextProviderInterface | ||
| { | ||
| /** | ||
| * Capture request-scoped profiler metadata. | ||
| * | ||
| * Implementations should return a request-context object whose request time | ||
| * and server snapshot describe the same request. | ||
| * | ||
| * @return RequestContextInterface | ||
| */ | ||
| public function capture(); | ||
| } |
Oops, something went wrong.
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.