Example #1
0
 /**
  * Method for object initialization by the string
  * @param string $string response string with authorization code data
  * @return Code response object
  */
 public static function initializeByString($string)
 {
     $data = array();
     parse_str($string, $data);
     $Response = new self();
     return $Response->setCode($data['code']);
 }
Example #2
0
 static function fromException($exception)
 {
     $exceptionClass = get_class($exception);
     $response = new self();
     if ($exception instanceof \RpcException) {
         $response->setHttpStatus($exception->getHttpStatus());
         $response->setCode($exception->getRpcErrorCode());
         $response->setData(['data' => $exception->getData(), 'trace' => $exception->getTrace()]);
     } else {
         $response->setHttpStatus(500);
         $response->setCode('UNKOWN');
         $response->setData(['trace' => $exception->getTrace()]);
     }
     $response->setMessage($exception->getMessage());
     return $response;
 }
Example #3
0
 public static function fromException(Exception $e)
 {
     $obj = new self();
     $obj->setException(get_class($e));
     $obj->setMessage($e->getMessage());
     $obj->setCode($e->getCode());
     $obj->setTrace($e->getTraceAsString());
     return $obj;
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public static function buildFromResponse(stdClass $response)
 {
     $bank = new self();
     $bank->setCode(isset($response->code) ? $response->code : null);
     $bank->setName(isset($response->name) ? $response->name : null);
     $bank->setLogoUrl(isset($response->logo) ? $response->logo : null);
     $bank->raw = $response;
     return $bank;
 }
Example #5
0
 public static function initWithArray($array)
 {
     $instance = new self(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
     $instance->setName($array[Event::EVENT_NAME]);
     $instance->setCode($array[Event::EVENT_CODE]);
     $instance->setCat_id($array[Event::EVENT_CAT_ID]);
     $instance->setShort_desc($array[Event::EVENT_SHORTDESC]);
     $instance->setLong_desc($array[Event::EVENT_LONGDESC]);
     $instance->setTags($array[Event::EVENT_TAGS]);
     $instance->setContacts($array[Event::EVENT_CONTACTS]);
     $instance->setPrize($array[Event::EVENT_PRIZE]);
     $instance->setPrtpnt($array[Event::EVENT_PRTPNT]);
     $instance->setValidate($array[Event::EVENT_VALIDATE]);
     $instance->setLocation_id($array[Event::EVENT_LOCATIONID]);
     $instance->setTimings($array[Event::EVENT_TIMINGS]);
     return $instance;
 }
Example #6
0
 /**
  * Initialization method
  * @param stdClass $Object object for initialization
  * @return Error initialized object
  */
 public static function initializeByObject(stdClass $Object)
 {
     $Error = new self();
     $Error->setCode($Object->error_code)->setMessage($Object->error_msg)->setData($Object->error_data);
     return $Error;
 }
Example #7
0
 /**
  * Create token collection directly from code.
  *
  * @param string $code PHP code
  *
  * @return Tokens
  */
 public static function fromCode($code)
 {
     $codeHash = self::calculateCodeHash($code);
     if (self::hasCache($codeHash)) {
         $tokens = self::getCache($codeHash);
         // generate the code to recalculate the hash
         $tokens->generateCode();
         if ($codeHash === $tokens->codeHash) {
             $tokens->clearEmptyTokens();
             $tokens->clearChanged();
             return $tokens;
         }
     }
     $tokens = new self();
     $tokens->setCode($code);
     $tokens->clearChanged();
     return $tokens;
 }
Example #8
0
 public static function create(\Exception $exception, $statusCode = null, array $headers = array())
 {
     $e = new self();
     $e->setMessage($exception->getMessage());
     $e->setCode($exception->getCode());
     if (null === $statusCode) {
         $statusCode = 500;
     }
     $e->setStatusCode($statusCode);
     $e->setHeaders($headers);
     $e->setTraceFromException($exception);
     $e->setClass(get_class($exception));
     $e->setFile($exception->getFile());
     $e->setLine($exception->getLine());
     if ($exception->getPrevious()) {
         $e->setPrevious(self::create($exception->getPrevious()));
     }
     return $e;
 }
Example #9
0
 /**
  * Initialization method
  * @param stdClass $Object object for initialization
  * @return ObjectInitializedInterface initialized object
  */
 public static function initializeByObject(\stdClass $Object)
 {
     $Error = new self();
     $Error->setCode($Object->error->error_code)->setMessage($Object->error->error_msg);
     if (isset($Object->error->request_params)) {
         $Items = array();
         foreach ($Object->error->request_params as $Item) {
             $Items[$Item->key] = $Item->value;
         }
         $Error->setParameters($Items);
     }
     return $Error;
 }
Example #10
0
 /**
  * @param $exception
  * @return Response
  */
 static function fromException($exception)
 {
     $exceptionClass = get_class($exception);
     $response = new self();
     if ($exception instanceof \RpcException) {
         $response->setHttpStatus($exception->getHttpStatus());
         $response->setCode($exception->getRpcErrorCode());
         $response->setData(['data' => $exception->getData(), 'trace' => $exception->getTrace()]);
     } else {
         $response->setHttpStatus(500);
         $response->setCode(ErrorMessages::JSONRPC_ERROR_UNKOWN_EXCEPTION_CODE);
         $response->setData(['trace' => $exception->getTrace()]);
     }
     $response->setMessage($exception->getMessage());
     $response->error = ['code' => $response->code, 'message' => $response->message, 'data' => $response->data];
     return $response;
 }
 /**
  * Create a success response
  *
  * @param  mixed  $body
  * @param  string $message
  * @return ServiceResponse
  */
 public static function success($body, $message = null, $messageType = Message::TYPE_INFO)
 {
     $instance = new self();
     $instance->setCode(self::STATUS_SUCCESS)->setBody($body);
     // Add message
     if ($message !== null) {
         $instance->addMessage(self::composeMessage($message, $messageType));
     }
     return $instance;
 }
 /**
  * Create a Get Method from Property of Class.
  *
  * @param PropertyInterface $property
  *
  * @return Method
  */
 public static function createGetterFromProperty(PropertyInterface $property)
 {
     $method = new self();
     $method->setName('get_' . $property->getName());
     $method->setCode('return $this->' . $property->getName() . ';');
     return $method;
 }