Skip to content

Commit 675aff1

Browse files
committed
Revert "Merge branch 'master' into master-yoda"
This reverts commit 0474e58, reversing changes made to 537814b.
1 parent 93a36e2 commit 675aff1

26 files changed

Lines changed: 280 additions & 718 deletions

composer.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"fzaninotto/faker": "1.*",
2121
"filp/whoops": "2.*",
2222
"tgalopin/html-sanitizer": "dev-master",
23-
"ezyang/htmlpurifier": "dev-master",
24-
"ext-json": "*"
23+
"ezyang/htmlpurifier": "dev-master"
2524
},
2625
"require-dev": {
2726
"maximebf/debugbar": "1.*",
@@ -53,14 +52,11 @@
5352
"vendor/bin/phpcs --extensions=php --warning-severity=8 --error-severity=1 --standard=PSR12 --parallel=2 -p src/",
5453
"vendor/bin/codecept run"
5554
],
56-
"applycsandpatch": [
57-
"composer autofix && composer autopatch"
58-
],
5955
"autofix": [
6056
"vendor/bin/phpcs --extensions=php --report-diff=phpcs.diff --warning-severity=8 --error-severity=1 --standard=PSR12 --parallel=2 -p src/"
6157
],
6258
"autopatch": [
63-
"patch -p0 -ui phpcs.diff ; rm phpcs.diff"
59+
"patch -p0 -ui phpcs.diff && rm phpcs.diff"
6460
]
6561
},
6662
"scripts-descriptions": {

composer.lock

Lines changed: 80 additions & 173 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Pckg/Framework/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function get($key = null, $default = null)
3434
if (strpos($key, '.')) {
3535
$keys = explode('.', $key);
3636

37-
return getDotted($this->data, $keys, 0, $default);
37+
return getDotted($this->data, $keys);
3838
}
3939

4040
return $default;

src/Pckg/Framework/Helper/functions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ function app()
7575
}
7676

7777
if (!function_exists('getDotted')) {
78-
function getDotted($data, $keys, $i = 0, $default = null)
78+
function getDotted($data, $keys, $i = 0)
7979
{
8080
if (!isset($keys[$i])) {
8181
return $data;
8282
} elseif (isset($data[$keys[$i]])) {
83-
return getDotted($data[$keys[$i]], $keys, $i + 1, $default);
83+
return getDotted($data[$keys[$i]], $keys, $i + 1);
8484
}
8585

86-
return $default;
86+
return null;
8787
}
8888
}
8989

@@ -455,7 +455,7 @@ function flash($key, $val)
455455
*/
456456
function config($key = null, $default = null)
457457
{
458-
$config = context()->getOrCreate(Config::class);
458+
$config = context()->get(Config::class);
459459

460460
if ($key) {
461461
return $config->get($key) ?? $default;

src/Pckg/Framework/Reflect/FrameworkResolver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ public function resolve($class)
8080

8181
if (class_exists($class)) {
8282
if (in_array($class, static::$singletones)) {
83-
$mockedClass = config('pckg.reflect.singletones.' . $class, $class);
84-
$newInstance = Reflect::create($mockedClass);
83+
$newInstance = Reflect::create($class);
8584

8685
context()->bind($class, $newInstance);
8786

src/Pckg/Framework/Request.php

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
use Pckg\Concept\Reflect;
66
use Pckg\Framework\Helper\Lazy;
77
use Pckg\Framework\Request\Data\Cookie;
8-
use Pckg\Framework\Request\Data\Get;
98
use Pckg\Framework\Request\Data\Post;
109
use Pckg\Framework\Request\Data\Server;
11-
use Pckg\Framework\Request\Data\Session;
12-
use Pckg\Framework\Request\Data\Request as DataRequest;
1310
use Pckg\Framework\Request\Message;
1411
use Psr\Http\Message\RequestInterface;
1512
use Psr\Http\Message\ServerRequestInterface;
@@ -56,21 +53,55 @@ class Request extends Message implements RequestInterface, ServerRequestInterfac
5653
*/
5754
protected $uri;
5855

59-
public function __construct()
56+
public function __construct($input = [])
6057
{
6158
Reflect::method($this, 'initDependencies');
6259

63-
$this->server = (new Server())->setFromGlobals();
64-
$this->request = (new DataRequest())->setFromGlobals();
65-
$this->post = (new Post())->setFromGlobals();
66-
$this->get = (new Get())->setFromGlobals();
67-
$this->cookie = (new Cookie())->setFromGlobals();
68-
$this->files = (new Lazy());
60+
if (!$input) {
61+
$input = file_get_contents('php://input');
62+
if ($input && (strpos($input, '{') === 0 && strrpos($input, '}') === strlen($input) - 1)) {
63+
$input = json_decode($input, true);
64+
} elseif ($input) {
65+
parse_str($input, $input);
66+
} else {
67+
$input = [];
68+
}
69+
}
70+
71+
if (!$input && $_POST) {
72+
/**
73+
* Why is php input sometimes empty?
74+
*/
75+
$input = $_POST;
76+
}
77+
78+
$this->setPost($input);
79+
$this->get = new Lazy($_GET);
80+
$this->server = new Server($_SERVER);
81+
$this->files = new Lazy($_FILES);
82+
$this->cookie = new Cookie($_COOKIE);
83+
$this->request = new Lazy($_REQUEST);
84+
85+
$this->fetchUrl();
86+
6987
$this->headers = collect(getallheaders())->groupBy(function ($value, $key) {
7088
return $key;
7189
})->all();
90+
}
91+
92+
public function setConstructs($post, $get, $server, $files, $cookie, $request, $headers = [])
93+
{
94+
$this->setPost($post);
95+
$this->get = new Lazy($get);
96+
$this->server = new Lazy($server);
97+
$this->files = new Lazy($files);
98+
$this->cookie = new Cookie($cookie);
99+
$this->request = new Lazy($request);
100+
$this->headers = $headers;
72101

73102
$this->fetchUrl();
103+
104+
return $this;
74105
}
75106

76107
/**
@@ -155,77 +186,46 @@ public function post($key = null, $default = [])
155186
return $this->post->get($key, $default);
156187
}
157188

158-
/**
159-
* @param $object
160-
* @param null $key
161-
* @param array $default
162-
* @return Lazy|mixed
163-
*/
164-
private function getOrFull($object, $key = null, $default = [])
165-
{
166-
return is_null($key)
167-
? $object
168-
: $object->get($key, $default);
169-
}
170-
171-
/**
172-
* @param null $key
173-
* @param array $default
174-
* @return Get|mixed
175-
*/
176189
public function get($key = null, $default = [])
177190
{
178-
return $this->getOrFull($this->get, $key, $default);
191+
return is_null($key)
192+
? $this->get
193+
: $this->get->get($key, $default);
179194
}
180195

181-
/**
182-
* @param null $key
183-
* @param array $default
184-
* @return Server|mixed
185-
*/
186196
public function server($key = null, $default = [])
187197
{
188-
return $this->getOrFull($this->server, $key, $default);
198+
return is_null($key)
199+
? $this->server
200+
: $this->server->get($key, $default);
189201
}
190202

191-
/**
192-
* @param null $key
193-
* @param array $default
194-
* @return Cookie|mixed
195-
*/
196203
public function cookie($key = null, $default = [])
197204
{
198-
return $this->getOrFull($this->cookie, $key, $default);
205+
return is_null($key)
206+
? $this->cookie
207+
: $this->cookie->get($key, $default);
199208
}
200209

201-
/**
202-
* @param null $key
203-
* @param array $default
204-
* @return Session|mixed
205-
*/
206210
public function session($key = null, $default = [])
207211
{
208-
return $this->getOrFull($this->session, $key, $default);
212+
return is_null($key)
213+
? $this->session
214+
: $this->session->get($key, $default);
209215
}
210216

211-
/**
212-
* @param null $key
213-
* @param array $default
214-
* @return \Pckg\Htmlbuilder\Datasource\Method\Request|mixed
215-
*/
216217
public function request($key = null, $default = [])
217218
{
218-
return $this->getOrFull($this->request, $key, $default);
219+
return is_null($key)
220+
? $this->request
221+
: $this->request->get($key, $default);
219222
}
220223

221-
/**
222-
* @param null $key
223-
* @param array $default
224-
* @return Lazy|mixed
225-
*/
226-
public function files($key = null, $default = [])
224+
public function files($key = null)
227225
{
228-
return $this->getOrFull($this->files, $key, $default);
226+
return is_null($key)
227+
? $this->files
228+
: $this->files->get($key);
229229
}
230230

231231
public function isMethod($method)
@@ -530,7 +530,7 @@ public function withParsedBody($data)
530530
*/
531531
public function getAttributes()
532532
{
533-
return $this->post()->all();
533+
return [];
534534
}
535535

536536
/**
@@ -540,7 +540,6 @@ public function getAttributes()
540540
*/
541541
public function getAttribute($name, $default = null)
542542
{
543-
return $this->post()->get($name, $default);
544543
return $this->attributes[$name] ?? $default;
545544
}
546545

@@ -551,8 +550,7 @@ public function getAttribute($name, $default = null)
551550
*/
552551
public function withAttribute($name, $value)
553552
{
554-
$this->post()->set($name, $value);
555-
// $this->attributes[$name] = $value;
553+
$this->attributes[$name] = $value;
556554

557555
return $this;
558556
}
@@ -563,8 +561,7 @@ public function withAttribute($name, $value)
563561
*/
564562
public function withoutAttribute($name)
565563
{
566-
unset($this->post()[$name]);
567-
//unset($this->attributes[$name]);
564+
unset($this->attributes[$name]);
568565

569566
return $this;
570567
}

src/Pckg/Framework/Request/Data/Cookie.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ class Cookie extends Lazy
1313
const DURATION_MONTH = 2592000;
1414
// 30 days
1515

16-
public function setFromGlobals()
16+
public function __construct(array $arr = [])
1717
{
18-
$this->setData($_COOKIE);
19-
20-
return $this;
18+
parent::__construct($_COOKIE ?? $arr);
2119
}
2220

2321
public function set($name, $value = '', $expiration = self::DURATION_MONTH, $path = '/', $domain = '')

src/Pckg/Framework/Request/Data/Get.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
class Get extends Lazy
88
{
99

10-
public function setFromGlobals()
10+
public function __construct($arr = [])
1111
{
12-
$this->setData($_GET);
12+
parent::__construct($_GET ?? $arr);
13+
}
1314

14-
return $this;
15+
public function __destruct()
16+
{
17+
$_GET = $this->data;
1518
}
1619
}

src/Pckg/Framework/Request/Data/Post.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,17 @@
33
namespace Pckg\Framework\Request\Data;
44

55
use Pckg\Framework\Helper\Lazy;
6-
use Pckg\Framework\Request\Data\PostResolver\Globals;
7-
use Pckg\Framework\Request\Data\PostResolver\PostSource;
86

97
class Post extends Lazy
108
{
119

12-
protected $source = Globals::class;
13-
14-
public function setSource(PostSource $postSource)
10+
public function __construct($arr = [])
1511
{
16-
$this->source = $postSource;
17-
18-
return $this;
12+
parent::__construct($arr ?? $_POST);
1913
}
2014

21-
public function getSource()
15+
public function __destruct()
2216
{
23-
if (is_string($this->source)) {
24-
$this->source = resolve($this->source);
25-
}
26-
27-
return $this->source;
28-
}
29-
30-
public function setFromGlobals()
31-
{
32-
$this->setData($this->getSource()->readFromSource());
33-
34-
return $this;
17+
//$_POST = $this->data;
3518
}
3619
}

src/Pckg/Framework/Request/Data/PostResolver/Globals.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)