This repository has been archived by the owner on Aug 1, 2021. It is now read-only.
-
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.
Using Request/Response objects; added a new Templating class; using a…
… temporary exception handling in the skeleton project's index.php file
- Loading branch information
1 parent
2687353
commit ef48052
Showing
9 changed files
with
251 additions
and
262 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 was deleted.
Oops, something went wrong.
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,39 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2019-2020 Douglas Silva (0x9fd287d56ec107ac) | ||
* | ||
* This file is part of Fragments. | ||
* | ||
* Fragments is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Fragments. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Fragments\Component\Http; | ||
|
||
/** | ||
* An object-oriented representation of the HTTP response. | ||
*/ | ||
class RedirectResponse extends Response | ||
{ | ||
public function __construct(string $url) | ||
{ | ||
$headers = []; | ||
$content = ""; | ||
|
||
$content = "Redirecting to {$url}"; | ||
$headers['Location'] = $url; | ||
|
||
parent::__construct($content, 302, $headers); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2019-2020 Douglas Silva (0x9fd287d56ec107ac) | ||
* | ||
* This file is part of Fragments. | ||
* | ||
* Fragments is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Fragments. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Fragments\Component\Http; | ||
|
||
/** | ||
* An object-oriented representation of the HTTP request. | ||
*/ | ||
class Request | ||
{ | ||
public $post; | ||
|
||
public $get; | ||
|
||
public $server; | ||
|
||
public function __construct() | ||
{ | ||
$this->post = $_POST; | ||
$this->get = $_GET; | ||
$this->server = $_SERVER; | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2019-2020 Douglas Silva (0x9fd287d56ec107ac) | ||
* | ||
* This file is part of Fragments. | ||
* | ||
* Fragments is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Fragments. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Fragments\Component\Http; | ||
|
||
/** | ||
* An object-oriented representation of the HTTP response. | ||
*/ | ||
class Response | ||
{ | ||
public $content; | ||
|
||
public $statusCode; | ||
|
||
public $headers; | ||
|
||
public function __construct(string $content = '', int $statusCode = 200, array $headers = []) | ||
{ | ||
$this->content = $content; | ||
$this->statusCode = $statusCode; | ||
$this->headers = $headers; | ||
} | ||
|
||
public function send() | ||
{ | ||
$this->sendHeaders(); | ||
$this->sendContent(); | ||
} | ||
|
||
private function sendHeaders() | ||
{ | ||
foreach ($this->headers as $name => $value) { | ||
header("{$name}: {$value}", true, $this->statusCode); | ||
} | ||
|
||
http_response_code($this->statusCode); | ||
} | ||
|
||
private function sendContent() | ||
{ | ||
echo $this->content; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.