コード例 #1
0
ファイル: Person.php プロジェクト: subtonix/aouka_lunch
 public function setGender($cGender)
 {
     if (!in_array($cGender, array(self::MALE, self::FEMALE, self::ANY))) {
         throw ExceptionType::domain("Argument #1 doit être égal à l'une des valeurs suivantes : Aouka\\Text\\Generator::MALE, Aouka\\Text\\Generator::FEMALE, Aouka\\Text\\Generator::ANY.", Exception::FROM_GENERATOR);
     }
     $this->_cGender = $cGender;
 }
コード例 #2
0
 public function __construct($mToMode)
 {
     if (!in_array($mToMode, array(String::GLOBAL_PARSING, String::CHUNK_PARSING))) {
         throw ExceptionType::domain("Argument #1 doit être égal à Aouka\\Text\\String::GLOBAL_PARSING (" . String::GLOBAL_PARSING . ") ou Aouka\\Text\\String::CHUNK_PARSING (" . String::CHUNK_PARSING . ") ", Exception::FROM_HANDLER);
     }
     $this->_cToMode = $mToMode;
 }
コード例 #3
0
ファイル: Google.php プロジェクト: subtonix/aouka_lunch
 protected function _getValidLangCode($sInputLangCode)
 {
     $sLang = strtolower($sInputLangCode);
     if (!$this->isTranslatableLang($sLang)) {
         throw ExceptionType::domain("Argument #1 n'est pas un code de langue valide.", Exception::FROM_INTERPRETOR);
     }
     return $sLang;
 }
コード例 #4
0
ファイル: Lorem.php プロジェクト: subtonix/aouka_lunch
 /**
  * Définit le type de texte à générer.
  * 
  * @param const|string $cToType Vaut \Aouka\Text\InterfaceText::PLAIN, \Aouka\Text\InterfaceText::HTML, "plain" ou "html".
  * @return \Aouka\Text\Generator\Lorem
  * @throws \Exception
  */
 public function setType($cToType)
 {
     if (!in_array($cToType, array(InterfaceText::PLAIN, InterfaceText::HTML))) {
         throw ExceptionType::domain("Argument #1 doit être égal à Aouka\\Text\\InterfaceText::PLAIN (" . InterfaceText::PLAIN . ") ou Aouka\\Text\\InterfaceText::HTML (" . InterfaceText::HTML . ").", Exception::FROM_GENERATOR);
     }
     $this->_cType = $cToType === InterfaceText::PLAIN ? InterfaceText::PLAIN : InterfaceText::HTML;
     return $this;
 }
コード例 #5
0
ファイル: EncodeTo.php プロジェクト: subtonix/aouka_lunch
 public function __construct($sEncoding)
 {
     if (!is_string($sEncoding)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_HANDLER);
     }
     $bValidEncoding = Encoding::isValidEncoding($sEncoding);
     if (!$bValidEncoding) {
         throw ExceptionType::domain("L'encodage passé en paramètre ({$sEncoding}) n'est pas valide. Il doit correspondre à l'un des encodages suivants : " . implode(', ', mb_list_encodings()), Exception::FROM_HANDLER);
     }
     $this->_sFinalEncoding = $bValidEncoding;
 }
コード例 #6
0
ファイル: Ucwords.php プロジェクト: subtonix/aouka_lunch
 public function __construct($aExceptions = array())
 {
     if (!is_array($aExceptions)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être un tableau.", Exception::FROM_HANDLER);
     }
     if ($aExceptions) {
         if (array_diff($aExceptions, self::_getCases())) {
             throw ExceptionType::domain("Argument #1 contient une valeur qui n'est pas une constante de casse.", Exception::FROM_HANDLER);
         }
     }
     $this->_aExceptions = $aExceptions;
 }
コード例 #7
0
ファイル: Inflector.php プロジェクト: subtonix/aouka_lunch
 /**
  * Returns a word in singular form.
  *
  * @param string $sWord The word in plural form.
  *
  * @return string The word in singular form.
  */
 public function singularize($sWord, $sEncoding = null)
 {
     if ($sEncoding === null) {
         $sEncoding = Encoding::detectEncoding($sWord);
     } else {
         $sEncoding = Encoding::isValidEncoding($sEncoding);
         if (!$sEncoding) {
             throw ExceptionType::domain("Argument #2 n'est pas un encodage valide.", Exception::FROM_INFLECTOR);
         }
     }
     $sResult = $this->_process($sWord, $sEncoding, $this->_oLocale->singulars());
     return $this->_aCache['singular'][$sWord] = $sResult ?: $sWord;
 }
コード例 #8
0
ファイル: Factory.php プロジェクト: subtonix/aouka_lunch
 public function __construct($sType, $sLocale)
 {
     if (!is_string($sType)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_LOCALE);
     }
     if (!Locale::isValid($sLocale)) {
         throw ExceptionType::domain("Argument #2 doit n'est pas une locale valide.", Exception::FROM_LOCALE);
     }
     $sLocaleNamespace = 'Aouka\\Text\\Locale\\' . $sLocale . '\\' . ucfirst(strtolower($sType));
     $oLocaleClass = new \ReflectionClass($sLocaleNamespace);
     $oLocaleInstance = $oLocaleClass->newInstance();
     $this->_oLocaleInstance = $oLocaleInstance;
 }
コード例 #9
0
ファイル: SetType.php プロジェクト: subtonix/aouka_lunch
 public function __construct($cToMode, $cHTMLParsingMode = null)
 {
     if (!in_array($cToMode, array(InterfaceText::PLAIN, InterfaceText::HTML))) {
         throw ExceptionType::domain("Argument #1 doit être égal à Aouka\\Text\\InterfaceText::PLAIN (" . InterfaceText::PLAIN . ") ou Aouka\\Text\\InterfaceText::HTML (" . InterfaceText::HTML . ").", Exception::FROM_HANDLER);
     }
     $this->_cToMode = $cToMode;
     if ($this->_cToMode === InterfaceText::HTML) {
         if ($cHTMLParsingMode !== null) {
             if (!in_array($cHTMLParsingMode, array(String::GLOBAL_PARSING, String::CHUNK_PARSING))) {
                 throw ExceptionType::domain("Argument #2 doit être égal à Aouka\\Text\\String::GLOBAL_PARSING (" . String::GLOBAL_PARSING . ") ou Aouka\\Text\\String::CHUNK_PARSING (" . String::CHUNK_PARSING . ").", Exception::FROM_HANDLER);
             }
             $this->_cToHTMLParsingMode = $cHTMLParsingMode;
         }
     }
 }
コード例 #10
0
ファイル: SetEncoding.php プロジェクト: subtonix/aouka_lunch
 /**
  * Convertit la chaîne de caractères dans l'encodage renseigné ou bien retourne le type d'encodage utilisé.
  * Attention : la modification de l'encodage n'est pas fiable à 100%.
  * 
  * @todo gerer exception
  * @param string $sEncodeTo Si ce paramètre est absent, la méthode retourne le type d'encodage courant. Dans l'autre cas, il convertit la chaîne dans l'encodage renseigné.
  * @return Encoding
  * @throws Exception
  */
 public function __construct($sEncodeTo)
 {
     // S'il y a des segments en cours de traitement
     $iProcessingPointsNb = Point::processingPointsCount();
     if ($iProcessingPointsNb) {
         throw ExceptionType::runtime("Il n'est pas possible de convertir la sous-chaîne de caractères pointée par la méthode Aouka\\Text\\Manipulator::Point(). Il faut d'abord sortir de toutes les sous-chaînes (qui sont au nombre de {$iProcessingPointsNb}) via la méthode Aouka\\Text\\Manipulator::EndFocus()", Exception::FROM_HANDLER);
     }
     if (!is_string($sEncodeTo)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères ou NULL.", Exception::FROM_HANDLER);
     }
     $sEncodingDestination = Encoding::isValidEncoding($sEncodeTo);
     if (!$sEncodingDestination) {
         throw ExceptionType::domain("Argument #1 n'est pas un encodage valide. Les encodages supportés sont décrits sur http://www.php.net/manual/fr/function.mb-list-encodings.php.", Exception::FROM_HANDLER);
     }
     $this->_sEncodingDestination = $sEncodingDestination;
 }
コード例 #11
0
ファイル: TranslateTo.php プロジェクト: subtonix/aouka_lunch
 /**
  * Effectue la traduction.
  * 
  * @param string $sFormat Type de texte ("html" ou "plain")
  * @return string
  * @throws \Exception
  */
 protected function _process($sFormat)
 {
     $sLangFrom = $this->_getFromLang();
     if ($this->_bUseLocaleFrom && $sLangFrom === $this->_sToLanguage) {
         return $this->_oString->get();
     }
     if (!$this->_getInterpretor()->isTranslatableLang(strtolower($this->_sToLanguage))) {
         throw ExceptionType::domain("La langue de destination n'est pas supportée par le traducteur.", Exception::FROM_HANDLER);
     }
     $this->_getInterpretor()->setLangTo($this->_sToLanguage)->setFormat($sFormat);
     if ($this->_bUseLocaleFrom) {
         $this->setLangFrom($sLangFrom);
     }
     $this->_setNewLocale();
     return $this->_getInterpretor()->translate($this->_oString->get());
 }
コード例 #12
0
ファイル: Base.php プロジェクト: subtonix/aouka_lunch
 public static function buildFromLang($sInputLang, $sSeparator = null)
 {
     $sLang = strtolower($sInputLang);
     if (!self::isValidLang($sLang)) {
         throw ExceptionType::domain("Argument #1 n'est pas une langue valide.", Exception::FROM_LOCALE);
     }
     if ($sSeparator === null) {
         $sSeparator = Config::get('locale.default_separator');
     } else {
         if (!is_string($sSeparator) || !in_array($sSeparator, array('-', '_'))) {
             throw ExceptionType::invalidArgument("Argument #2 doit être une chaîne de caractères ayant pour valeur '-' ou '_'.", Exception::FROM_LOCALE);
         }
     }
     return $sLang . $sSeparator . self::$_aLocaleData[$sLang][0];
 }
コード例 #13
0
 /** 
  * Définit le type de parsage HTML à exécuter sur la chaîne de caractères.
  * 
  * @param constant $cHTMLParsingMode Vaut Aouka\Text\String::GLOBAL_PARSING ou Aouka\Text\String::CHUNK_PARSING.
  * @return \Aouka\Text\Manipulator\Handler\SubHandler\PositionAnalyzer
  * @throws \Exception
  */
 public function setHTMLParsingMode($cHTMLParsingMode)
 {
     if (!in_array($cHTMLParsingMode, array(String::GLOBAL_PARSING, String::CHUNK_PARSING))) {
         throw ExceptionType::domain("Argument #1 doit être égal à Aouka\\Text\\String::GLOBAL_PARSING (" . String::GLOBAL_PARSING . ") ou Aouka\\Text\\String::CHUNK_PARSING (" . String::CHUNK_PARSING . ").", Exception::FROM_SUB_HANDLER);
     }
     $bModification = $this->_cHTMLParsingMode !== $cHTMLParsingMode;
     $this->_cHTMLParsingMode = $cHTMLParsingMode;
     // S'il y a eu une modification du type de texte, on réinitialise les propriétés impactées
     if ($bModification) {
         $this->_resetCalculatedProperties();
     }
     return $this;
 }
コード例 #14
0
ファイル: String.php プロジェクト: subtonix/aouka_lunch
 /**
  * Définit le type de texte.
  * 
  * @param string $cToMode Vaut InterfaceText::PLAIN ou InterfaceText::HTML.
  * @return \Aouka\Text\String
  * @throws \Exception
  */
 public function setType($cToMode)
 {
     if ($cToMode !== InterfaceText::PLAIN && $cToMode !== InterfaceText::HTML) {
         throw ExceptionType::domain("Argument #1 doit être égal à InterfaceText::PLAIN (" . InterfaceText::PLAIN . ") ou InterfaceText::HTML (" . InterfaceText::HTML . ").", Exception::FROM_STRING);
     }
     $this->_cType = $cToMode;
     return $this;
 }
コード例 #15
0
ファイル: Regex.php プロジェクト: subtonix/aouka_lunch
 /**
  * 
  * @param type $sInputString
  * @param type $iLimit
  * @param type $iFlags
  * @return type
  * @throws \Exception
  * @todo Trouver un moyen de détecter le type d'encodage unicode à utiliser pour recalculer les offsets
  */
 public function split($sInputString, $iLimit = -1, $iFlags = 0)
 {
     $sString = (string) $sInputString;
     if (!is_string($sString)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_REGEX);
     }
     if (!is_int($iLimit)) {
         throw ExceptionType::invalidArgument("Argument #2 doit être un entier.", Exception::FROM_REGEX);
     }
     if (!is_int($iFlags)) {
         throw ExceptionType::domain("Argument #3 doit être une constante ou une combinaison des constantes suivantes : PREG_SPLIT_NO_EMPTY, PREG_SPLIT_DELIM_CAPTURE, PREG_SPLIT_OFFSET_CAPTURE.", Exception::FROM_REGEX);
     }
     if ($this->_bCustomPattern) {
         $sExpresssion = $this->getExpression();
     } else {
         $sExpresssion = '(' . $this->getExpression() . ')';
     }
     $aResults = preg_split($this->_sDelimiter . $sExpresssion . $this->_sDelimiter . $this->_sModifiers, $sString, $iLimit, $iFlags);
     // Si la constante PREG_SPLIT_OFFSET_CAPTURE est utilisée pour une chaîne à traiter en unicode
     // Les offsets retournés sont faussés pour les caractères en multibytes. Il faut donc calculer
     // les offsets à la main...
     if ($iFlags & PREG_SPLIT_OFFSET_CAPTURE && strpos($this->_sModifiers, 'u') !== false) {
         // On peut retrouver les bons offsets, uniquement dans le cas où les délimiteurs sont aussi capturés
         if ($iFlags & PREG_SPLIT_DELIM_CAPTURE) {
             $iCounter = 0;
             foreach ($aResults as $iIndex => &$aCapture) {
                 $aCapture[1] = $iCounter;
                 // on part du principe que le texte unicode est l'utf-8
                 $iCounter += mb_strlen($aCapture[0], Encoding::UTF_8);
             }
         }
     }
     return $aResults;
 }