Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CompanyServiceException extends RuntimeException { }
- class CompanyServiceNotAvailableException extends CompanyServiceException { }
- class CompanyServiceUnknownIdException extends CompanyServiceException { }
- class CompanyServiceController
- {
- const ERROR_CODE_SERVICE_NOT_AVAILALE = 1;
- const ERROR_CODE_VAT_ID_UNKNOWN = 2;
- const ERROR_UNKNOWN = 3;
- private $companyService;
- function __construct($companyService)
- {
- $this->companyService = $companyService;
- }
- function run($request)
- {
- try {
- $company = $this->companyService->readByIdAndCountry($request->id, $request->country);
- $responseData = $company->toArray();
- } catch (CompanyServiceNotAvailableException $e) {
- $responseData = array(
- "error" => "EC neni dostupna",
- "errorCode" => static::ERROR_CODE_SERVICE_NOT_AVAILALE,
- );
- } catch (CompanyServiceUnknownIdException $e) {
- $responseData = array(
- "error" => "DIC {$request->country}{$request->id} nebylo nalezeno",
- "errorCode" => static::ERROR_CODE_VAT_ID_UNKNOWN,
- );
- } catch (Exception $e) {
- $responseData = array(
- "error" => "Neznámá chyba",
- "errorCode" => static::ERROR_UNKNOWN,
- );
- }
- return new JsonResponse($responseData);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment