Exemple #1
0
 /**
  * packs all responses into one array
  *
  * @param array		$responses
  * @return array
  */
 protected static function pack($responses)
 {
     return array_merge(CCArr::get('before', $responses, array()), CCArr::get('main', $responses, array()), CCArr::get('after', $responses, array()));
 }
Exemple #2
0
 /**
  * generates an file header string
  *
  * @param string		$title
  * @param array 		$data
  * @return string
  */
 public function make_comment_header($title, $data = array())
 {
     // get author
     $authors = \CCArr::get('authors', $data, \CCConfig::create('shipyard')->get('defaults.authors'));
     // author
     if (is_array($authors)) {
         foreach ($authors as $person) {
             $author_str .= $person['name'] . " ";
             if (array_key_exists('email', $person)) {
                 $author_str .= "<" . $person['email'] . ">";
             }
             $author_str .= ", ";
         }
         $author_str = substr($author_str, 0, -2);
     }
     return "{$title}\n" . "*\n" . "\n" . "@package       " . \CCArr::get('package', $data, \CCConfig::create('shipyard')->get('defaults.package')) . "\n" . "@author        " . $author_str . "\n" . "@version       " . \CCArr::get('version', $data, \CCConfig::create('shipyard')->get('defaults.version')) . "\n" . "@copyright     " . \CCArr::get('copyright', $data, \CCConfig::create('shipyard')->get('defaults.copyright')) . "\n";
 }
Exemple #3
0
 /**
  * get a special item from every array
  *
  * @param mixed			$key
  * @param array[array]	$arr
  * @return array
  */
 public static function pick($key, $arr)
 {
     if (!is_array($arr)) {
         throw new \InvalidArgumentException('CCArr::pick - second argument has to be an array.');
     }
     $return = array();
     foreach ($arr as $array) {
         $return[] = CCArr::get($key, $array);
     }
     return $return;
 }
Exemple #4
0
 /**
  * Cookie driver constructor
  */
 public function __construct($name, $conf)
 {
     $this->cookie_suffix = \CCArr::get('cookie_suffix', $conf, '-session-store');
     $this->crypt_salt = \CCArr::get('crypt_salt', $conf);
 }
Exemple #5
0
 /**
  * get the path of an uplaoded file
  *
  * @param string	$key
  * @return string|false
  */
 public static function upload_path($key)
 {
     return CCArr::get('tmp_name', CCIn::file($key, array('tmp_name' => false)));
 }
Exemple #6
0
 /**
  * Cookie driver constructor
  *
  * @param string		$name
  * @param array 		$conf
  */
 public function __construct($name, $conf)
 {
     $this->database = \CCArr::get('database', $conf);
     $this->table = \CCArr::get('table', $conf, 'sessions');
     $this->index_fields = array_merge(\CCArr::get('index_fields', $conf, array()), array_keys(Manager::default_data_provider()));
 }
Exemple #7
0
 /**
  * Revert the last migration
  *
  * @return void
  */
 public static function rollback()
 {
     // first of all we have to filter only the already migrated versions
     $available = static::available();
     foreach ($available as $key => $migrations) {
         foreach ($migrations as $time => $migration) {
             if ($time > static::$config->get($key . '.revision', 0)) {
                 unset($available[$key][$time]);
             }
         }
     }
     $revisions = array();
     foreach ($available as $key => $value) {
         if (empty($value)) {
             continue;
         }
         foreach ($value as $name => $path) {
             $revisions[$name . '::' . $key] = $path;
         }
     }
     // nothing to rollback?
     if (empty($revisions)) {
         if (\ClanCats::is_cli()) {
             \CCCli::warning('nothing to rollback to.');
         }
         return false;
     }
     ksort($revisions);
     end($revisions);
     list($time, $key) = explode('::', key($revisions));
     $migration = new static(array_pop($revisions));
     // rollback the migration
     $migration->down();
     // get the lastet migration from the group
     $others = \CCArr::get($key, $available);
     ksort($others);
     array_pop($others);
     end($others);
     // update the config
     static::$config->set($key . '.revision', key($others));
     static::$config->write();
     return true;
 }
Exemple #8
0
 /**
  * test the CCArr setter
  */
 public function testArraySetItem()
 {
     $test_array = $this->test_array;
     /*
      * set string
      */
     CCArr::set('string', 'batz', $test_array);
     $this->assertEquals(CCArr::get('string', $test_array), 'batz');
     /*
      * set number
      */
     CCArr::set('array.number', 0, $test_array);
     $this->assertEquals(CCArr::get('array.number', $test_array), 0);
     /*
      * set new value
      */
     CCArr::set('not.existing.item', 'new value', $test_array);
     $this->assertEquals(CCArr::get('not.existing.item', $test_array), 'new value');
     /*
      * set value in deep field
      */
     CCArr::set('not.existing.item.in.deep.deep.field', 'deep', $test_array);
     $this->assertEquals(CCArr::get('not.existing.item.in.deep.deep.field', $test_array), 'deep');
 }
Exemple #9
0
 /**
  * Garbage collection, delete all outdated sessions
  *
  * @return void
  */
 public function gc()
 {
     $lifetime = \CCArr::get('lifetime', $this->_config, \CCDate::minutes(5));
     if ($lifetime < ($min_lifetime = \CCArr::get('min_lifetime', $this->_config, \CCDate::minutes(5)))) {
         $lifetime = $min_lifetime;
     }
     $this->_driver->gc($lifetime);
 }
Exemple #10
0
 /**
  * gets data, use a default if not set.
  *
  * @param string 	$key
  * @param mixed		$default
  * @return mixed
  */
 public function get($key, $default = null)
 {
     return CCArr::get($key, $this->_data, $default);
 }
Exemple #11
0
 /**
  * install an orbit module
  *
  * @param array 		$params 
  */
 public function action_install($params)
 {
     $path = $params[0];
     // get target directory
     $target_dir = \CCArr::get('target', $params, ORBITPATH);
     if (empty($path)) {
         CCCli::line('no ship path given.', 'red');
         return;
     }
     /*
      * direct install if starting with /
      */
     if (substr($path, 0, 1) == '/') {
         // fix path
         if (substr($path, -1) != '/') {
             $path .= '/';
         }
         // is directory
         if (!is_dir($path)) {
             CCCli::line('could not find a ship at path: ' . $path, 'red');
             return;
         }
         // define the target
         $target = $target_dir . basename($path) . '/';
         // check if we already have an directory with the same name
         if ($target != $path && is_dir($target)) {
             if (!CCCli::confirm("there is already a ship with this name. do you want to overwrite?", true)) {
                 return;
             }
         }
         // are ya serius..
         if (!CCCli::confirm("are you sure you want to install this ship?", true)) {
             return;
         }
         // move the directory
         if ($target != $path) {
             rename($path, $target);
         }
         // run the installer
         try {
             \CCOrbit::install($target);
         } catch (\Exception $e) {
             CCCli::line($e->getMessage(), 'red');
             CCCli::line('ship installation failure.', 'red');
             return;
         }
         // we are done
         CCCli::line('ship installation succeeded', 'green');
         return;
     }
     // check if the module is in our orbit path
     if (is_dir(ORBITPATH . $path)) {
         // there is a ship yay
         CCCli::line('found ship at path: ' . ORBITPATH . $path, 'green');
         return static::action_install(array(ORBITPATH . $path, 'target' => \CCArr::get('target', $params)));
     }
     // check if the module is in CCF dir
     if (is_dir(CCROOT . $path)) {
         // there is a ship yay
         CCCli::line('found ship at path: ' . CCROOT . $path, 'green');
         return static::action_install(array(CCROOT . $path, 'target' => \CCArr::get('target', $params)));
     }
     // search the repository for this ship
     CCCli::line('searching the repositories for: ' . $path . ' ...', 'cyan');
 }
Exemple #12
0
 /**
  * CCModel::__set
  *
  * @dataProvider people_provider
  */
 public function test_set($person)
 {
     $person_model = CCUnit\Model_Person::create($person);
     $person_model->age = mt_rand(-20, 20);
     $this->assertTrue($person_model->age >= 18);
     $this->assertTrue(CCArr::get('age', $person_model->raw()) >= 18);
 }