Example #1
0
 /**
  * initialize the ship
  * 
  * @return void
  */
 public function wake()
 {
     if (!\ClanCats::in_development()) {
         return;
     }
     // get all controllers in the dev namespace
     foreach (\CCFile::ls(\CCPath::controllers('Dev::*Controller' . EXT)) as $path) {
         $name = \CCStr::cut(basename($path), 'Controller' . EXT);
         \CCRouter::on('dev/' . \CCStr::lower($name), 'Dev::' . $name);
     }
 }
Example #2
0
 /**
  * Set up the basic uri filters in our static init and 
  * also add a default 404 response
  *
  * @return void
  */
 public static function _init()
 {
     // default string
     static::filter('any', '[a-zA-Z0-9' . ClanCats::$config->get('router.allowed_special_chars') . ']');
     // only numbers
     static::filter('num', '[0-9]');
     // only alpha characters
     static::filter('alpha', '[a-zA-Z]');
     // only alphanumeric characters
     static::filter('alphanum', '[a-zA-Z0-9]');
     // 404 not found error
     CCRouter::on('#404', function () {
         return CCResponse::create(CCView::create('Core::CCF/404')->render(), 404);
     });
 }
Example #3
0
 /**
  * start the ccf app lifecycle
  *
  * This method registers the App class and runs the wake events.
  *
  * @param string			$app		The used app class = APPATH/<$app>.php
  * @return void
  */
 public static function wake_app($app)
 {
     static::$runtime_class = $app;
     \CCFinder::bind($app, static::$paths['app'] . $app . EXT);
     // run the application wake
     $response = $app::wake();
     // when the application wake returns an response we display it
     if ($response instanceof CCResponse) {
         if (static::$config->send_app_wake_response) {
             $response->send(true);
             die;
         }
     }
     $response = null;
     // run the environment wake
     if (method_exists($app, 'wake_' . static::$environment)) {
         $response = call_user_func($app . '::wake_' . static::$environment);
         // when the application env wake returns an response we display it
         if ($response instanceof CCResponse) {
             if (static::$config->send_app_wake_response) {
                 $response->send(true);
                 die;
             }
         }
     }
     // add routes from the app
     CCRouter::on($app::routes());
 }
Example #4
0
 /**
  * CCUrl::action
  */
 public function test_action()
 {
     CCRouter::on('test_action', 'CCUnit::Test');
     CCRequest::uri('test_action/detail')->perform();
     $this->assertEquals('/test_action/detail/?woo=yay', CCUrl::action('detail/', array('woo' => 'yay')));
     $this->assertEquals('/test_action/?woo=yay', CCUrl::action('index', array('woo' => 'yay')));
     $this->assertEquals('/test_action/', CCUrl::action());
     // another route
     CCRouter::on('test_action/wurst', 'CCUnit::Test');
     CCRequest::uri('test_action/wurst/detail')->perform();
     $this->assertEquals('/test_action/wurst/detail/?woo=yay', CCUrl::action('detail/', array('woo' => 'yay')));
     $this->assertEquals('/test_action/wurst/?woo=yay', CCUrl::action('index', array('woo' => 'yay')));
     $this->assertEquals('/test_action/wurst/', CCUrl::action());
 }
Example #5
0
 /**
  * Tests the CCRouter filter escaping
  */
 public function test_escaping()
 {
     CCRouter::on('this/u$l/conta([num])n+special/[any]', function () {
         echo "Escaping works";
     });
     $response = CCRequest::uri('this/u$l/conta(1)n+special/chars')->perform()->response()->body;
     $this->assertEquals($response, "Escaping works");
 }