-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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,26 @@ | ||
<?php | ||
|
||
namespace Vendimia\Http\BodyParser; | ||
|
||
use Vendimia\Http\Request; | ||
use Vendimia\Exception\VendimiaException; | ||
use Exception; | ||
use JsonException; | ||
|
||
/** | ||
* Parse a multipart/form-data body to obtain the parsedBody | ||
* | ||
* @author Oliver Etchebarne <yo@drmad.org> | ||
*/ | ||
class FormData implements BodyParserInterface | ||
{ | ||
/** | ||
* FIXME: This should not use $_POST | ||
*/ | ||
public static function parseBody(Request $request): Request | ||
{ | ||
$request = $request->withParsedBody($_POST); | ||
|
||
return $request; | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
<?php | ||
|
||
namespace Vendimia\Http\BodyParser; | ||
|
||
use Vendimia\Http\Request; | ||
|
||
/** | ||
* Parses a url-encoded body to an array. | ||
* | ||
* @author Oliver Etchebarne <yo@drmad.org> | ||
*/ | ||
class Url implements BodyParserInterface | ||
{ | ||
public static function canDecode(string $mime): bool | ||
public static function parseBody(Request $request): Request | ||
{ | ||
return $mime == 'application/x-www-form-urlencoded'; | ||
} | ||
parse_str($request->getBody()->getContents(), $parsed_body); | ||
$request = $request->withParsedBody($parsed_body); | ||
|
||
public static function parse($source): array | ||
{ | ||
parse_str($source, $parsed_body); | ||
return $parsed_body; | ||
return $request; | ||
} | ||
} |
This file contains 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