HosipLan

Untitled

Feb 14th, 2012
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. class CompanyServiceException extends RuntimeException { }
  2. class CompanyServiceNotAvailableException extends CompanyServiceException { }
  3. class CompanyServiceUnknownIdException extends CompanyServiceException { }
  4.  
  5. class CompanyServiceController
  6. {
  7.         const ERROR_CODE_SERVICE_NOT_AVAILALE = 1;
  8.         const ERROR_CODE_VAT_ID_UNKNOWN = 2;
  9.         const ERROR_UNKNOWN = 3;
  10.  
  11.         private $companyService;
  12.  
  13.         function __construct($companyService)
  14.         {
  15.                 $this->companyService = $companyService;
  16.         }
  17.  
  18.         function run($request)
  19.         {
  20.                 try {
  21.                         $company = $this->companyService->readByIdAndCountry($request->id, $request->country);
  22.                         $responseData = $company->toArray();
  23.  
  24.                 } catch (CompanyServiceNotAvailableException $e) {
  25.                         $responseData = array(
  26.                                 "error" => "EC neni dostupna",
  27.                                 "errorCode" => static::ERROR_CODE_SERVICE_NOT_AVAILALE,
  28.                         );
  29.  
  30.                 } catch (CompanyServiceUnknownIdException $e) {
  31.             $responseData = array(
  32.                                 "error" => "DIC {$request->country}{$request->id} nebylo nalezeno",
  33.                                 "errorCode" => static::ERROR_CODE_VAT_ID_UNKNOWN,
  34.                         );
  35.  
  36.         } catch (Exception $e) {
  37.             $responseData = array(
  38.                                 "error" => "Neznámá chyba",
  39.                                 "errorCode" => static::ERROR_UNKNOWN,
  40.                         );
  41.         }
  42.  
  43.                 return new JsonResponse($responseData);
  44.         }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment