Exemple #1
0
 /**
  * Merge the headers of two translations.
  * 
  * @param Translations $from
  * @param Translations $to
  * @param int          $options
  */
 public static function mergeHeaders(Translations $from, Translations $to, $options = self::DEFAULTS)
 {
     if ($options & self::HEADERS_REMOVE) {
         foreach (array_keys($to->getHeaders()) as $name) {
             if ($from->getHeader($name) === null) {
                 $to->deleteHeader($name);
             }
         }
     }
     foreach ($from->getHeaders() as $name => $value) {
         $current = $to->getHeader($name);
         if (empty($current)) {
             if ($options & self::HEADERS_ADD) {
                 $to->setHeader($name, $value);
             }
             continue;
         }
         if (empty($value)) {
             continue;
         }
         switch ($name) {
             case Translations::HEADER_LANGUAGE:
             case Translations::HEADER_PLURAL:
                 if ($options & self::LANGUAGE_OVERRIDE) {
                     $to->setHeader($name, $value);
                 }
                 break;
             case Translations::HEADER_DOMAIN:
                 if ($options & self::DOMAIN_OVERRIDE) {
                     $to->setHeader($name, $value);
                 }
                 break;
             default:
                 if ($options & self::HEADERS_OVERRIDE) {
                     $to->setHeader($name, $value);
                 }
         }
     }
 }