コード例 #1
0
ファイル: Config.php プロジェクト: subtonix/aouka_lunch
 protected function _getNestedPropertyValue($sPropertyKeys)
 {
     $aNestedPropertyKeys = explode('.', $sPropertyKeys);
     $mPropertyValue = ArrayHelper::getNestedValue($this->_aProperties, $aNestedPropertyKeys, $bKeyExists);
     if (!$bKeyExists) {
         throw ExceptionType::outOfBounds("La propriété de configuration \"{$sPropertyKeys}\" n'est pas définie.", Exception::FROM_CONFIG);
     }
     return $mPropertyValue;
 }
コード例 #2
0
ファイル: Google.php プロジェクト: subtonix/aouka_lunch
 protected function _treatResponse($sJson)
 {
     // decode the response data
     $aResponse = json_decode($sJson, true);
     // ensure the returned data is valid
     if (!is_array($aResponse) || !isset($aResponse['data'])) {
         throw ExceptionType::outOfBounds("Impossible de récupérer la réponse de l'API.", Exception::FROM_INTERPRETOR);
     }
     $sDataType = $this->_bDetectLanguage ? 'detections' : 'translations';
     // ensure the returned data is valid
     if (!isset($aResponse['data'][$sDataType])) {
         throw ExceptionType::outOfBounds("Impossible de trouver la clé {$sDataType} dans le tableau retourné par l'API.", Exception::FROM_INTERPRETOR);
     }
     if (!is_array($aResponse['data'][$sDataType])) {
         throw ExceptionType::unexpectedValue("La valeur retournée par l'API n'est pas un tableau, comme attendu.", Exception::FROM_INTERPRETOR);
     }
     if ($sDataType === 'translations') {
         // loop over the translations and return the first one.
         // if you wanted to handle multiple translations in a single call
         // you would need to modify how this returns data
         foreach ($aResponse['data'][$sDataType] as $aTranslation) {
             return $aTranslation['translatedText'];
         }
     } else {
         if (!is_array($aResponse['data']['detections'][0][0])) {
             throw ExceptionType::unexpectedValue("La valeur des détections retournée par l'API n'est pas un tableau, comme attendu.", Exception::FROM_INTERPRETOR);
         } else {
             if (!isset($aResponse['data']['detections'][0][0]['language'])) {
                 throw ExceptionType::runtime("Aucune langue n'a pu être détectée.", Exception::FROM_INTERPRETOR);
             }
         }
         return $aResponse['data']['detections'][0][0]['language'];
     }
     // assume failure since success would've returned just above
     throw ExceptionType::runtime("L'appel à l'API a échoué.", Exception::FROM_INTERPRETOR);
 }
コード例 #3
0
ファイル: Regex.php プロジェクト: subtonix/aouka_lunch
 /**
  * Retourne le format négatif de l'expression prédéfinie passée en paramètre.
  * 
  * Seules les expressions rationnelles prédéfinies suivantes sont concernées par cette méthode :
  * <ul>
  * <li>InterfaceText::ALPHA</li> 
  * <li>InterfaceText::BLANK</li> 
  * <li>InterfaceText::LOWER_CASE</li> 
  * <li>InterfaceText::UPPER_CASE</li> 
  * <li>InterfaceText::WORD</li> 
  * <li>InterfaceText::ALPHA_WORD</li> 
  * <li>InterfaceText::PUNCT</li> 
  * <li>InterfaceText::DIGIT</li> 
  * <li>InterfaceText::NUMBER</li> 
  * </ul> 
  * 
  * @param integer $cType Constante correspondant à une expression prédéfinie.
  * @param string $sAdditionalChars 
  * @return string Format néfatif de l'expression prédéfinie.
  * @throws \Exception
  */
 protected function _negateFormat($cType, $sAdditionalChars = '')
 {
     $sRegex = null;
     switch ($cType) {
         case self::ALPHA:
         case self::BLANK:
         case self::LOWER_CASE:
         case self::UPPER_CASE:
         case self::WORD:
         case self::ALPHA_WORD:
         case self::PUNCT:
         case self::DIGIT:
         case self::NUMBER:
             $sRegex = substr_replace($this->_format($cType, $sAdditionalChars), '^', 1, 0);
             break;
         default:
             throw ExceptionType::outOfBounds("Impossible de renvoyer l'inverse de l'expression rationnelle demandée.", Exception::FROM_REGEX);
     }
     return $sRegex;
 }