-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: complete Superglobals implementation
#9858
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
base: 4.7
Are you sure you want to change the base?
Changes from all commits
d60b0ab
1b1440f
0383f06
d4977d0
b3eb0cc
294e62e
2cc0e58
5ba09f2
670bbe5
9a583f2
d3bd139
fd4bf4a
79091a3
84c9cef
770afff
519e2a3
3303443
863789d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -86,7 +86,7 @@ final class Environment extends BaseCommand | |||||
| public function run(array $params) | ||||||
| { | ||||||
| if ($params === []) { | ||||||
| CLI::write(sprintf('Your environment is currently set as %s.', CLI::color($_SERVER['CI_ENVIRONMENT'] ?? ENVIRONMENT, 'green'))); | ||||||
| CLI::write(sprintf('Your environment is currently set as %s.', CLI::color(service('superglobals')->server('CI_ENVIRONMENT') ?? ENVIRONMENT, 'green'))); | ||||||
| CLI::newLine(); | ||||||
|
|
||||||
| return EXIT_ERROR; | ||||||
|
|
@@ -119,7 +119,8 @@ public function run(array $params) | |||||
| // force DotEnv to reload the new environment | ||||||
| // however we cannot redefine the ENVIRONMENT constant | ||||||
| putenv('CI_ENVIRONMENT'); | ||||||
| unset($_ENV['CI_ENVIRONMENT'], $_SERVER['CI_ENVIRONMENT']); | ||||||
| unset($_ENV['CI_ENVIRONMENT']); | ||||||
| service('superglobals')->unsetServer('CI_ENVIRONMENT'); | ||||||
| (new DotEnv((new Paths())->envDirectory ?? ROOTPATH))->load(); | ||||||
|
|
||||||
| CLI::write(sprintf('Environment is successfully changed to "%s".', $env), 'green'); | ||||||
|
|
@@ -149,7 +150,7 @@ private function writeNewEnvironmentToEnvFile(string $newEnv): bool | |||||
| copy($baseEnv, $envFile); | ||||||
| } | ||||||
|
|
||||||
| $pattern = preg_quote($_SERVER['CI_ENVIRONMENT'] ?? ENVIRONMENT, '/'); | ||||||
| $pattern = preg_quote(service('superglobals')->server('CI_ENVIRONMENT') ?? ENVIRONMENT, '/'); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| $pattern = sprintf('/^[#\s]*CI_ENVIRONMENT[=\s]+%s$/m', $pattern); | ||||||
|
|
||||||
| return file_put_contents( | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -543,7 +543,7 @@ public static function createRequest(App $config, bool $isCli = false): void | |||||
| $request = AppServices::incomingrequest($config); | ||||||
|
|
||||||
| // guess at protocol if needed | ||||||
| $request->setProtocolVersion($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1'); | ||||||
| $request->setProtocolVersion(static::superglobals()->server('SERVER_PROTOCOL') ?? 'HTTP/1.1'); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| // Inject the request object into Services. | ||||||
|
|
@@ -746,13 +746,17 @@ public static function siteurifactory( | |||||
| public static function superglobals( | ||||||
| ?array $server = null, | ||||||
| ?array $get = null, | ||||||
| ?array $post = null, | ||||||
| ?array $cookie = null, | ||||||
| ?array $files = null, | ||||||
| ?array $request = null, | ||||||
| bool $getShared = true, | ||||||
| ) { | ||||||
| if ($getShared) { | ||||||
| return static::getSharedInstance('superglobals', $server, $get); | ||||||
| return static::getSharedInstance('superglobals', $server, $get, $post, $cookie, $files, $request); | ||||||
| } | ||||||
|
|
||||||
| return new Superglobals($server, $get); | ||||||
| return new Superglobals($server, $get, $post, $cookie, $files, $request); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -86,19 +86,21 @@ public function appendBody($data): self | |||||
| */ | ||||||
| public function populateHeaders(): void | ||||||
| { | ||||||
| $contentType = $_SERVER['CONTENT_TYPE'] ?? getenv('CONTENT_TYPE'); | ||||||
| $contentType = service('superglobals')->server('CONTENT_TYPE') ?? getenv('CONTENT_TYPE'); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| if (! empty($contentType)) { | ||||||
| $this->setHeader('Content-Type', $contentType); | ||||||
| } | ||||||
| unset($contentType); | ||||||
|
|
||||||
| foreach (array_keys($_SERVER) as $key) { | ||||||
| $serverArray = service('superglobals')->getServerArray(); | ||||||
|
|
||||||
| foreach (array_keys($serverArray) as $key) { | ||||||
| if (sscanf($key, 'HTTP_%s', $header) === 1) { | ||||||
| // take SOME_HEADER and turn it into Some-Header | ||||||
| $header = str_replace('_', ' ', strtolower($header)); | ||||||
| $header = str_replace(' ', '-', ucwords($header)); | ||||||
|
|
||||||
| $this->setHeader($header, $_SERVER[$key]); | ||||||
| $this->setHeader($header, $serverArray[$key]); | ||||||
|
|
||||||
| // Add us to the header map, so we can find them case-insensitively | ||||||
| $this->headerMap[strtolower($header)] = $header; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -279,7 +279,7 @@ public function getPageURI(?int $page = null, string $group = 'default', bool $r | |||||
| } | ||||||
|
|
||||||
| if ($this->only !== null) { | ||||||
| $query = array_intersect_key($_GET, array_flip($this->only)); | ||||||
| $query = array_intersect_key(service('superglobals')->getGetArray(), array_flip($this->only)); | ||||||
|
|
||||||
| if (! $segment) { | ||||||
| $query[$this->groups[$group]['pageSelector']] = $page; | ||||||
|
|
@@ -411,8 +411,9 @@ protected function ensureGroup(string $group, ?int $perPage = null) | |||||
|
|
||||||
| $this->calculateCurrentPage($group); | ||||||
|
|
||||||
| if ($_GET !== []) { | ||||||
| $this->groups[$group]['uri'] = $this->groups[$group]['uri']->setQueryArray($_GET); | ||||||
| $get = service('superglobals')->getGetArray(); | ||||||
| if ($get !== []) { | ||||||
| $this->groups[$group]['uri'] = $this->groups[$group]['uri']->setQueryArray($get); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -433,7 +434,7 @@ protected function calculateCurrentPage(string $group) | |||||
| } else { | ||||||
| $pageSelector = $this->groups[$group]['pageSelector']; | ||||||
|
|
||||||
| $page = (int) ($_GET[$pageSelector] ?? 1); | ||||||
| $page = (int) (service('superglobals')->get($pageSelector) ?? 1); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| $this->groups[$group]['currentPage'] = $page < 1 ? 1 : $page; | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.