Exemplo n.º 1
0
 /**
  * The initial call of the CCServer get all Superglobals
  * and assigns them to itself as an holder.
  * 
  * @return void
  */
 public static function _init()
 {
     // create new instance from default input
     CCServer::$_instance = CCIn::create($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
     // unset default http holder to safe mem
     //unset( $_GET, $_POST, $_COOKIE, $_SERVER, $_FILES );
 }
Exemplo n.º 2
0
 /**
  * initialize the ship
  */
 public function wake()
 {
     $uri = \CCServer::server('REQUEST_URI', '/');
     // fix doubled slashes
     $uri_fixed = preg_replace('/(\\/+)/', '/', $uri);
     // redirect if not match
     if ($uri != $uri_fixed) {
         \CCRedirect::to($uri_fixed)->send(true);
         die;
     }
 }
Exemplo n.º 3
0
 /**
  * write the log down to disk
  *
  * @return void
  */
 public static function write()
 {
     if (empty(static::$_data)) {
         return;
     }
     $buffer = date("H:i:s") . " - " . CCServer::method() . ' ' . CCServer::server('REQUEST_URI') . "\n";
     $buffer .= implode("\n", static::$_data);
     CCFile::append(CCStorage::path('logs/' . date('Y-m') . '/' . date('d') . '.log'), $buffer . "\n");
     // clear
     static::clear();
 }
Exemplo n.º 4
0
 /**
  * Application initialization.
  * do your inital stuff here like getting the current user object ect..
  * You can return a CCResponse wich will cancle all other actions 
  * if enebaled ( see. main.config -> send_app_wake_response )
  *
  * @return void | CCResponse
  */
 public static function wake()
 {
     /*
      * Start the session by adding the current uri
      */
     CCSession::set('uri', CCServer::uri());
     /*
      * try to authenticate the user
      */
     //static::$user =& CCAuth::handler()->user;
     /*
      * load the App configuration
      */
     static::$config = CCConfig::create('app');
 }
Exemplo n.º 5
0
 /**
  * Execute the Request
  *
  * @param array 	$action
  * @param array 	$params
  *
  * @return self
  */
 public function perform()
 {
     // set the input
     if (!is_null($this->input)) {
         CCIn::instance($this->input);
     } else {
         CCIn::instance(CCServer::instance());
     }
     // set current request
     static::$_current =& $this;
     // route is invalid show 404
     if (!$this->route instanceof CCRoute) {
         $this->route = CCRouter::resolve('#404');
     }
     /*
      * call wake events
      * if one event returns an response all other calls will be skipped also events!
      */
     foreach (CCRouter::events_matching('wake', $this->route->uri) as $callback) {
         if (($return = CCContainer::call($callback)) instanceof CCResponse) {
             $this->response = $return;
             return $this;
         }
     }
     /*
      * a closure
      */
     if (!is_array($this->route->callback) && is_callable($this->route->callback)) {
         // execute and capture the output
         ob_start();
         // run the closure
         $return = call_user_func_array($this->route->callback, $this->route->params);
         // catch the output
         $output = ob_get_clean();
         // do we got a response?
         if (!$return instanceof CCResponse) {
             // if not create one with the captured output
             $return = CCResponse::create($output);
         }
     } elseif (is_callable($this->route->callback)) {
         // execute the callback and get the return
         $return = call_user_func_array($this->route->callback, array($this->route->action, $this->route->params));
         // do we got a response?
         if (!$return instanceof CCResponse) {
             // if not create one with the return as string
             $return = CCResponse::create((string) $return);
         }
     } else {
         $return = CCResponse::error(404);
     }
     // set the response
     $this->response = $return;
     /*
      * call sleep events
      * if one event returns an response all other calls will be skipped also events!
      */
     foreach (CCRouter::events_matching('sleep', $this->route->uri) as $callback) {
         if ($return = CCContainer::call($callback, $this->response) instanceof CCResponse) {
             $this->response = $return;
             return $this;
         }
     }
     return $this;
 }
Exemplo n.º 6
0
<?php

/*
 *---------------------------------------------------------------
 * ClanCatsFramework runner
 *---------------------------------------------------------------
 *
 * This file just loads CCF and all needed resources to run the 
 * php unit tests. PHPUnit is a really elegant way to make sure 
 * that everything works how it should.
 *
 *---------------------------------------------------------------
 * Require CCF
 *---------------------------------------------------------------
 *
 * load the framework file wich wil initialize CCF. 
 */
require_once __DIR__ . "/clancatsapp/framework.php";
/*
 * execute the main request
 * The main request contains the params of the http header
 */
$response = CCRequest::uri(CCServer::uri())->perform()->response();
/*
 * "send" means actaully printing the response.
 * If the secound parameter is true the response will 
 * also set headers
 */
$response->send(true);
Exemplo n.º 7
0
 /**
  * Some default values for our session
  *
  * @return array
  */
 public static function default_data_provider()
 {
     return array('last_active' => time(), 'current_lang' => \CCLang::current(), 'client_agent' => \CCServer::client('agent'), 'client_ip' => \CCServer::client('ip'), 'client_port' => \CCServer::client('port'), 'client_lang' => \CCServer::client('language'));
 }