-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "REST: Replace
invalid-property-id
with `invalid-path-paramet…
…er`"
- Loading branch information
Showing
41 changed files
with
330 additions
and
182 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
36 changes: 36 additions & 0 deletions
36
...t-api/src/Application/UseCaseRequestValidation/PropertyIdFilterValidatingDeserializer.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,36 @@ | ||
<?php declare( strict_types=1 ); | ||
|
||
namespace Wikibase\Repo\RestApi\Application\UseCaseRequestValidation; | ||
|
||
use Wikibase\DataModel\Entity\NumericPropertyId; | ||
use Wikibase\Repo\RestApi\Application\UseCases\UseCaseError; | ||
use Wikibase\Repo\RestApi\Application\Validation\PropertyIdValidator; | ||
|
||
/** | ||
* @license GPL-2.0-or-later | ||
*/ | ||
class PropertyIdFilterValidatingDeserializer { | ||
|
||
private PropertyIdValidator $propertyIdValidator; | ||
|
||
public function __construct( PropertyIdValidator $validator ) { | ||
$this->propertyIdValidator = $validator; | ||
} | ||
|
||
/** | ||
* @throws UseCaseError | ||
*/ | ||
public function validateAndDeserialize( string $propertyId ): NumericPropertyId { | ||
$validationError = $this->propertyIdValidator->validate( $propertyId ); | ||
if ( $validationError ) { | ||
$invalidPropertyId = $validationError->getContext()[PropertyIdValidator::CONTEXT_VALUE]; | ||
throw new UseCaseError( | ||
UseCaseError::INVALID_PROPERTY_ID, | ||
"Not a valid property ID: $invalidPropertyId", | ||
[ UseCaseError::CONTEXT_PROPERTY_ID => $invalidPropertyId ] | ||
); | ||
} | ||
return new NumericPropertyId( $propertyId ); | ||
} | ||
|
||
} |
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.