Overview

Namespaces

  • Flea
  • None

Classes

  • Flea
  • Flea\BuildUtil
  • Flea\Cache
  • Flea\DataBase
  • Flea\DataBaseCRUD
  • Flea\DataList
  • Flea\DataUtil
  • Flea\Debug
  • Flea\FileUtil
  • Flea\General
  • Flea\Header
  • Flea\InitUtil
  • Flea\LangList
  • Flea\Login
  • Flea\LoginFormHelper
  • Flea\LoginTableName
  • Flea\LoginUser
  • Flea\Page
  • Flea\PageList
  • Flea\PageListCreate
  • Flea\SqlQuery
  • Flea\TagUtil
  • Flea\UrlUtil
  • Flea\ValueObject
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /*
  4:  * The MIT License
  5:  *
  6:  * Copyright 2014 Damien Doussaud (namide.com).
  7:  *
  8:  * Permission is hereby granted, free of charge, to any person obtaining a copy
  9:  * of this software and associated documentation files (the "Software"), to deal
 10:  * in the Software without restriction, including without limitation the rights
 11:  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 12:  * copies of the Software, and to permit persons to whom the Software is
 13:  * furnished to do so, subject to the following conditions:
 14:  *
 15:  * The above copyright notice and this permission notice shall be included in
 16:  * all copies or substantial portions of the Software.
 17:  *
 18:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19:  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20:  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 21:  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 22:  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 23:  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 24:  * THE SOFTWARE.
 25:  */
 26: 
 27: namespace Flea;
 28: 
 29: /**
 30:  * Used for write and read files
 31:  *
 32:  * @author Namide
 33:  */
 34: class Header {
 35: 
 36:     private static $_INSTANCE;
 37: 
 38:     /**
 39:      * Get the header for a format.
 40:      * Example : 
 41:      * getHeaderOfPage(Page::$FORMAT_HTML)
 42:      * return 'Content-Type: text/html'
 43:      * 
 44:      * @param string $format
 45:      * @return string
 46:      */
 47:     public function getHeaderOfPage($format) {
 48:         switch ($format) {
 49:             case Page::$FORMAT_HTML:
 50:                 return 'Content-Type: text/html';
 51:                 break;
 52:             case Page::$FORMAT_CSS:
 53:                 return 'Content-Type: text/css';
 54:                 break;
 55:             case Page::$FORMAT_JS:
 56:                 return 'Content-Type: application/javascript';
 57:                 break;
 58:             case Page::$FORMAT_XML:
 59:                 return 'Content-Type: text/xml';
 60:                 break;
 61:             case Page::$FORMAT_JSON:
 62:                 return 'Content-Type: application/json';
 63:                 break;
 64:             case Page::$FORMAT_PDF:
 65:                 return 'Content-Type: application/pdf';
 66:                 break;
 67:             case Page::$FORMAT_ZIP:
 68:                 return 'Content-Type: application/zip';
 69:                 break;
 70:         }
 71:         return '';
 72:     }
 73: 
 74:     /**
 75:      * Appli the header of the page (custom header and format).
 76:      * 
 77:      * @param \Flea\Page $page
 78:      */
 79:     public function appliHeaderOfPage(Page &$page) {
 80:         if ($page->getPhpHeader() != '') {
 81:             header(BuildUtil::getInstance()->replaceFleaVars($page->getPhpHeader(), $page));
 82:         }
 83: 
 84:         $this->appliHeaderByFormat($page->getFormat());
 85:     }
 86: 
 87:     /**
 88:      * Appli the header for the format.
 89:      * Example 'Content-Type: text/html' for an HTML page
 90:      * 
 91:      * @param type $format
 92:      */
 93:     public function appliHeaderByFormat($format) {
 94:         $headForm = $this->getHeaderOfPage($format);
 95:         if ($headForm != '') {
 96:             header($headForm);
 97:         }
 98:     }
 99: 
100:     final private function __construct() {
101:         
102:     }
103: 
104:     final private function __clone() {
105:         
106:     }
107: 
108:     /**
109:      * Instance of the Header
110:      * 
111:      * @return self     Instance of the Header
112:      */
113:     final public static function getInstance() {
114:         if (!isset(self::$_INSTANCE)) {
115:             self::$_INSTANCE = new self();
116:         }
117: 
118:         return self::$_INSTANCE;
119:     }
120: 
121: }
122: 
Flea API documentation generated by ApiGen