Skip to content

Commit

Permalink
add ApiException
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 10, 2024
1 parent 0670e75 commit 4373ae2
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/ApiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Psr\Cache\CacheItemPoolInterface;
use PSX\Api\Builder\SpecificationBuilder;
use PSX\Api\Builder\SpecificationBuilderInterface;
use PSX\Api\Exception\ApiException;
use PSX\Api\Exception\InvalidApiException;
use PSX\Api\Parser\Attribute\BuilderInterface;
use PSX\Schema\Parser\ContextInterface;
Expand All @@ -41,6 +42,9 @@ class ApiManager implements ApiManagerInterface
private CacheItemPoolInterface $cache;
private bool $debug;

/**
* @var array<string, ParserInterface>
*/
private array $parsers = [];

public function __construct(SchemaManagerInterface $schemaManager, BuilderInterface $builder, ?CacheItemPoolInterface $cache = null, bool $debug = false)
Expand All @@ -59,6 +63,9 @@ public function register(string $scheme, ParserInterface $parser): void
$this->parsers[$scheme] = $parser;
}

/**
* @throws ApiException
*/
public function getApi(string $source, ?ContextInterface $context = null): SpecificationInterface
{
$item = null;
Expand Down
32 changes: 32 additions & 0 deletions src/Exception/ApiException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/*
* PSX is an open source PHP framework to develop RESTful APIs.
* For the current version and information visit <https://phpsx.org>
*
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace PSX\Api\Exception;

/**
* ApiException
*
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class ApiException extends \Exception
{
}
2 changes: 1 addition & 1 deletion src/Exception/ArgumentNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class ArgumentNotFoundException extends \Exception
class ArgumentNotFoundException extends ApiException
{
}
2 changes: 1 addition & 1 deletion src/Exception/GeneratorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class GeneratorException extends \Exception
class GeneratorException extends ApiException
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class InvalidApiException extends \Exception
class InvalidApiException extends ApiException
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class InvalidArgumentException extends \Exception
class InvalidArgumentException extends ApiException
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidMethodException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class InvalidMethodException extends \Exception
class InvalidMethodException extends ApiException
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidOperationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class InvalidOperationException extends \Exception
class InvalidOperationException extends ApiException
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class InvalidTypeException extends \Exception
class InvalidTypeException extends ApiException
{
}
2 changes: 1 addition & 1 deletion src/Exception/OperationAlreadyExistsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class OperationAlreadyExistsException extends \Exception
class OperationAlreadyExistsException extends ApiException
{
}
2 changes: 1 addition & 1 deletion src/Exception/OperationNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class OperationNotFoundException extends \Exception
class OperationNotFoundException extends ApiException
{
}
2 changes: 1 addition & 1 deletion src/Exception/ParserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class ParserException extends \Exception
class ParserException extends ApiException
{
}

0 comments on commit 4373ae2

Please sign in to comment.