Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from chubbyphp/api-problem
api-problem
- Loading branch information
Showing
135 changed files
with
5,167 additions
and
1,062 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
phpunit/ | ||
vendor/ | ||
composer.lock | ||
.php_cs.cache | ||
|
||
.DS_Store | ||
.idea/ | ||
.php_cs.cache | ||
.phpunit.result.cache | ||
.vscode/ | ||
build/ | ||
composer.lock | ||
composer.symlink | ||
phpunit | ||
phpunit.xml | ||
vendor/ |
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
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
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,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\ApiHttp\ApiProblem; | ||
|
||
abstract class AbstractApiProblem implements ApiProblemInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $title; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $detail; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $instance; | ||
|
||
/** | ||
* @param string $title | ||
* @param string|null $detail | ||
* @param string|null $instance | ||
*/ | ||
public function __construct(string $title, string $detail = null, string $instance = null) | ||
{ | ||
$this->title = $title; | ||
$this->detail = $detail; | ||
$this->instance = $instance; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getHeaders(): array | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTitle(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getDetail() | ||
{ | ||
return $this->detail; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getInstance() | ||
{ | ||
return $this->instance; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\ApiHttp\ApiProblem; | ||
|
||
interface ApiProblemInterface | ||
{ | ||
/** | ||
* @return int | ||
*/ | ||
public function getStatus(): int; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getHeaders(): array; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTitle(): string; | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getDetail(); | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getInstance(); | ||
} |
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\ApiHttp\ApiProblem\ClientError; | ||
|
||
use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem; | ||
|
||
final class BadRequest extends AbstractApiProblem | ||
{ | ||
/** | ||
* @var array[] | ||
*/ | ||
private $invalidParameters = []; | ||
|
||
/** | ||
* @param array $invalidParameters | ||
* @param string $title | ||
* @param string|null $detail | ||
* @param string|null $instance | ||
*/ | ||
public function __construct(array $invalidParameters, string $title, string $detail = null, string $instance = null) | ||
{ | ||
parent::__construct($title, $detail, $instance); | ||
|
||
$this->invalidParameters = $invalidParameters; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getStatus(): int | ||
{ | ||
return 400; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return 'https://tools.ietf.org/html/rfc2616#section-10.4.1'; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getInvalidParameters(): array | ||
{ | ||
return $this->invalidParameters; | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\ApiHttp\ApiProblem\ClientError; | ||
|
||
use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem; | ||
|
||
final class Conflict extends AbstractApiProblem | ||
{ | ||
/** | ||
* @return int | ||
*/ | ||
public function getStatus(): int | ||
{ | ||
return 409; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return 'https://tools.ietf.org/html/rfc2616#section-10.4.10'; | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\ApiHttp\ApiProblem\ClientError; | ||
|
||
use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem; | ||
|
||
final class ExpectationFailed extends AbstractApiProblem | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $failedExpectations = []; | ||
|
||
/** | ||
* @param string[] $failedExpectations | ||
* @param string $title | ||
* @param string|null $detail | ||
* @param string|null $instance | ||
*/ | ||
public function __construct(array $failedExpectations, string $title, string $detail = null, string $instance = null) | ||
{ | ||
parent::__construct($title, $detail, $instance); | ||
|
||
$this->failedExpectations = $failedExpectations; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getStatus(): int | ||
{ | ||
return 417; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return 'https://tools.ietf.org/html/rfc2616#section-10.4.18'; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getFailedExpectations(): array | ||
{ | ||
return $this->failedExpectations; | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\ApiHttp\ApiProblem\ClientError; | ||
|
||
use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem; | ||
|
||
final class FailedDependency extends AbstractApiProblem | ||
{ | ||
/** | ||
* @return int | ||
*/ | ||
public function getStatus(): int | ||
{ | ||
return 424; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return 'https://tools.ietf.org/html/rfc4918#section-11.4'; | ||
} | ||
} |
Oops, something went wrong.