Esempio n. 1
0
 /**
  * Throw validation exception
  *
  * @param string $short_error_name
  * @param string $long_error_name
  * @param array|null $arguments
  * @param mixed $value
  */
 protected final function error($short_error_name, $long_error_name, $arguments, $value)
 {
     assert('is_string($short_error_name)');
     assert('is_string($long_error_name)');
     assert('is_null($arguments) || is_array($arguments)');
     // add options to $arguments
     if (!is_array($arguments)) {
         $arguments = array();
     }
     $arguments = array_merge($this->_options, $arguments);
     // get error format
     $short_error_key = $short_error_name . '_error';
     if (!($format = $this->getOption($short_error_key))) {
         $long_error_key = $long_error_name . '_error';
         $format = FWI18N::get('FWFormValidator', $long_error_key);
         if (!$format) {
             $format = 'is invalid';
         }
     }
     // generate message
     $search = $replace = array();
     foreach ($arguments as $s => $r) {
         if (!is_object($r) && !is_array($r)) {
             $search[] = '{' . $s . '}';
             $replace[] = $r;
         }
     }
     $message = str_replace($search, $replace, $format);
     // throw exception
     $e = new FWFormValidationException($message);
     $e->sanitizedValue = $value;
     throw $e;
 }
Esempio n. 2
0
 /**
  * Set locale
  *
  * @param string $locale
  */
 public static function setLocale($locale)
 {
     if (!self::_isValidLocale($locale)) {
         throw new Exception('Invalid locale: ' . $locale);
     }
     self::$_locale = $locale;
     if (!isset(self::$_messages[$locale])) {
         self::$_messages[$locale] = array();
     }
 }
Esempio n. 3
0
// UTF8 encoding
header('Content-Type: text/html; charset=UTF-8');
// include path
require_once FW_DIR . '/lib/classes/FWIncludePath.class.php';
FWIncludePath::clean();
FWIncludePath::prepend(FW_DIR . '/lib/classes');
FWIncludePath::prepend(APP_DIR . '/lib');
FWIncludePath::prepend(APP_DIR . '/lib/forms');
require_once 'exceptions.php';
// error handler
require_once 'FWErrorHandler.class.php';
FWErrorHandler::resetAssertOptions();
FWErrorHandler::enable();
if (DEVELOPMENT) {
    FWErrorHandler::setDebug(true);
}
// autoloader
require_once 'FWAutoloader.class.php';
FWAutoloader::register();
// i18n
if (defined('APP_LOCALE')) {
    FWI18N::setLocale(APP_LOCALE);
}
// load propel
if (APP_ENABLE_PROPEL) {
    FWIncludePath::prepend(FW_DIR . '/lib/vendor/propel/runtime/classes');
    FWIncludePath::prepend(APP_DIR . '/model/build/classes/propel');
    FWIncludePath::prepend(APP_DIR . '/model/build/classes');
    require 'propel/Propel.php';
    Propel::init(APP_DIR . '/model/build/conf/propel-conf.php');
}