# CommonDoctypeDeclaration.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2007 by Ivan Y. Khvostishkov                            *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00023     final class CommonDoctypeDeclaration extends DoctypeDeclaration
    00024     {
    00025         private $organization   = null;
    00026
    00027         private $type           = null;
    00028         private $subtype        = null;
    00029         private $version        = null;
    00030         private $variant        = null;
    00031         private $language       = null;
    00032
    00036         public static function create()
    00037         {
    00038             return new self;
    00039         }
    00040
    00044         public function setOrganization($organization)
    00045         {
    00046             $this->organization = $organization;
    00047
    00048             return $this;
    00049         }
    00050
    00051         public function getOrganization()
    00052         {
    00053             return $this->organization;
    00054         }
    00055
    00059         public function setType($type)
    00060         {
    00061             $this->type = $type;
    00062
    00063             return $this;
    00064         }
    00065
    00066         public function getType()
    00067         {
    00068             return $this->type;
    00069         }
    00070
    00074         public function setSubtype($subtype)
    00075         {
    00076             $this->subtype = $subtype;
    00077
    00078             return $this;
    00079         }
    00080
    00081         public function getSubtype()
    00082         {
    00083             return $this->subtype;
    00084         }
    00085
    00089         public function setVersion($version)
    00090         {
    00091             $this->version = $version;
    00092
    00093             return $this;
    00094         }
    00095
    00096         public function getVersion()
    00097         {
    00098             return $this->version;
    00099         }
    00100
    00104         public function setVariant($variant)
    00105         {
    00106             $this->variant = $variant;
    00107
    00108             return $this;
    00109         }
    00110
    00111         public function getVariant()
    00112         {
    00113             return $this->variant;
    00114         }
    00115
    00119         public function setLanguage($language)
    00120         {
    00121             $this->language = $language;
    00122
    00123             return $this;
    00124         }
    00125
    00126         public function getLanguage()
    00127         {
    00128             return $this->language;
    00129         }
    00130
    00134         public function setFpi($fpi)
    00135         {
    00136             parent::setFpi($fpi);
    00137
    00138             $matches = array();
    00139
    00140             preg_match(
    00141                 '~^-//([a-z0-9]+)//DTD ([a-z]+)'
    00142                 .' ?([a-z]+)? ?(\d+\.\d+)?'.
    00143                 ' ?([a-z]+)?//([a-z]+)$~i',
    00144                 $fpi,
    00145                 $matches
    00146             );
    00147
    00148             $this->organization = !empty($matches[1]) ? $matches[1] : null;
    00149             $this->type = !empty($matches[2]) ? $matches[2] : null;
    00150
    00151             $this->subtype = !empty($matches[3]) ? $matches[3] : null;
    00152             $this->version = !empty($matches[4]) ? $matches[4] : null;
    00153             $this->variant = !empty($matches[5]) ? $matches[5] : null;
    00154             $this->language = !empty($matches[6]) ? $matches[6] : null;
    00155
    00156             return $this;
    00157         }
    00158
    00159         public function getFpi()
    00160         {
    00161             if (!$this->organization)
    00162                 return null;
    00163
    00164             return
    00165                 '-//'.$this->organization.'//DTD '.$this->type
    00166                 .($this->subtype ? ' '.$this->subtype : null)
    00167                 .($this->version ? ' '.$this->version : null)
    00168                 .($this->variant ? ' '.$this->variant : null)
    00169                 .'//'.$this->language;
    00170         }
    00171     }
    00172 ?>