"Fossies" - the Fresh Open Source Software Archive

Member "grav/vendor/willdurand/negotiation/src/Negotiation/AcceptLanguage.php" (19 Mar 2020, 1063 Bytes) of package /linux/www/grav-v1.6.23.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AcceptLanguage.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Negotiation;
    4 
    5 use Negotiation\Exception\InvalidLanguage;
    6 
    7 final class AcceptLanguage extends BaseAccept implements AcceptHeader
    8 {
    9     private $language;
   10     private $script;
   11     private $region;
   12 
   13     public function __construct($value)
   14     {
   15         parent::__construct($value);
   16 
   17         $parts = explode('-', $this->type);
   18 
   19         if (2 === count($parts)) {
   20             $this->language = $parts[0];
   21             $this->region   = $parts[1];
   22         } elseif (1 === count($parts)) {
   23             $this->language = $parts[0];
   24         } elseif (3 === count($parts)) {
   25             $this->language = $parts[0];
   26             $this->script   = $parts[1];
   27             $this->region   = $parts[2];
   28         } else {
   29             // TODO: this part is never reached...
   30             throw new InvalidLanguage();
   31         }
   32     }
   33 
   34     /**
   35      * @return string
   36      */
   37     public function getSubPart()
   38     {
   39         return $this->region;
   40     }
   41 
   42     /**
   43      * @return string
   44      */
   45     public function getBasePart()
   46     {
   47         return $this->language;
   48     }
   49 }