Kerio APIs Client Library for PHP 1.4.0.234
  • Namespace
  • Class
  • Tree
  • Deprecated

Namespaces

  • None
  • PHP

Classes

  • KerioApi
  • KerioApiSocket
  • KerioConnectApi
  • KerioControlApi
  • KerioDirectoryApi
  • KerioOperatorApi
  • KerioWorkspaceApi
  • SamepageApi

Interfaces

  • KerioApiInterface
  • KerioApiSocketInterface

Exceptions

  • KerioApiException
  1 <?php
  2 /**
  3  * This file is part of the kerio-api-php.
  4  *
  5  * Copyright (c) Kerio Technologies s.r.o.
  6  *
  7  * For the full copyright and license information, please view
  8  * the file license.txt that was distributed with this source code
  9  * or visit Developer Zone. (http://www.kerio.com/developers)
 10  *
 11  * Do not modify this source code.
 12  * Any changes may be overwritten by a new version.
 13  */
 14 
 15 /**
 16  * Kerio API Exception Class.
 17  *
 18  * This class extends Exception class to provide CSS-based error message formating.
 19  *
 20  * @copyright   Copyright &copy; 2012-2012 Kerio Technologies s.r.o.
 21  * @license     http://www.kerio.com/developers/license/sdk-agreement
 22  * @version     1.4.0.234
 23  */
 24 class KerioApiException extends Exception {
 25 
 26     /**
 27      * Positional parameters
 28      * @var array
 29      */
 30     private $positionalParameters = array();
 31 
 32     /**
 33      * Error code
 34      * @var integer
 35      */
 36     protected $code;
 37 
 38     /**
 39      * Error message
 40      * @var string
 41      */
 42     protected $message = '';
 43 
 44     /**
 45      * Request message
 46      * @var string
 47      */
 48     protected $request = '';
 49 
 50     /**
 51      * Response message
 52      * @var string
 53      */
 54     protected $response = '';
 55 
 56     /**
 57      * Exception contructor.
 58      *
 59      * @param   string  Message to display
 60      * @param   mixed   Can be integer or string
 61      * @param   array   Positional parameters in message
 62      * @return  void
 63      */
 64     public function KerioApiException($message, $code = '', $positionalParameters = '', $request = '', $response = '') {
 65         $this->message = $message;
 66 
 67         if (is_int($code) || is_string($code)) {
 68             $this->code = $code;
 69         }
 70         if (is_array($positionalParameters)) {
 71             $this->positionalParameters = $positionalParameters;
 72             $this->setPositionalParameterToString();
 73         }
 74         if (is_string($request)) {
 75             $this->request = $request;
 76         }
 77         if (is_string($response)) {
 78             $this->response = $response;
 79         }
 80 
 81     }
 82 
 83     /**
 84      * Get request data.
 85      *
 86      * @return  string  JSON request
 87      */
 88     public function getRequest() {
 89         return $this->request;
 90     }
 91 
 92     /**
 93      * Get response data.
 94      *
 95      * @return  string  JSON response
 96      */
 97     public function getResponse() {
 98         return $this->response;
 99     }
100 
101     /**
102      * Replace positional parameter with a string
103      *
104      * @return  void
105      */
106     private function setPositionalParameterToString() {
107         if (preg_match_all('/%\d/', $this->message, $matches)) {
108             /* Found positional parameters */
109             $index = 0;
110             foreach ($matches[0] as $occurence) {
111                 $replaceWith = $this->positionalParameters[$index];
112                 $this->message = str_replace($occurence, $replaceWith, $this->message);
113                 $index++;
114             }
115         }
116     }
117 }
118 
Kerio APIs Client Library for PHP 1.4.0.234 API documentation generated by ApiGen 2.8.0