Exemple #1
0
 public function __construct($language, $segment = '')
 {
     if (Inflector::length($segment)) {
         $fileTranslation = LANGUAGE_PATH . DS . ucwords(Inflector::lower(repl('.', DS, $segment))) . DS . Inflector::lower($language) . '.ini';
     } else {
         $fileTranslation = LANGUAGE_PATH . DS . Inflector::lower($language) . '.ini';
     }
     if (File::exists($fileTranslation)) {
         $ini = new Ini($fileTranslation);
         $translations = $ini->parseIni();
         $this->setSentences($translations);
         Utils::set('ThinTranslate', $this);
     } else {
         throw new Exception('The translation file ' . $fileTranslation . ' does not exist.');
     }
 }
Exemple #2
0
 /**
  * Remove the PKCS7 compatible padding from the given value.
  *
  * @param  string  $value
  * @return string
  */
 protected static function unpad($value)
 {
     $pad = ord($value[($length = Inflector::length($value)) - 1]);
     if ($pad and $pad < static::$block) {
         // If the correct padding is present on the string, we will remove
         // it and return the value. Otherwise, we'll throw an exception
         // as the padding appears to have been changed.
         if (preg_match('/' . chr($pad) . '{' . $pad . '}$/', $value)) {
             return substr($value, 0, $length - $pad);
         } else {
             throw new Exception("Decryption error. Padding is invalid.");
         }
     }
     return $value;
 }