PHP code example of riper / exception-transformer
1. Go to this page and download the library: Download riper/exception-transformer library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
riper / exception-transformer example snippets
namespace Riper\Bundle\Moderation\AmoBundle\Exceptions;
use Riper\Bundle\Accounts\AuthenticationBundle\Exceptions\NotFoundException;
use Riper\Bundle\ExceptionTransformerBundle\ExceptionTransformer\ExceptionTransformerInterface;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ExceptionTransformer implements ExceptionTransformerInterface
{
/**
* {@inheritdoc}
*/
public function transform(\Exception $exception)
{
switch (1){
case $exception instanceof NotFoundException :
throw new NotFoundHttpException($exception->getMessage(),$exception);
case $exception instanceof InvalidParametersException :
throw new BadRequestHttpException($exception->getMessage(),$exception);
}
}
}