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.
- Loading branch information
1 parent
025c1ff
commit db84d0a
Showing
13 changed files
with
238 additions
and
39 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/Fragments/Bundle/Exception/AccessDeniedHttpException.php
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,30 @@ | ||
<?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\Bundle\Exception; | ||
|
||
class AccessDeniedHttpException extends HttpException | ||
{ | ||
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0) | ||
{ | ||
parent::__construct(403, $message, $previous, $code); | ||
} | ||
} |
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\Bundle\Exception; | ||
|
||
class HttpException extends \RuntimeException | ||
{ | ||
private $statusCode; | ||
|
||
public function __construct(int $statusCode, string $message = null, \Throwable $previous = null, ?int $code = 0) | ||
{ | ||
$this->statusCode = $statusCode; | ||
|
||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
public function getStatusCode(): int | ||
{ | ||
return $this->statusCode; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Fragments/Bundle/Exception/MethodNotAllowedHttpException.php
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,32 @@ | ||
<?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\Bundle\Exception; | ||
|
||
class MethodNotAllowedHttpException extends HttpException | ||
{ | ||
public function __construct(\Throwable $previous = null, int $code = 0) | ||
{ | ||
$message = 'Method not allowed.'; | ||
|
||
parent::__construct(405, $message, $previous, $code); | ||
} | ||
} |
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,30 @@ | ||
<?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\Bundle\Exception; | ||
|
||
class NotFoundHttpException extends HttpException | ||
{ | ||
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0) | ||
{ | ||
parent::__construct(404, $message, $previous, $code); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Fragments/Bundle/Exception/ServerErrorHttpException.php
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,30 @@ | ||
<?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\Bundle\Exception; | ||
|
||
class ServerErrorHttpException extends HttpException | ||
{ | ||
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0) | ||
{ | ||
parent::__construct(500, $message, $previous, $code); | ||
} | ||
} |
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,45 @@ | ||
<?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; | ||
|
||
/** | ||
* Converts all PHP errors to exceptions. | ||
*/ | ||
class ExceptionHandler | ||
{ | ||
public function handler($severity, $message, $file, $line) | ||
{ | ||
if (!(error_reporting() & $severity)) { | ||
// This error code is not included in error_reporting | ||
return; | ||
} | ||
|
||
// FIXME: handle different severities differently | ||
|
||
throw new \ErrorException($message, 0, $severity, $file, $line); | ||
} | ||
|
||
public function setHandler() | ||
{ | ||
set_error_handler([$this, 'handler']); | ||
} | ||
} |
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
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
Oops, something went wrong.