コード例 #1
0
ファイル: Focus.php プロジェクト: subtonix/aouka_lunch
 /**
  * Cible la partie de la chaîne de caractères commençant à l'occurrence $mStart et terminant à $mEnd.<br/>
  * Toutes les méthodes appelées par la suite ne s'appliqueront que sur la partie du texte qui a été ciblée par cette méthode.
  * Même la méthode \Aouka\Text\Manipulator::get() !<br/>Après avoir ciblé une partie du texte et lui avoir appliqué des transformations,
  * il est possible de revenir à l'intégralité du texte d'origine tout en conservant le résultat des modifications
  * avec la méthode \Aouka\Text\Manipulator::end(). 
  * 
  * <p>
  *	Exemples d'utilisation :<br/>
  *	Ciblage de la partie du texte située :
  *	<ul>
  *		<li>- jusqu'à la fin de la 3ème phrase (incluse) ->focus(NULL, array(3, \Aouka\Text\InterfaceText::SENTENCE).</li>
  *		<li>- avant le début de la 3ème phrase (exclue) ->focus(NULL, array(3, \Aouka\Text\Regex::sentence(), FALSE).</li>
  *		<li>- entre le 15ème mot (exclu) et le dernier mot "toto" (inclus) ->focus(array(15, \Aouka\Text\Regex::word(), FALSE), array(-1, "`(toto)`")).</li>
  *		<li>- après la 3ème lettre "a" (exclue) ->focus(array(3, \Aouka\Text\Regex::create("`(a)`"), FALSE), NULL).</li>
  *	<ul>
  * </p>
  * 
  * @param array|null $mStart Si $mStart vaut NULL, le ciblage commence à partir du début de la chaîne.<br/>
  * Si $mStart est un tableau, il doit contenir entre 2 et 3 éléments : <br/>
  *	<ul>
  *		<li>
  *			- Le premier de ces éléments est un nombre entier qui détermine la position n de l'ancre à partir de
  *			laquelle débute le ciblage. Si ce nombre est positif le ciblage commencera à la énième ancre à partir
  *			du début de la chaîne ; s'il est négatif, le ciblage débutera à la énième ancre à partir de la fin.
  *			S'il vaut 0, l'ancre ne sera pas prise en compte pour le ciblage de début.
  *		</li>
  *		<li>
  *			- Le deuxième de ces éléments est objet \Aouka\Text\Regex, une expression rationnelle ou une constante de l'interface
  *			\Aouka\Text\InterfaceText. Il détermine l'ancre à utiliser.
  *		</li>
  *		<li>
  *			- Le troisième élément est optionnel. Il définit si l'ancre doit être incluse ou exclue du ciblage. Par
  *			défaut, l'ancre est incluse. Il peut être une expression rationnelle sous la forme d'une chaîne de caractères
  *			ou d'un objet \Aouka\Text\Regex. Cela peut aussi être une constante de la classe \Aouka\Text\Interface.
  *		</li>
  *	<ul>
  * @param array|null $mEnd Si $mEnd vaut NULL, le ciblage termine à la fin de la chaîne.<br/>
  * Si $mEnd est un tableau, il doit contenir entre 2 et 3 éléments : <br/>
  *	<ul>
  *		<li>
  *			- Le premier de ces éléments est un nombre entier qui détermine la position n de l'ancre à partir de
  *			laquelle termine le ciblage. Si ce nombre est positif le ciblage terminera à la énième ancre à partir
  *			du début de la chaîne ; s'il est négatif, le ciblage terminera à la énième ancre à partir de la fin.
  *			S'il vaut 0, l'ancre ne sera pas prise en compte pour le ciblage de fin.
  *		</li>
  *		<li>
  *			- Le deuxième de ces éléments est objet \Aouka\Text\Regex, une expression rationnelle ou une constante de l'interface
  *			\Aouka\Text\InterfaceText. Il détermine l'ancre à utiliser.
  *		</li>
  *		<li>
  *			- Le troisième élément est optionnel. Il définit si l'ancre doit être incluse ou exclue du ciblage. Par
  *			défaut, l'ancre est incluse. Il peut être une expression rationnelle sous la forme d'une chaîne de caractères
  *			ou d'un objet \Aouka\Text\Regex. Cela peut aussi être une constante de la classe \Aouka\Text\Interface.
  *		</li>
  *	<ul>	
  */
 public function __construct($mStart, $mEnd = null)
 {
     $aArgs = func_get_args();
     $aArgs[1] = isset($aArgs[1]) ? $aArgs[1] : null;
     for ($i = 0; $i <= 1; $i++) {
         $iArgIndex = $i + 1;
         if (!is_array($aArgs[$i]) && !is_null($aArgs[$i])) {
             throw ExceptionType::invalidArgument("Argument #{$iArgIndex} doit être un tableau ou null.", Exception::FROM_HANDLER);
         }
         if ($aArgs[$i] !== null) {
             $aParams = array_values($aArgs[$i]);
             if (count($aParams) < 2 || !is_int($aParams[0])) {
                 throw ExceptionType::invalidArgument("Argument #{$iArgIndex} n'est pas un tableau indexé ayant comme premier élément un entier positif et second élément une expression rationnelle.\n\t\t\t\t\t\tLe troisième élément est optionnel. C'est un booléen déterminant si l'ancre de focus doit être incluse dans le ciblage.", Exception::FROM_HANDLER);
             }
             try {
                 $aArray = array('regex' => Regex::create($aParams[1]), 'offset' => $aParams[0], 'include' => (bool) (isset($aParams[2]) ? $aParams[2] : self::$_bDefaultInclusion));
             } catch (\Exception $oException) {
                 throw ExceptionType::invalidArgument("Argument #{$iArgIndex} n'a pas comme second élément une expression rationnelle, un objet Aouka\\Text\\Regex ou une constante de Aouka\\Text\\InterfaceText.", Exception::FROM_HANDLER);
             }
             if (!$i) {
                 $this->_aInterval['start'] = $aArray;
             } else {
                 $this->_aInterval['end'] = $aArray;
             }
         }
     }
 }
コード例 #2
0
 public function __construct($sAllowableTags = '')
 {
     if (!is_string($sAllowableTags)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_HANDLER);
     }
     $this->_sAllowableTags = $sAllowableTags;
 }
コード例 #3
0
 public function __construct($aAttributes = array(), $aQuery = array())
 {
     if (!is_array($aAttributes)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être un tableau.", Exception::FROM_HANDLER);
     }
     $this->_oAutoLink = new AutoLink(AutoLink::LINK_EMAIL, $aAttributes, $aQuery);
 }
コード例 #4
0
ファイル: Split.php プロジェクト: subtonix/aouka_lunch
 /**
  * Convertit une chaîne de caractères en tableau.
  * 
  * @param integer $iSplitLength Longueur maximale de chaque élément.
  * @throws Aouka\Text\Exception\LogicException\InvalidArgumentException
  */
 public function __construct($iSplitLength = 1)
 {
     if (!is_int($iSplitLength)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être un entier.", Exception::FROM_HANDLER);
     }
     $this->_iLength = $iSplitLength;
 }
コード例 #5
0
ファイル: AutoLinkUrls.php プロジェクト: subtonix/aouka_lunch
 public function __construct($aAttributes = array(), $aUrl = array())
 {
     if (!is_array($aAttributes)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être un tableau.", Exception::FROM_HANDLER);
     }
     if (!is_array($aUrl)) {
         throw ExceptionType::invalidArgument("Argument #2 doit être un tableau.", Exception::FROM_HANDLER);
     } elseif (isset($aUrl[AutoLink::QUERY])) {
         if (!is_array($aUrl[AutoLink::QUERY])) {
             throw ExceptionType::invalidArgument("Argument #2 : l'élément [" . AutoLink::QUERY . "] doit être un tableau.", Exception::FROM_HANDLER);
         }
         if (isset($aUrl[AutoLink::QUERY][AutoLink::QUERY_DATA]) && !is_array($aUrl[AutoLink::QUERY][AutoLink::QUERY_DATA])) {
             throw ExceptionType::invalidArgument("Argument #2 : l'élément [" . AutoLink::QUERY . "][" . AutoLink::QUERY_DATA . "] doit être un tableau.", Exception::FROM_HANDLER);
         }
         if (isset($aUrl[AutoLink::QUERY][AutoLink::QUERY_NUMERIC_PREFIX]) && !is_string($aUrl[AutoLink::QUERY][AutoLink::QUERY_NUMERIC_PREFIX])) {
             throw ExceptionType::invalidArgument("Argument #2 : l'élément [" . AutoLink::QUERY . "][" . AutoLink::QUERY_NUMERIC_PREFIX . "] doit être une chaîne de caractères.", Exception::FROM_HANDLER);
         }
         if (isset($aUrl[AutoLink::QUERY][AutoLink::QUERY_ARG_SEPARATOR]) && !is_string($aUrl[AutoLink::QUERY][AutoLink::QUERY_ARG_SEPARATOR])) {
             throw ExceptionType::invalidArgument("Argument #2 : l'élément [" . AutoLink::QUERY . "][" . AutoLink::QUERY_ARG_SEPARATOR . "] doit être une chaîne de caractères.", Exception::FROM_HANDLER);
         }
         if (isset($aUrl[AutoLink::QUERY][AutoLink::QUERY_ENC_TYPE]) && !in_array($aUrl[AutoLink::QUERY][AutoLink::QUERY_ENC_TYPE], array(PHP_QUERY_RFC1738, PHP_QUERY_RFC3986))) {
             throw ExceptionType::invalidArgument("Argument #2 : l'élément [" . AutoLink::QUERY . "][" . AutoLink::QUERY_ENC_TYPE . "] doit valoir PHP_QUERY_RFC1738 ou PHP_QUERY_RFC3986.", Exception::FROM_HANDLER);
         }
     }
     $this->_oAutoLink = new AutoLink(AutoLink::LINK_URL, $aAttributes, $aUrl);
 }
コード例 #6
0
ファイル: GetCharAt.php プロジェクト: subtonix/aouka_lunch
 public function __construct($iPos)
 {
     if (!is_int($iPos)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être un entier.", Exception::FROM_HANDLER);
     }
     $this->_iPos = abs($iPos);
 }
コード例 #7
0
ファイル: Config.php プロジェクト: subtonix/aouka_lunch
 public static function get($sProperty)
 {
     if (!is_string($sProperty)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères désignant une propriété de configuration.", Exception::FROM_CONFIG);
     }
     $oInstance = self::_getInstance();
     return $oInstance->_getNestedPropertyValue($sProperty);
 }
コード例 #8
0
ファイル: Br2nl.php プロジェクト: subtonix/aouka_lunch
 public function __construct($sSeparator = PHP_EOL, $bReplacement = false)
 {
     if (!in_array($sSeparator, $this->_getValidSeparators())) {
         throw ExceptionType::invalidArgument("Argument #1 n'est pas un séparateur valide. Il doit faire partie de la liste suivante : " . implode(', ', $this->_getValidSeparators()) . '.', Exception::FROM_HANDLER);
     }
     $this->_sSeparator = $sSeparator;
     $this->_bReplacement = (bool) $bReplacement;
 }
コード例 #9
0
ファイル: TranslateTo.php プロジェクト: subtonix/aouka_lunch
 /**
  * Constructeur.
  * 
  * @param string $sToLanguageOrLocale Langue ou locale vers laquelle traduire le texte
  * @throws \Exception
  */
 public function __construct($sToLanguageOrLocale, $bAutoDetectLocaleFrom = false)
 {
     if (!is_string($sToLanguageOrLocale)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_HANDLER);
     }
     $this->_bUseLocaleFrom = !(bool) $bAutoDetectLocaleFrom;
     $this->_setDestinationLocaleLanguage($sToLanguageOrLocale);
 }
コード例 #10
0
ファイル: Google.php プロジェクト: subtonix/aouka_lunch
 public function setText($sText)
 {
     if (!is_string($sText)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_INTERPRETOR);
     }
     $this->_aParams['q'] = $sText;
     return $this;
 }
コード例 #11
0
ファイル: PasteIn.php プロジェクト: subtonix/aouka_lunch
 /**
  * Remplace $sPattern dans la chaîne de caractères $sRecipient par le texte courant.
  * @param string $sRecipient Chaîne de caractères dans laquelle insérer le texte courant.
  * @param string $sPattern Mot-clé de $sRecipient devant être remplacé par le texte courant.
  * @throws \Exception
  */
 public function __construct($sRecipient, $sPattern)
 {
     if (!is_string($sRecipient) || !is_string($sPattern)) {
         throw ExceptionType::invalidArgument("Arguments #1 et #2 doivent être des chaînes de caractères.");
     }
     $this->_sRecipient = $sRecipient;
     $this->_sPattern = $sPattern;
 }
コード例 #12
0
ファイル: Ltrim.php プロジェクト: subtonix/aouka_lunch
 public function __construct($sCharList = null)
 {
     if ($sCharList !== null) {
         if (!is_string($sCharList)) {
             throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_HANDLER);
         }
     }
     $this->_sCharList = $sCharList;
 }
コード例 #13
0
ファイル: SpellOut.php プロジェクト: subtonix/aouka_lunch
 public function __construct($sLocale = null)
 {
     //		if (!extension_loaded('intl')) {
     //			throw new \Exception("Cette méthode n'est disponible qu'à condition de charger l'extension PECL intl.");
     //		}
     if (!is_string($sLocale) && $sLocale !== null) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères ou être null.", Exception::FROM_HANDLER);
     }
     $this->_oLocale = $sLocale;
 }
コード例 #14
0
ファイル: RPad.php プロジェクト: subtonix/aouka_lunch
 public function __construct($iPadLength, $sPadString = ' ')
 {
     if (!is_int($iPadLength)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être un entier.", Exception::FROM_HANDLER);
     }
     if (!is_string($sPadString)) {
         throw ExceptionType::invalidArgument("Argument #2 doit être une chaîne de caractères.", Exception::FROM_HANDLER);
     }
     $this->_iPadLength = $iPadLength;
     $this->_sPadString = $sPadString;
 }
コード例 #15
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;
 }
コード例 #16
0
ファイル: GetExplode.php プロジェクト: subtonix/aouka_lunch
 public function __construct($sDelimiter, $iLimit = null)
 {
     if (!is_string($sDelimiter)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_HANDLER);
     }
     if (!is_null($iLimit) && !is_int($iLimit)) {
         throw ExceptionType::invalidArgument("Argument #2 doit être un entier.", Exception::FROM_HANDLER);
     }
     $this->_sDelimiter = $sDelimiter;
     $this->_iLimit = $iLimit;
 }
コード例 #17
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;
 }
コード例 #18
0
ファイル: PregMatch.php プロジェクト: subtonix/aouka_lunch
 public function __construct($mPattern, &$aMatches = array(), $iFlags = 0, $iOffset = 0)
 {
     $this->_mPattern = $mPattern;
     $this->_aMatches = $aMatches;
     if (!is_int($iFlags)) {
         throw ExceptionType::invalidArgument("Argument #3 doit être un entier.", Exception::FROM_HANDLER);
     }
     if (!is_int($iOffset)) {
         throw ExceptionType::invalidArgument("Argument #4 doit être un entier.", Exception::FROM_HANDLER);
     }
     $this->_cFlags = $iFlags;
     $this->_iOffset = $iOffset;
 }
コード例 #19
0
ファイル: LimitChars.php プロジェクト: subtonix/aouka_lunch
 /**
  * Limite le nombre de caractères de la chaîne.
  * 
  * @param integer $iMaxLength Nombre maximal de caractères.
  * @param array $aOptions Tableau associatif qui par défaut vaut :<br/>
  * Array(
  *		LimitChars::EXACTLY => false,
  *		LimitChars::MARKER => '...',
  *		LimitChars::INCLUDE_MARKER => true
  * )<br/>
  * où LimitChars::EXACTLY définit si le texte doit exactement respecter la longueur définie $iMaxLength, même dans le cas où la césure survient après des caractères vides;
  * LimitChars::MARKER définit le marker à ajouter après la césure, le cas échéant ;
  * LimitChars::INCLUDE_MARKER définit si les caractères de LimitChars::MARKER doivent être pris en compte par $iMaxLength
  * @throws \Exception
  */
 public function __construct($iMaxLength, $aOptions = array())
 {
     if (!is_int($iMaxLength)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être un entier.", Exception::FROM_HANDLER);
     }
     if (!is_array($aOptions)) {
         throw ExceptionType::invalidArgument("Argument #2 doit être un tableau.", Exception::FROM_HANDLER);
     }
     $this->_iMaxLength = $iMaxLength;
     $this->_bExactly = isset($aOptions[self::EXACTLY]) ? (bool) $aOptions[self::EXACTLY] : false;
     $this->_sTrimMarker = isset($aOptions[self::MARKER]) ? (string) $aOptions[self::MARKER] : Config::get('ellipsis');
     $this->_bIncludeTrimMarker = isset($aOptions[self::INCLUDE_MARKER]) ? (bool) $aOptions[self::INCLUDE_MARKER] : true;
 }
コード例 #20
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;
 }
コード例 #21
0
ファイル: WrapTag.php プロジェクト: subtonix/aouka_lunch
 /**
  * Définit les tags de début et de fin.
  * 
  * Les tags de fin sont définis à partir des tags de début.
  * 
  * @param string Balises HTML de début.
  * @throws \Exception
  */
 protected function _initTags()
 {
     $oRegexTag = Regex::tag()->setModifiers($this->_m());
     $aTags = array_filter(preg_split("`({$oRegexTag})`", $this->_sInputTags, -1, PREG_SPLIT_DELIM_CAPTURE));
     foreach ($aTags as $sTag) {
         if (!$oRegexTag->test(trim($sTag))) {
             throw ExceptionType::invalidArgument("Argument #1 doit être uniquement composé de balises HTML.", Exception::FROM_HANDLER);
         }
         $this->_sStartingTags = $this->_sInputTags;
         if (preg_match('`^<([[:alnum:]]+)`', $sTag, $aMatches)) {
             $this->_sEndingTags = "</{$aMatches[1]}>" . $this->_sEndingTags;
         }
     }
 }
コード例 #22
0
 public function __construct($bSensitiveCase = true, $bRegroup = false, $aWordRegex = array())
 {
     $this->_bSensitive = (bool) $bSensitiveCase;
     $this->_bRegroup = (bool) $bRegroup;
     if (!is_array($aWordRegex)) {
         throw ExceptionType::invalidArgument("Argument #3 doit être un tableau associatif.", Exception::FROM_HANDLER);
     }
     if (isset($aWordRegex[self::WORD_ADDITIONAL_CHARS])) {
         if (!is_string($aWordRegex[self::WORD_ADDITIONAL_CHARS])) {
             throw ExceptionType::invalidArgument("Argument #3, l'élément " . self::WORD_ADDITIONAL_CHARS . " doit être une chaîne de caractères.", Exception::FROM_HANDLER);
         }
         $this->_sAdditionalChars = $aWordRegex[self::WORD_ADDITIONAL_CHARS];
     }
 }
コード例 #23
0
ファイル: Pad.php プロジェクト: subtonix/aouka_lunch
 public function __construct($iPadLength, $sPadString = ' ', $iPadType = STR_PAD_RIGHT)
 {
     if (!is_int($iPadLength)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être un entier.", Exception::FROM_HANDLER);
     }
     if (!is_string($sPadString)) {
         throw ExceptionType::invalidArgument("Argument #2 doit être une chaîne de caractères.", Exception::FROM_HANDLER);
     }
     if (!in_array($iPadType, array(STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH))) {
         throw ExceptionType::invalidArgument("Argument #3 doit valoir STR_PAD_LEFT ou STR_PAD_RIGHT ou STR_PAD_BOTH.", Exception::FROM_HANDLER);
     }
     $this->_iPadLength = $iPadLength;
     $this->_sPadString = $sPadString;
     $this->_iPadType = $iPadType;
 }
コード例 #24
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;
 }
コード例 #25
0
ファイル: Inflector.php プロジェクト: subtonix/aouka_lunch
 public function __construct($sLocale)
 {
     if (!is_string($sLocale)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_INFLECTOR);
     }
     switch ($sLocale) {
         case 'fr_FR':
             $this->_oLocale = new \Aouka\Text\Locale\fr_FR\Inflection();
             break;
         case 'en_US':
             $this->_oLocale = new \Aouka\Text\Locale\en_US\Inflection();
             break;
         default:
             throw ExceptionType::domain("Argument #1 ({$sLocale}) n'est pas une locale valide.", Exception::FROM_INFLECTOR);
     }
 }
コード例 #26
0
ファイル: Each.php プロジェクト: subtonix/aouka_lunch
 /**
  * Formate sous forme littérale l'expression rationnelle à utiliser.
  * 
  * @return void
  * @throws \Exception
  */
 protected function _formatPattern()
 {
     // Si on reçoit une chaîne de caractères, on la considère comme un pattern valide
     if (is_string($this->_mPattern)) {
         return;
     }
     // Si le pattern est un entier, c'est qu'il s'agit d'une constante
     // on construit alors sa regex
     if (is_int($this->_mPattern)) {
         $this->_mPattern = Regex::create($this->_mPattern);
     }
     // Si le pattern est un objet \Aouka\Regex, on construit l'expression sous sa forme littérale
     if ($this->_mPattern instanceof Regex) {
         $this->_mPattern = '`(' . $this->_mPattern->getExpression() . ')`' . $this->_m();
         return;
     }
     throw ExceptionType::invalidArgument("Le pattern fourni n'est pas correct.", Exception::FROM_HANDLER);
 }
コード例 #27
0
ファイル: LimitRegex.php プロジェクト: subtonix/aouka_lunch
 /**
  * Réduit la chaîne jusqu'à la $iMaxRegex expression rationnelle rencontrée depuis le début.
  * 
  * @param integer $iMaxRegex Nombre maximal d'expressions rationnelles à autoriser. Doit être supérieur à 0.
  * @param array $aOptions Tableau associatif qui par défaut vaut :<br/>
  * Array(
  *		'include_marker'		=> null,
  *		'marker'				=> '',
  *		'regex'					=> \Aouka\Text\Config::get('ellipsis'),
  *		'exact_limit_chars'		=> \
  *		'limit_chars'			=> true
  * )<br/>
  * où LimitWords::EXACTLY définit si le texte doit exactement respecter la longueur définie $iMaxWords, même dans le cas où la césure survient après des caractères vides;
  * LimitWords::MARKER définit le marker à ajouter après la césure, le cas échéant ;
  * LimitWords::INCLUDE_MARKER définit si les caractères de LimitWords::MARKER doivent être pris en compte par $iMaxWords
  * @throws \Exception
  */
 public function __construct($iMaxRegex, $aOptions = array())
 {
     if (!is_int($iMaxRegex)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être un entier supérieur à 0.", Exception::FROM_HANDLER);
     }
     if (!is_array($aOptions)) {
         throw ExceptionType::invalidArgument("Argument #2 doit être un tableau.", Exception::FROM_HANDLER);
     }
     $this->_iMaxWords = abs($iMaxRegex);
     $this->_sTrimMarker = Config::get('ellipsis');
     foreach ($aOptions as $sParam => $mValue) {
         switch ($sParam) {
             case self::REGEX:
                 if (!$mValue instanceof Regex) {
                     throw ExceptionType::invalidArgument("Argument #2, l'élément {$sParam} doit être une instance de la classe \\Aouka\\Text\\Regex.", Exception::FROM_HANDLER);
                 }
                 $this->_oRegex = $mValue;
                 break;
             case self::LIMIT_CHARS:
                 if (!is_int($mValue) && !is_null($mValue)) {
                     throw ExceptionType::invalidArgument("Argument #2, l'élément {$sParam} doit être un entier ou null.", Exception::FROM_HANDLER);
                 }
                 $this->_iMaxChars = abs($mValue);
                 break;
             case self::INCLUDE_MARKER:
                 $this->_bIncludeTrimMarker = (bool) $mValue;
                 break;
             case self::EXACT_LIMIT_CHARS:
                 $this->_bExactLimitChars = (bool) $mValue;
                 break;
             case self::MARKER:
                 $this->_sTrimMarker = (string) $mValue;
                 break;
         }
     }
     if (!$this->_oRegex) {
         throw ExceptionType::invalidArgument("Argument #2, l'élément '" . self::REGEX . "' est obligatoire.", Exception::FROM_HANDLER);
     }
 }
コード例 #28
0
ファイル: LimitWords.php プロジェクト: subtonix/aouka_lunch
 public function __construct($iMaxWords, $aOptions = array())
 {
     if (!is_int($iMaxWords)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être un entier supérieur à 0.", Exception::FROM_HANDLER);
     }
     if (!is_array($aOptions)) {
         throw ExceptionType::invalidArgument("Argument #2 doit être un tableau.", Exception::FROM_HANDLER);
     }
     $this->_iMaxWords = abs($iMaxWords);
     $this->_sTrimMarker = Config::get('ellipsis');
     foreach ($aOptions as $sParam => $mValue) {
         switch ($sParam) {
             case self::LIMIT_CHARS:
                 if (!is_int($mValue) && !is_null($mValue)) {
                     throw ExceptionType::invalidArgument("Argument #2, l'élément {$sParam} doit être un entier ou null.", Exception::FROM_HANDLER);
                 }
                 $this->_iMaxChars = abs($mValue);
                 break;
             case self::WORD_ADDITIONAL_CHARS:
                 if (!is_string($mValue)) {
                     throw ExceptionType::invalidArgument("Argument #2, l'élément {$sParam} doit être une chaîne de caractères.", Exception::FROM_HANDLER);
                 }
                 $this->_sAdditionalChars = $mValue;
                 break;
             case self::INCLUDE_MARKER:
                 $this->_bIncludeTrimMarker = (bool) $mValue;
                 break;
             case self::EXACT_LIMIT_CHARS:
                 $this->_bExactLimitChars = (bool) $mValue;
                 break;
             case self::MARKER:
                 $this->_sTrimMarker = (string) $mValue;
                 break;
         }
     }
 }
コード例 #29
0
 /**
  * Retourne les positions string (= plain + balises html) correspondant aux positions plain passées en paramètres.
  * Si on souhaite ne récupérer que la position de début, il suffit de passer le paramètre $iTo à null. De même, si on ne 
  * veut que la position de fin, on passe le paramètre $iFrom à null.
  * 
  * Dans le cas où $iFrom et $iTo sont renseignés, le tableau retourné est bidimensionel car un texte comme "toto", qui aurait comme positions plain [0, 4],
  * peut avoir plusieurs positions dans un environnement string où il serait scindé en 2 par une balise "to[br/]to".
  * Ses positions string seraient alors [[0,2],[7,9]]
  * 
  * @param array $aTextStringPos Tableau des positions des éléments plain et html séparés (tableau retourné par la méthode self::_getTagTextPositions()).
  * @param integer $iFrom Position de début dans un environnement plain. Si vaut null, le tableau retourné ne concernera que la position de fin.
  * @param integer $iTo Position de fin dans un environnement plain. Si vaut null, le tableau retourné ne concernera que la position de début.
  * @return array Tableau indexé à 2 dimensions composé des tableaux des positions dans son environnement plain + balises html (= string). Les index du premier niveau du tableau correspondent aux index du tableau des positions des éléments plain et html séparés.
  */
 public function textPosToStringPos($iFrom = null, $iTo = null)
 {
     if (!is_integer($iFrom) && $iFrom !== null || !is_integer($iTo) && $iTo !== null) {
         throw ExceptionType::invalidArgument("Arguments #2 et #3 doivent être des entiers ou null.", Exception::FROM_SUB_HANDLER);
     }
     // Récupération des positions des éléments séparés (balises html et textes plain)
     $aTagTextPositions = $this->getTagTextPos();
     // Tableau des positions dans l'environnement string
     $aStringPos = array();
     $iIndex = $iLastStringPos = 0;
     // Faut-il récupérer toutes les positions ou uniquement la position de début ou de fin ?
     $bReturnOnlyStartPos = $iTo === null;
     $bReturnOnlyEndPos = $iFrom === null;
     // Pour chaque élément (plain ou balise html) de la string
     foreach ($aTagTextPositions as $iTagTextIndex => $aHtmlTextStat) {
         // S'il n'y a plus rien à chercher, on s'arrête là
         if (isset($bKeepSearching) && !$bKeepSearching) {
             break;
         }
         // Si l'élément a des positions de texte (càd, si ce n'est pas une balise html)
         if (isset($aHtmlTextStat['pos']['text'])) {
             // Calculs des deltas entre les positions fournies en paramètres de la fonction
             // et les positions de l'élément
             if (!$bReturnOnlyEndPos) {
                 $iDeltaFrom = $iFrom - $aHtmlTextStat['pos']['text']['start'];
             }
             if (!$bReturnOnlyStartPos) {
                 $iDeltaTo = $iTo - $aHtmlTextStat['pos']['text']['end'];
             }
             $aPos = array();
             // Si on ne demande pas à retourner uniquement la position de fin
             if (!$bReturnOnlyEndPos) {
                 // Si $iFrom entre dans l'intervalle de l'élément ou bien qu'il faut continuer à chercher
                 if (0 <= $iDeltaFrom && $iFrom < $aHtmlTextStat['pos']['text']['end'] || isset($bKeepSearching) && $bKeepSearching) {
                     // Si $iFrom se situe avant l'intervalle de l'élément
                     if ($iDeltaFrom < 0) {
                         $aPos['start'] = $aHtmlTextStat['pos']['string']['start'];
                     } else {
                         $aPos['start'] = $aHtmlTextStat['pos']['string']['start'] + $iDeltaFrom;
                     }
                     if ($bReturnOnlyStartPos) {
                         return $aPos['start'];
                     }
                     // Comme on n'a pas encore trouvé la position de fin
                     // on demande à continuer la recherche
                     $bKeepSearching = true;
                 }
             }
             // Si une recherche est demandée
             if ($bReturnOnlyEndPos || isset($bKeepSearching) && $bKeepSearching) {
                 // Si $iTo se situe avant ou à la fin de l'intervalle de l'élément
                 if ($iDeltaTo <= 0) {
                     $aPos['end'] = $aHtmlTextStat['pos']['string']['end'] + $iDeltaTo;
                     // on arrête la recherche
                     $bKeepSearching = false;
                     if ($bReturnOnlyEndPos) {
                         return $aPos['end'];
                     }
                 } else {
                     $aPos['end'] = $aHtmlTextStat['pos']['string']['end'];
                 }
             }
             if ($aPos) {
                 $aStringPos[] = $aPos + array('index' => array('tag_text_pos' => $iTagTextIndex));
             }
         }
         ++$iIndex;
     }
     return $aStringPos;
 }
コード例 #30
0
ファイル: Base.php プロジェクト: subtonix/aouka_lunch
 public static function isValid($sLocale)
 {
     if (!is_string($sLocale)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_LOCALE);
     }
     $aLocale = preg_split('`-|_`', $sLocale);
     $sLang = isset($aLocale[0]) ? $aLocale[0] : null;
     $sCountry = isset($aLocale[1]) ? $aLocale[1] : null;
     // Si la langue ou le pays n'est pas défini
     // ou que la langue n'est pas répertoriée dans le tableau des locales
     // ou que le pays n'est pas associé à la langue
     if (!$sLang || !$sCountry || !self::isValidLang($sLang) || !in_array($sCountry, self::$_aLocaleData[$sLang])) {
         return false;
     }
     return true;
 }