Exemple #1
0
 /**
  * The Autoloader initialisation
  *
  * @return void
  */
 public static function _init()
 {
     // is the profiler enabled?
     if (!(static::$_enabled = ClanCats::$config->get('profiler.enabled'))) {
         return;
     }
     // enable profiling only in development mode
     if (ClanCats::in_development()) {
         // add a hook to the resposne so that we can
         // append a table with the profiler data to the body
         CCEvent::mind('response.output', function ($output) {
             if (strpos($output, '</body>') === false) {
                 return $output;
             }
             $table = \UI\Table::create(array('style' => array('width' => '100%'), 'cellpadding' => '5', 'class' => 'table debug-table debug-table-profiler'));
             $table->header(array('#', 'message', 'memory', 'time'));
             foreach (\CCProfiler::data() as $key => $item) {
                 $table->row(array($key + 1, $item[0], $item[1], $item[2]));
             }
             // add the table before the body end
             return str_replace('</body>', $table . "\n</body>", $output);
         });
         // also add an error inspector hook so that we can access the
         // profiler data in the error handler
         CCError_Inspector::info_callback('Profiler', function () {
             $table = array();
             foreach (\CCProfiler::data() as $key => $check) {
                 $table['#' . ($key + 1) . ': ' . $check[2]] = $check[0];
             }
             return $table;
         });
     }
 }
Exemple #2
0
 /**
  * trigger the handler
  *
  * @return void
  */
 public function handle()
 {
     $this->log();
     // when not in development we respond using a route
     if (!ClanCats::in_development() && !ClanCats::is_cli()) {
         CCResponse::error(500)->send(true);
     } else {
         $this->respond();
     }
 }
Exemple #3
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);
     }
 }
Exemple #4
0
 /**
  * print information about this application
  *
  * @param array 		$params 
  */
 public function action_info($params)
 {
     $app = \ClanCats::runtime();
     // print the app name
     $this->line(\CCForge_Php::make('comment', $app::$name . PHP_EOL . "*" . PHP_EOL . "Running on ClanCatsFramework " . \ClanCats::VERSION . PHP_EOL . "© 2010 - " . date('Y') . " ClanCats GmbH" . PHP_EOL), 'cyan');
     // list printer
     $list = function ($array) {
         foreach ($array as $key => $value) {
             $this->line($key . ': ' . CCCli::color($value, 'green'));
         }
     };
     // print info
     $list(array('Runtime Class' => $app, 'CCF Version' => \ClanCats::version(), 'CCF Environment' => \ClanCats::environment(), 'Development env' => var_export(\ClanCats::in_development(), true), 'File extention' => EXT, 'Core namespace' => CCCORE_NAMESPACE));
     // paths
     $this->line(PHP_EOL . "Paths", 'cyan');
     $list(\ClanCats::paths());
     // paths
     $this->line(PHP_EOL . "Directories", 'cyan');
     $list(\ClanCats::directories());
     // autoloader
     $this->line(PHP_EOL . "Autoloader - namespaces", 'cyan');
     $list(\CCFinder::$namespaces);
 }
Exemple #5
0
 */
$paths = (require CCROOT . 'boot/paths' . EXT);
/*
 *---------------------------------------------------------------
 * the direcotries
 *---------------------------------------------------------------
 * 
 * Here are the module directories defined. 
 * @ToDo: move them to the classes that use that direcotries. 
 *        that way the you could subclass a class and define 
 *        a custom direcotry.
 */
$directories = array('controller' => 'controllers/', 'language' => 'language/', 'class' => 'classes/', 'console' => 'console/', 'config' => 'config/', 'view' => 'views/', 'test' => 'tests/');
/*
 *---------------------------------------------------------------
 * wake CCF
 *---------------------------------------------------------------
 * 
 * Lets require the ClanCatsFramework resources
 */
require $paths['core'] . 'wake' . EXT;
/*
 *---------------------------------------------------------------
 * wake the application
 *---------------------------------------------------------------
 * 
 * Lets wake the main application.
 */
ClanCats::wake_app('App');
// at this point the app has completet its own boot
CCProfiler::check("CCF - App completed.");
Exemple #6
0
 /**
  * start the ccf lifecycle
  *
  * this method sets the current environment, loads the configuration
  * and wakes the application
  *
  * @param string			$environment
  * @return void
  */
 public static function wake($environment)
 {
     if (!is_null(static::$environment)) {
         throw new CCException("ClanCats::wake - you cannot wake the application twice.");
     }
     // set environment
     static::$environment = $environment;
     // load the main configuration
     static::$config = CCConfig::create('main');
     // setup the application error tables
     CCError_Inspector::info_callback('ClanCatsFramework', function () {
         return array('Runtime Class' => \ClanCats::runtime(), 'CCF Version' => \ClanCats::version(), 'CCF Environment' => \ClanCats::environment(), 'Development env' => var_export(\ClanCats::in_development(), true), 'File extention' => EXT, 'Core namespace' => CCCORE_NAMESPACE);
     });
     CCError_Inspector::info_callback('CCF Paths', array('ClanCats', 'paths'));
     CCError_Inspector::info_callback('CCF Directories', array('ClanCats', 'directories'));
     CCError_Inspector::info_callback('Namespaces', function () {
         return \CCFinder::$namespaces;
     });
 }
Exemple #7
0
<?php

/*
 *---------------------------------------------------------------
 * Mail configuration
 *---------------------------------------------------------------
 */
return array('transporter' => array('main' => array('driver' => 'array'), 'alias' => 'main'), 'disabled' => false, 'layout' => 'CCUnit::mail', 'catch_all' => array('enabled' => false, 'addresses' => array(), 'transporter' => null), 'bcc' => array(), 'from' => array('*****@*****.**', ClanCats::runtime('name')));
 /**
  * the index function is just "function <controller_name>Index() {}" 
  */
 public function action_index()
 {
     $this->theme->topic = "Willkommen";
     $this->view = $this->theme->view('welcome', array('runtime_name' => ClanCats::runtime('name'), 'environment' => ClanCats::environment()));
 }
Exemple #9
0
 function _dd($var)
 {
     if (ClanCats::is_cli()) {
         var_dump($var);
     } else {
         echo "<pre>";
         var_dump($var);
         echo "</pre>";
     }
     die;
 }
Exemple #10
0
 * 
 * Lets wake the ccf and pass the environment.
 */
ClanCats::wake($environment);
unset($environment);
// at this point ccf has completet its own boot
CCProfiler::check("CCF - Boot completed.");
/*
 *---------------------------------------------------------------
 * output buffer
 *---------------------------------------------------------------
 * 
 * Start output buffering if it isn't disabled and we are not 
 * running ccf from the command line interface.
 */
if (!ClanCats::is_cli() && ClanCats::$config->output_buffering) {
    ob_start();
}
/*
 *---------------------------------------------------------------
 * timezone
 *---------------------------------------------------------------
 * 
 * Sets the default timezone used by all php native date/time 
 * functions in the application. 
 */
if (ClanCats::$config->timezone) {
    if (!date_default_timezone_set(ClanCats::$config->timezone)) {
        throw new CCException("CCF - The given timezone is invalid. check main config -> timezone.");
    }
}
Exemple #11
0
    echo to('@auth.sign_in');
    ?>
">Sign In</a>
					</li>
					<li>
						<a href="<?php 
    echo to('@auth.sign_up');
    ?>
">Sign Up</a>
					</li>
					<?php 
}
?>
					
					<?php 
if (ClanCats::in_development()) {
    ?>
					<li class="dropdown">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dev Toolbox <b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="<?php 
    echo to('dev/session/');
    ?>
">Session Sandbox</a></li>
							<li><a href="<?php 
    echo to('dev/mail/');
    ?>
">Mail Sandbox</a></li>
							<li><a href="<?php 
    echo to('dev/common/phpinfo');
    ?>
Exemple #12
0
 /**
  * Run the query and return the PDO statement
  *
  * @param string			$query
  * @param array 			$params
  * @return array
  */
 public function statement($query, $params = array())
 {
     // we alway prepare the query even if we dont have parameters
     $sth = $this->driver()->connection()->prepare($query);
     // because we set pdo the throw exception on db errors
     // we catch them here to throw our own exception.
     try {
         $sth->execute($params);
     } catch (\PDOException $e) {
         throw new Exception("DB\\Handler - PDOException: {$e->getMessage()} \n Query: {$query}");
     }
     // In development we alway log the query into an array.
     if (\ClanCats::in_development()) {
         $keys = array();
         foreach ($params as $key => $value) {
             if (is_string($key)) {
                 $keys[] = '/:' . $key . '/';
             } else {
                 $keys[] = '/[?]/';
             }
         }
         static::$_query_log[] = preg_replace($keys, $params, $query, 1);
     }
     return $sth;
 }
Exemple #13
0
 /**
  * generates a path for a config name
  *
  * @param string		$name
  * @param bool		$env
  */
 protected function path($name, $env = false)
 {
     $conf = CCPath::get($name, \CCDIR_CONFIG, static::EXT);
     if (!$env) {
         return $conf;
     }
     $env_conf = CCPath::get($name, \CCDIR_CONFIG . ClanCats::environment() . '/', static::EXT);
     if (file_exists($env_conf)) {
         return $env_conf;
     }
     return $conf;
 }
Exemple #14
0
 /**
  * Session constructor
  *
  * @param string 		$name
  * @param array 			$config
  */
 protected function __construct($name, $config = null)
 {
     if (is_null($config)) {
         $config = \CCConfig::create('session')->get($name);
         // check for an alias. If you set a string
         // in your config file we use the config
         // with the passed key.
         if (is_string($config)) {
             $config = \CCConfig::create('session')->get($config);
         }
     }
     if (empty($config)) {
         throw new Exception("Session\\Manager::create - Invalid session manager (" . $name . ").");
     }
     // also don't forget to set the name manager name becaue we need him later.
     $this->_name = $name;
     // keep the configuration array
     $this->_config = $config;
     // Setup the driver class. We simply use name
     // from the confif file and make the first letter
     // capital. example: Handler_Mysql, Handler_Sqlite etc.
     $driver_class = __NAMESPACE__ . "\\Manager_" . ucfirst($config['driver']);
     if (!class_exists($driver_class)) {
         throw new Exception("Session\\Manager::create - The driver (" . $driver_class . ") is invalid.");
     }
     $this->set_driver($driver_class);
     // try to get the id from cookie
     $this->id = $this->cookie_session_id();
     // set the fingerprint
     $this->fingerprint = sha1($this->id);
     // Before reading we might have to kill old sessions using
     // the Garbage collector
     if (\CCArr::get('gc.enabled', $this->_config, true)) {
         if (mt_rand(1, \CCArr::get('gc.factor', $this->_config, 25)) == 1) {
             $this->gc();
         }
     }
     // Register a shutdown event to write the session down
     // This should not happen on shutdown if we using command line
     if (!\ClanCats::is_cli()) {
         \CCEvent::mind('CCF.shutdown', array($this, 'write'));
     }
     // Now get the inital data from our driver
     $this->read();
 }
Exemple #15
0
<?php

/*
 *---------------------------------------------------------------
 * Mail configuration
 *---------------------------------------------------------------
 */
return array('transporter' => array('main' => array('driver' => 'sendmail', 'path' => '/usr/sbin/sendmail')), 'disabled' => false, 'layout' => null, 'catch_all' => array('enabled' => false, 'addresses' => array(), 'transporter' => null), 'bcc' => array(), 'from' => array('*****@*****.**', ClanCats::runtime('name')));
Exemple #16
0
<?php

/**
 * CCFTheme default configuration
 */
return array('default' => array('topic' => 'no title', 'title' => '%s | ' . ClanCats::runtime('name'), 'description' => 'Change your default description under theme.config -> defatul.description.', 'sidebar' => false));
Exemple #17
0
 /**
  * Test CC directories
  */
 public function testEnvironment_detector()
 {
     $original_host = $_SERVER['HTTP_HOST'];
     $_SERVER['HTTP_HOST'] = 'localhost';
     $this->assertEquals('development', \ClanCats::environment_detector(array('local*' => 'development', ':all' => 'testenv')));
     $_SERVER['HTTP_HOST'] = 'example.com';
     $this->assertEquals('testenv', \ClanCats::environment_detector(array('local*' => 'development', ':all' => 'testenv')));
     $this->assertEquals('example_env', \ClanCats::environment_detector(array('local*' => 'development', 'example.com' => 'example_env', ':all' => 'testenv')));
     $this->assertEquals('example_env', \ClanCats::environment_detector(array('local*' => 'development', 'example*' => 'example_env', ':all' => 'testenv')));
     $this->assertEquals('example_env', \ClanCats::environment_detector(array('local*' => 'development', '*example.com' => 'example_env', ':all' => 'testenv')));
     $_SERVER['HTTP_HOST'] = 'www.example.com';
     $this->assertEquals('example_env', \ClanCats::environment_detector(array('local*' => 'development', '*example.com' => 'example_env', ':all' => 'testenv')));
 }
Exemple #18
0
		  </div>
		  <div class="form-group">
		   	<label for="input-subject">Subject</label>
		   	<input name="subject" type="text" class="form-control" id="input-subject" value="Dev Mail Sandbox" placeholder="E-Mail">
		  </div>
		  <div class="form-group">
		   	<label for="input-from_name">Message</label>
		   	<textarea name="message" class="form-control" rows="3"></textarea>
		  </div>
		  <div class="checkbox">
			<label>
			  <input value="1" name="plaintext" type="checkbox"> Plaintext?
			</label>
		  </div>
		  <button type="submit" class="btn btn-primary">Send</button>
		</form>
	</div>
	
	<div class="col-md-6">
		
		<h4>Enirnoment <small><?php 
echo ClanCats::environment();
?>
</small></h4>
		<pre style="overflow: auto; overflow-x:scroll;white-space: nowrap;"><?php 
echo $config_dump;
?>
</pre>
	</div>
</div>
Exemple #19
0
 /**
  * Is CCFile able to print information
  *
  * @return bool
  */
 protected static function _can_print()
 {
     return ClanCats::is_cli() && static::$_print_infos ? true : false;
 }
Exemple #20
0
 /**
  * Returns the available migrations
  *
  * @return array
  */
 public static function available()
 {
     $bundles = array_merge(\CCFinder::$bundles, array('app' => \CCPath::get('', null)));
     $available = array();
     foreach ($bundles as $name => $path) {
         $directory = $path . \ClanCats::directory('migration');
         if (is_dir($directory)) {
             $available[strtolower($name)] = static::get_migrations($directory);
         }
     }
     return $available;
 }
Exemple #21
0
 /**
  * exception handler
  *
  * @param Exception 		$exception
  * @return void
  */
 public static function exception($exception)
 {
     // clean the main output buffer
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     $error_handler = "\\" . CCCORE_NAMESPACE . "\\CCError_Handler" . (ClanCats::is_cli() ? '_Cli' : '');
     $error_inspector = "\\" . CCCORE_NAMESPACE . "\\CCError_Inspector";
     if (is_object(ClanCats::$config) && ClanCats::$config instanceof CCConfig) {
         $error_handler = ClanCats::$config->get('error.' . (ClanCats::is_cli() ? 'cli_' : '') . 'handler', $error_handler);
         $error_inspector = ClanCats::$config->get('error.inspector', $error_inspector);
     }
     $inspector = new $error_inspector($exception);
     $handler = new $error_handler($inspector);
     $handler->handle();
 }
Exemple #22
0
$directories = array('controller' => 'controllers/', 'language' => 'language/', 'class' => 'classes/', 'console' => 'console/', 'config' => 'config/', 'view' => 'views/', 'test' => 'tests/');
/*
 *---------------------------------------------------------------
 * environment setup
 *---------------------------------------------------------------
 *
 * force the environment to phpunit.
 */
$environment = 'phpunit';
/*
 *---------------------------------------------------------------
 * wake CCF
 *---------------------------------------------------------------
 * 
 * Lets require the ClanCatsFramework resources
 */
require $paths['core'] . 'wake' . EXT;
// wake the phpunit application class this bypasses a failure
// of the clancats::runtime unitest
ClanCats::wake_app('PHPUnitApp');
/*
 *---------------------------------------------------------------
 * CCUnit resources
 *---------------------------------------------------------------
 *
 * For the unit tests we need some additional resources like
 * controllers, views, ect... 
 */
CCOrbit::enter(COREPATH . 'orbit/CCUnit');
// writ header
CCCli::line("==============================\n    _____ _____ ______ \n   / ____/ ____|  ____|\n  | |   | |    | |__   \n  | |   | |    |  __|  \n  | |___| |____| |     \n   \\_____\\_____|_| ramework\n==============================\n", 'cyan');