Esempio n. 1
0
 /**
  * CCController factory
  *
  * @param string			$path
  * @return CCController
  */
 public static function create($path)
 {
     $class = static::find($path);
     // if class already loaded
     if (!class_exists($class, false)) {
         // register the controller with the autoloader
         \CCFinder::bind($class, CCPath::get($path, CCDIR_CONTROLLER, 'Controller' . EXT));
     }
     // create new controller instance and assign the name
     $controller = new $class();
     $controller->name = $path;
     return $controller;
 }
Esempio n. 2
0
 /**
  * Load a language file into the appliaction
  *
  *     CCLang::load( 'some/path/to/file' );
  *     CCLang::load( 'controller/example' );
  *     CCLang::load( 'Blog::controller/dashboard' );
  *
  * @param string			$path
  * @param bool			$overwrite
  * @return void
  */
 public static function load($path, $overwrite = false)
 {
     if (array_key_exists($path, static::$data[static::$current_language]) && $overwrite === false) {
         return;
     }
     $file_path = CCPath::get($path, CCDIR_LANGUAGE . static::$current_language . '/', EXT);
     if (!file_exists($file_path)) {
         // as fallback try to load the language file of the default language
         if (static::$current_language !== ($default_lang = ClanCats::$config->get('language.default'))) {
             $file_path = CCPath::get($path, CCDIR_LANGUAGE . $default_lang . '/', EXT);
             if (!file_exists($file_path)) {
                 throw new CCException("CCLang::load - could not find language file: " . $file_path);
             }
         } else {
             throw new CCException("CCLang::load - could not find language file: " . $file_path);
         }
     }
     static::$data[static::$current_language][$path] = (require $file_path);
 }
Esempio n. 3
0
<?php

/*
 *---------------------------------------------------------------
 * Database configuration for phpunit
 *---------------------------------------------------------------
 */
return array('main' => 'app', 'app' => array('db' => 'ccf2_phpunit_application', 'driver' => 'mysql', 'host' => '127.0.0.1', 'user' => 'root', 'pass' => '', 'charset' => 'utf8'), 'phpunit' => array('db' => 'ccf2_phpunit_database', 'driver' => 'mysql', 'host' => '127.0.0.1', 'user' => 'root', 'pass' => '', 'charset' => 'utf8'), 'phpunit_sqlite' => array('driver' => 'sqlite', 'path' => CCPath::get('CCUnit::test.db'), 'charset' => 'utf8'));
Esempio n. 4
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;
 }
Esempio n. 5
0
 /**
  * Run a console script
  *
  * @param string		$controller
  * @param string		$action	
  * @param array 		$params
  */
 public static function run($controller, $action = null, $params = array())
 {
     // always enable the file infos
     // this allows CCFile to print an info when a file gets created or deleted.
     CCFile::enable_infos();
     // execute by default the help action
     if (empty($action)) {
         $action = 'default';
     }
     $path = CCPath::get($controller, CCDIR_CONSOLE, EXT);
     // check if the file exists, if not try with core path
     if (!file_exists($path)) {
         if (!CCPath::contains_namespace($controller)) {
             $path = CCPath::get(CCCORE_NAMESPACE . '::' . $controller, CCDIR_CONSOLE, EXT);
         }
     }
     // still nothing?
     if (!file_exists($path)) {
         CCCli::line("Could not find controller {$controller}.", 'red');
         return false;
     }
     // all console classes should be on the CCConsole namespace
     // this way you can easly overwrite a console script
     $class = 'CCConsole\\' . $controller;
     // add the class to the autoloader
     \CCFinder::bind($class, $path);
     // create an instance
     $class = new $class($action, $params);
     // run wake function
     if (method_exists($class, 'wake')) {
         call_user_func(array($class, 'wake'), $params);
     }
     // run the execution
     call_user_func(array($class, '_execute'), $action, $params);
     // run sleep
     if (method_exists($class, 'sleep')) {
         call_user_func(array($class, 'sleep'), $params);
     }
 }
Esempio n. 6
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;
 }
Esempio n. 7
0
 /**
  * Get the path to real view file
  *
  * This function will also build the cache view file if needed.
  *
  * @param string 		$path
  * @return string 
  */
 protected function view_path($view)
 {
     if (isset(static::$_view_paths[$view])) {
         return static::$_view_paths[$view];
     }
     // view is empty?
     if (is_null($view)) {
         throw new CCException("CCView - cannot render view without a view file.");
     }
     // generate the views path
     $path = CCPath::get($view, CCDIR_VIEW, EXT);
     if (!file_exists($path)) {
         throw new CCException("CCView - could not find view: " . $view . " at: {$path}.");
     }
     // does the view implement a view builder?
     if (strpos($view, '.') !== false) {
         $cache = static::cache_path($view);
         // does the cache not exits or is out of date
         if (!file_exists($cache) || filemtime($cache) < filemtime($path)) {
             list($view_name, $builder) = explode('.', $view);
             $this->build_cache($cache, $builder, $path);
         }
         $path = $cache;
     }
     return static::$_view_paths[$view] = $path;
 }