Esempio n. 1
0
 public function __construct($params = null)
 {
     if (isset($params['baseurl'])) {
         $this->_baseUrl = $params['baseurl'];
     } else {
         $this->_baseUrl = c::config()->baseUrl->{c::env()};
     }
 }
Esempio n. 2
0
 public function __construct($params)
 {
     if (!$params || !is_object($params)) {
         $params = new Cana_Model();
     }
     if (!$params->dir) {
         $params->dir = 'data';
     }
     $this->dir = c::config()->dirs->cache . $params->dir . '/';
     if (!file_exists($this->dir)) {
         mkdir($this->dir, 0777);
     }
     if (isset($params->expire)) {
         $this->expire = $params->expire;
     }
     if (isset($params->suffix)) {
         $this->suffix = $params->suffix;
     }
 }
Esempio n. 3
0
 /** 
  * Sets a config value by key
  *
  * @param  string  $key The key to define
  * @param  mixed   $value The value for the passed key
  */
 static function set($key, $value = null)
 {
     if (is_array($key)) {
         // set all new values
         self::$config = array_merge(self::$config, $key);
     } else {
         self::$config[$key] = $value;
     }
 }
Esempio n. 4
0
 /**
  * Filter whitespace to remove unwanted spaces.
  *
  * @param	string	the content to pass
  * @param	array	array of config values
  *	filter	bool	whether or not to run the filter (overwrite object var)
  * @return	string
  */
 private function outputFilter($content, $params)
 {
     $env = c::env();
     if (!c::config()->templates->{$env}->compress) {
         return $content;
     }
     if (isset($params['filter']) && $params['filter'] || !isset($params['filter']) && $this->_useFilter != false) {
         $find = ['/^(\\s?)(.*?)(\\s?)$/', '/\\t|\\n|\\r/', '/(\\<\\!\\-\\-)(.*?)\\-\\-\\>/'];
         $replace = ['\\2', '', ''];
         return preg_replace($find, $replace, $content);
     } else {
         return $content;
     }
 }
Esempio n. 5
0
 public static function timeout($func, $ms = null, $async = true, $forceEnv = false)
 {
     $closure = new Cana_SuperClosure($func);
     $encoded = base64_encode(serialize($closure));
     if ($ms) {
         $sleep = ' -s=' . $ms;
     }
     if ($forceEnv) {
         $env = ' -e=' . $forceEnv;
     } else {
         $env = ' -e=' . c::getEnv(false);
     }
     if (file_exists('/usr/local/bin/php')) {
         $v = 'local';
     } else {
         $v = 'auto';
     }
     $cmd = c::config()->dirs->root . 'cli/timeout-' . $v . '.php' . $sleep . ' -c=' . str_replace("'", '"', escapeshellarg($encoded)) . $env;
     if (getenv('TRAVIS')) {
         $async = false;
     }
     if ($async) {
         try {
             $log = getenv('TRAVIS') ? '/dev/null' : '/var/log/timeout';
             exec('nohup ' . $cmd . ' >> ' . $log . ' 2>&1 &');
         } catch (Exception $e) {
             Crunchbutton_Log::error(['type' => 'timeout exception', 'cmd' => $cmd]);
         }
     } else {
         exec($cmd . ' 2>&1 &', $o);
         if ($o) {
             print_r($o);
         }
     }
 }