Example #1
0
 /**
  * @covers Opc_Visit::__get
  * @covers Opc_Visit::get
  */
 public function testProtocolOther()
 {
     $visit = Opc_Visit::getInstance();
     $_SERVER['SERVER_PROTOCOL'] = 'IMGW';
     $this->assertEquals('unknown', $visit->protocol);
 }
Example #2
0
<?php

/**
 * This file tests the Opc_Visit functionality.
 */
// OPL Initialization
$config = parse_ini_file('../paths.ini', true);
require $config['libraries']['Opl'] . 'Base.php';
Opl_Loader::loadPaths($config);
Opl_Loader::setCheckFileExists(false);
Opl_Loader::register();
Opl_Registry::setState('opl_debug_console', false);
Opl_Registry::setState('opl_extended_errors', true);
try {
    $opc = new Opc_Class();
    $visit = Opc_Visit::getInstance();
    //echo '<p>Current host: '.$visit->host.'</p>';
    echo '<pre>';
    var_dump($visit->toArray());
    echo '</pre>';
} catch (Opc_Exception $exception) {
    $handler = new Opc_ErrorHandler();
    $handler->display($exception);
}
Example #3
0
 /**
  * Creates a "Content-type" header from the information provided in the
  * arguments or in OPT configuration. If one of the arguments is NULL,
  * the method tries to import equivalent setting from the Opt_Class configuration
  * fields.
  *
  * If Open Power Classes is available, the method may perform a full
  * content-negotiation procedure.
  *
  * @param String|Int $contentType The content type described manually or by the class constants.
  * @param String $charset The output document encoding.
  */
 public function setContentType($contentType = null, $charset = null)
 {
     $charset = is_null($charset) ? $this->_tpl->charset : $charset;
     $contentType = is_null($contentType) ? $this->_tpl->contentType : $contentType;
     $this->_tpl->charset = $charset;
     $this->_tpl->contentType = $contentType;
     if ($charset !== null) {
         $charset = ';charset=' . $charset;
     }
     $replacements = array(self::HTML => 'text/html', self::XML => 'application/xml', self::WML => 'text/vnd.wap.wml', self::TXT => 'text/plain');
     if ($this->_tpl->contentNegotiation) {
         // This part of the code requires OPC!
         $visit = Opc_Visit::getInstance();
         if ($contentType == self::XHTML) {
             // Choose XHTML or HTML depending on their priority
             $contentType = 'text/html';
             foreach ($visit->mimeTypes as $type) {
                 if ($type == 'application/xhtml+xml' || $type == 'text/html') {
                     $contentType = $type;
                     break;
                 }
             }
         } elseif ($contentType == self::FORCED_XHTML) {
             // Choose XHTML, if the browser accepts it.
             $contentType = 'text/html';
             if (in_array('application/xhtml+xml', $visit->mimeTypes)) {
                 $contentType = 'application/xhtml+xml';
             }
         } else {
             // Optionally convert the other constants and check whether
             // the browser supports them.
             if (in_array($contentType, $replacements)) {
                 $contentType = $replacements[$replacements];
             }
             if (!in_array($contentType, $visit->mimeTypes)) {
                 $contentType = 'application/octet-stream';
             }
         }
         $this->setHeader('Vary', 'Accept');
     } else {
         // No content-negotiation. Do the basic checks only.
         if ($contentType == self::XHTML || $contentType == self::FORCED_XHTML) {
             if ($this->_tpl->debugConsole) {
                 $contentType = 'text/html';
             } elseif (stristr($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml')) {
                 $contentType = 'application/xhtml+xml';
             } else {
                 $contentType = 'text/html';
             }
         } elseif (isset($replacements[$contentType])) {
             $contentType = $replacements[$contentType];
         }
     }
     $this->setHeader('Content-type', $contentType . $charset);
 }
Example #4
0
 /**
  * Singleton implementation.
  *
  * @static
  * @return Opc_Visit
  */
 public static function getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new Opc_Visit();
     }
     return self::$_instance;
 }