[ Index ]

PHP Cross Reference of Akelos Framework

title

Body

[close]

/AkUnitTest/ -> AkTestRequest.php (source)

   1  <?php
   2  require_once (AK_LIB_DIR.DS.'AkRequest.php');
   3  class AkTestRequest extends AkRequest
   4  {
   5  
   6      function &recognize($Map = null)
   7      {
   8          AK_ENVIRONMENT != 'setup' ? $this->_connectToDatabase() : null;
   9          $this->_startSession();
  10          $this->_enableInternationalizationSupport();
  11          $this->_mapRoutes($Map);
  12  
  13          $params = $this->getParams();
  14  
  15          $module_path = $module_class_peffix = '';
  16          if(!empty($params['module'])){
  17              $module_path = trim(str_replace(array('/','\\'), DS, Ak::sanitize_include($params['module'], 'high')), DS).DS;
  18              $module_shared_model = AK_CONTROLLERS_DIR.DS.trim($module_path,DS).'_controller.php';
  19              $module_class_peffix = str_replace(' ','_',AkInflector::titleize(str_replace(DS,' ', trim($module_path, DS)))).'_';
  20          }
  21  
  22          $controller_file_name = AkInflector::underscore($params['controller']).'_controller.php';
  23          $controller_class_name = $module_class_peffix.AkInflector::camelize($params['controller']).'Controller';
  24          $controller_path = AK_CONTROLLERS_DIR.DS.$module_path.$controller_file_name;
  25          include_once(AK_APP_DIR.DS.'application_controller.php');
  26  
  27          if(!empty($module_path) && file_exists($module_shared_model)){
  28              include_once($module_shared_model);
  29          }
  30  
  31          if(!is_file($controller_path) || !include_once($controller_path)){
  32              defined('AK_LOG_EVENTS') && AK_LOG_EVENTS && $this->Logger->error('Controller '.$controller_path.' not found.');
  33              if(AK_ENVIRONMENT == 'development'){
  34                  trigger_error(Ak::t('Could not find the file /app/controllers/<i>%controller_file_name</i> for '.
  35                  'the controller %controller_class_name',
  36                  array('%controller_file_name'=> $controller_file_name,
  37                  '%controller_class_name' => $controller_class_name)), E_USER_ERROR);
  38              }elseif(@include(AK_PUBLIC_DIR.DS.'404.php')){
  39                  $response = new AkTestResponse();
  40                  $response->addHeader('Status',404);
  41                  return false;
  42                  //exit;
  43              }else{
  44                  //header("HTTP/1.1 404 Not Found");
  45                  $response = new AkResponse();
  46                  $response->addHeader('Status',404);
  47                  return false;
  48                  //die('404 Not found');
  49              }
  50          }
  51          if(!class_exists($controller_class_name)){
  52              defined('AK_LOG_EVENTS') && AK_LOG_EVENTS && $this->Logger->error('Controller '.$controller_path.' does not implement '.$controller_class_name.' class.');
  53              if(AK_ENVIRONMENT == 'development'){
  54                  trigger_error(Ak::t('Controller <i>%controller_name</i> does not exist',
  55                  array('%controller_name' => $controller_class_name)), E_USER_ERROR);
  56              }elseif(@include(AK_PUBLIC_DIR.DS.'405.php')){
  57                  exit;
  58              }else{
  59                  $response = new AkResponse();
  60                  $response->addHeader('Status',405);
  61                  return false;
  62                  //header("HTTP/1.1 405 Method Not Allowed");
  63                  //die('405 Method Not Allowed');
  64              }
  65          }
  66          $Controller =& new $controller_class_name(array('controller'=>true));
  67          $Controller->_module_path = $module_path;
  68          isset($_SESSION) ? $Controller->session =& $_SESSION : null;
  69          return $Controller;
  70  
  71      }
  72      
  73      function _fixGpcMagic()
  74      {
  75          if(!defined('AK_TEST_REQUEST_GPC_MAGIC_FIXED')){
  76              if (get_magic_quotes_gpc()) {
  77                  array_walk($_GET, array('AkRequest', '_fixGpc'));
  78                  array_walk($_POST, array('AkRequest', '_fixGpc'));
  79                  array_walk($_COOKIE, array('AkRequest', '_fixGpc'));
  80              }
  81              define('AK_TEST_REQUEST_GPC_MAGIC_FIXED',true);
  82          }
  83      }
  84      
  85      function getHost()
  86      {
  87          if(!empty($this->_host)){
  88              return $this->_host;
  89          }
  90          return isset($this->env['SERVER_NAME']) ? $this->env['SERVER_NAME'] : 'localhost';
  91      }
  92  }
  93  
  94  function &AkTestRequest()
  95  {
  96      $null = null;
  97      $AkRequest =& Ak::singleton('AkTestRequest', $null);
  98      return $AkRequest;
  99  }


Generated: Mon Oct 27 12:43:49 2008 Cross-referenced by PHPXref 0.6