Skip to content

Commit

Permalink
thusfar
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmagicii committed Jun 22, 2024
1 parent e5d38d3 commit e312010
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 90 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"require": {
"php": "^8.1",
"netherphp/common": "dev-master as 5.0.98",
"netherphp/common": "dev-master",
"netherphp/console": "dev-redux"
},
"require-dev": {
Expand Down
131 changes: 131 additions & 0 deletions src/Nether/Avenue/Headers/HttpContentRange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php ##########################################################################
################################################################################

namespace Nether\Avenue\Headers;

use Nether\Avenue;
use Nether\Common;

################################################################################
################################################################################

class HttpContentRange {

public const
NameServerVar = 'HTTP_CONTENT_RANGE',
NameProtocol = 'content-range';

protected const
RegexContentRange = '/(bytes) ([\d]+)-([\d]+)\/([\d]+)/';

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

public string
$Unit = 'bytes';

public int
$Begin = 0;

public int
$End = 0;

public int
$Total = 0;

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

public function
Import(string $Data):
static {

$Bits = NULL;
$Result = preg_match(static::RegexContentRange, $Data, $Bits);

if(!$Result)
throw new Common\Error\RegexMatchFailure(
static::RegexContentRange,
$Data
);

////////

$this->Unit = $Bits[1];
$this->Begin = (int)$Bits[2];
$this->End = (int)$Bits[3];
$this->Total = (int)$Bits[4];

return $this;
}

public function
ReadFromEnv():
static {

// try the easy route if it is in a global var.

if(static::NameServerVar !== NULL)
if(isset($_SERVER[static::NameServerVar]))
return $this->Import($_SERVER[static::NameServerVar]);

// try a little harder by smelling headers.

$Heads = new Common\Datafilter(Avenue\Util::FetchRequestHeaders());

if($Heads->Exists('content-range'))
return $this->Import($Heads->Get('content-range'));

////////

throw new Common\Error\RequiredDataMissing(
'Content-Type', 'HTTP Header'
);

return $this;
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

static public function
From(string $Data):
?static {

$Output = NULL;
$Err = NULL;

////////

$Output = new static;
$Output->Import($Data);

////////

return $Output;
}

static public function
FromEnv():
?static {

$Output = NULL;
$Err = NULL;

////////

try {
$Output = new static;
$Output->ReadFromEnv();
}

catch(Common\Error\RequiredDataMissing $Err) {
return NULL;
}

////////

return $Output;
}

};
15 changes: 7 additions & 8 deletions src/Nether/Avenue/Struct/FormData.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,24 @@ protected function
$Output = [];
$Key = NULL;
$Val = NULL;
$Found = NULL;
$Fob = NULL;

////////

foreach($this->Fields as $Key => $Val) {

if(preg_match('/^(.+?)\[(.+?)\]$/', $Key, $Found)) {
if(!array_key_exists($Found[1], $Output))
$Output[$Found[1]] = [];
if(preg_match('/^(.+?)\[(.+?)\]$/', $Key, $Fob)) {
if(!array_key_exists($Fob[1], $Output))
$Output[$Fob[1]] = [];

$Output[$Found[1]][$Found[2]] = $Val;
$Output[$Fob[1]][$Fob[2]] = $Val;
continue;
}

$Output[$Key] = $Val;
continue;
}

//Common\Dump::Var($this->Fields);
//Common\Dump::Var($Output);

return Common\Datastore::FromArray($Output);
}

Expand Down
81 changes: 0 additions & 81 deletions src/Nether/Avenue/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,87 +194,6 @@ static public function
return $StupidFuckingTempVariable;
}

static public function
ParseMultipartData(?string $Input):
array {

// @todo 2024-06-06 after php 8.4 remove the third party library
// to use the new request_parse_body function.

$Req = MultipartFormDataParser\MultipartFormDataParser::parse();
$Output = [];
$Key = NULL;
$Val = NULL;
$Fob = NULL;

////////

foreach($Req->params as $Key => $Val) {

// handle ExtraData[Key] array hydration.
if(preg_match('#^(.+?)\[(.+?)\]$#i', $Key, $Fob)) {
if(!array_key_exists($Fob[1], $Output))
$Output[$Fob[1]] = [];

$Output[$Fob[1]][$Fob[2]] = $Val;
continue;
}

// default
$Output[$Key] = $Val;

continue;
}

// @todo 2024-06-06 fill in the files array this same way.

////////

return $Output;
}

static public function
ParseMultipartRequest():
array {

// @todo 2024-06-06 after php 8.4 remove the third party library
// to use the new request_parse_body function.

$Req = MultipartFormDataParser\MultipartFormDataParser::parse();
$Output = [];
$Key = NULL;
$Val = NULL;
$Fob = NULL;

////////

foreach($Req->params as $Key => $Val) {

// handle ExtraData[Key] array hydration.
if(preg_match('#^(.+?)\[(.+?)\]$#i', $Key, $Fob)) {
if(!array_key_exists($Fob[1], $Output))
$Output[$Fob[1]] = [];

$Output[$Fob[1]][$Fob[2]] = $Val;
continue;
}

// default
$Output[$Key] = $Val;

continue;
}

// @todo 2024-06-06 fill in the files array this same way.

////////

return [
new Common\Datafilter($Output),
new Common\Datafilter($Req->files)
];
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

Expand Down

0 comments on commit e312010

Please sign in to comment.