Example #1
0
 /**
  * Initializes the instance
  * @param mixed $argumentValue The value of the invalid argument
  * @param string $destinationTypeDescription The description of the destination type
  * @param \Exception $previous = null The previous exception used for the exception chaining
  */
 public function __construct($argumentValue, $destinationTypeDescription, $previous = null)
 {
     $this->argumentValue = $argumentValue;
     $this->destinationTypeDescription = $destinationTypeDescription;
     $type = gettype($argumentValue);
     switch ($type) {
         case 'boolean':
             $shownName = $argumentValue ? 'TRUE' : 'FALSE';
             break;
         case 'integer':
         case 'double':
             $shownName = strval($argumentValue);
             break;
         case 'string':
             $shownName = "'{$argumentValue}'";
             break;
         case 'object':
             $shownName = get_class($argumentValue);
             break;
         default:
             $shownName = $type;
             break;
     }
     $message = "Can't convert {$shownName} to a {$destinationTypeDescription}";
     parent::__construct($message, \RedCat\Localize\Punic\Exception::BAD_ARGUMENT_TYPE, $previous);
 }
Example #2
0
 /**
  * Initializes the instance
  * @param string|numeric $value The invalid value
  * @param array[string|numeric] $allowedValues The list of valid values
  * @param \Exception $previous = null The previous exception used for the exception chaining
  */
 public function __construct($value, $allowedValues, $previous = null)
 {
     $this->value = $value;
     $this->allowedValues = $allowedValues;
     $message = "'{$value}' is not valid. Acceptable values are: '" . implode("', '", $allowedValues) . "'";
     parent::__construct($message, \RedCat\Localize\Punic\Exception::VALUE_NOT_IN_LIST, $previous);
 }
Example #3
0
 /**
  * Initializes the instance
  * @param string $dataFilePath The path to the file with bad contents
  * @param string $dataFileContents The malformed of the file
  * @param \Exception $previous = null The previous exception used for the exception chaining
  */
 public function __construct($dataFilePath, $dataFileContents, $previous = null)
 {
     $this->dataFilePath = $dataFilePath;
     $this->dataFileContents = $dataFileContents;
     $message = "The file '{$dataFilePath}' contains malformed data";
     parent::__construct($message, \RedCat\Localize\Punic\Exception::BAD_DATA_FILE_CONTENTS, $previous);
 }
Example #4
0
 /**
  * Initializes the instance
  * @param mixed $locale The bad locale
  * @param \Exception $previous = null The previous exception used for the exception chaining
  */
 public function __construct($locale, $previous = null)
 {
     $this->locale = $locale;
     $type = gettype($locale);
     if ($type === 'string') {
         $message = "'{$locale}' is not a valid locale identifier";
     } else {
         $message = "A valid locale should be a string, {$type} received";
     }
     parent::__construct($message, \RedCat\Localize\Punic\Exception::INVALID_LOCALE, $previous);
 }
Example #5
0
 /**
  * Initializes the instance
  * @param string $locale The preferred locale
  * @param string $fallbackLocale The fallback locale
  * @param \Exception $previous = null The previous exception used for the exception chaining
  */
 public function __construct($locale, $fallbackLocale, $previous = null)
 {
     $this->locale = $locale;
     $this->fallbackLocale = $fallbackLocale;
     if (@strcasecmp($locale, $fallbackLocale) === 0) {
         $message = "Unable to find the specified locale folder for '{$locale}'";
     } else {
         $message = "Unable to find the specified locale folder, neither for '{$locale}' nor for '{$fallbackLocale}'";
     }
     parent::__construct($message, \RedCat\Localize\Punic\Exception::DATA_FOLDER_NOT_FOUND, $previous);
 }
Example #6
0
 /**
  * Initializes the instance
  * @param mixed $identifier The bad data file identifier
  * @param \Exception $previous = null The previous exception used for the exception chaining
  */
 public function __construct($identifier, $previous = null)
 {
     $this->identifier = $identifier;
     $type = gettype($identifier);
     if ($type === 'string') {
         $message = "'{$identifier}' is not a valid data file identifier";
     } else {
         $message = "A valid identifier should be a string, {$type} received";
     }
     parent::__construct($message, \RedCat\Localize\Punic\Exception::INVALID_DATAFILE, $previous);
 }
Example #7
0
 /**
  * Initializes the instance
  * @param string $identifier The data file identifier
  * @param string $locale = '' The preferred locale (if the data file is locale-specific)
  * @param string $fallbackLocale = '' The fallback locale (if the data file is locale-specific)
  * @param \Exception $previous = null The previous exception used for the exception chaining
  */
 public function __construct($identifier, $locale = '', $fallbackLocale = '', $previous = null)
 {
     $this->identifier = $identifier;
     if (empty($locale) && empty($fallbackLocale)) {
         $this->locale = '';
         $this->fallbackLocale = '';
         $message = "Unable to find the data file '{$identifier}'";
     } else {
         $this->locale = $locale;
         $this->fallbackLocale = $fallbackLocale;
         if (@strcasecmp($locale, $fallbackLocale) === 0) {
             $message = "Unable to find the data file '{$identifier}' for '{$locale}'";
         } else {
             $message = "Unable to find the data file '{$identifier}', neither for '{$locale}' nor for '{$fallbackLocale}'";
         }
     }
     parent::__construct($message, \RedCat\Localize\Punic\Exception::DATA_FILE_NOT_FOUND, $previous);
 }
Example #8
0
 /**
  * Initializes the instance
  * @param string $dataFilePath The path to the unreadable file
  * @param \Exception $previous = null The previous exception used for the exception chaining
  */
 public function __construct($dataFilePath, $previous = null)
 {
     $this->dataFilePath = $dataFilePath;
     $message = "Unable to read from the data file '{$dataFilePath}'";
     parent::__construct($message, \RedCat\Localize\Punic\Exception::DATA_FILE_NOT_READABLE, $previous);
 }
Example #9
0
 /**
  * Initializes the instance
  * @param string $function The function/method that's not implemented
  * @param \Exception $previous = null The previous exception used for the exception chaining
  */
 public function __construct($function, $previous = null)
 {
     $this->function = $function;
     $message = "{$function} is not implemented";
     parent::__construct($message, \RedCat\Localize\Punic\Exception::NOT_IMPLEMENTED, $previous);
 }