예제 #1
0
 /**
  * test methods
  */
 public function testMagicMethods()
 {
     $object = CCDataObject::assign($this->test_array);
     // test isset
     $this->assertTrue(isset($object->string));
     $this->assertFalse(isset($object->notexisting));
     // test get
     $this->assertEquals($object->string, 'bar');
     // test set
     $object->test = "hello";
     $this->assertEquals($object->test, 'hello');
     $this->assertEquals($object->get('test'), 'hello');
     // test delete
     unset($object->test);
     $this->assertFalse(isset($object->test));
     $this->assertFalse($object->has('test'));
 }
예제 #2
0
파일: shipyard.php 프로젝트: clancats/core
 /**
  * generate ships
  *
  * exmample:
  * run shipyard::ship <name>
  * run shipyard::ship <name> <namespace>
  * run shipyard::ship <name> --no-namespace
  *
  * @param array 		$params 
  * @return void
  */
 public function action_ship($params)
 {
     $options = \CCDataObject::assign($params);
     $name = $options->get(0, null);
     $namespace = $options->get(1, null);
     // get name if we dont have one
     while (!$name) {
         $name = CCCli::read('Please enter the ship name: ');
     }
     // set namespace
     if (!$namespace) {
         $namespace = $name;
     }
     // no namespace?
     if ($params['no-namespace']) {
         $namespace = false;
     }
     // custom target
     $target = $options->get('target', ORBITPATH);
     if (substr($target, 0, 1) !== '/') {
         $target = CCFPATH . $target;
     }
     if (substr($target, -1) !== '/') {
         $target .= '/';
     }
     $target .= $name . '/';
     // check if the module is in our orbit path
     if (is_dir($target)) {
         if (!CCCli::confirm("there is already a ship with this name. do you want to overwrite?", true)) {
             return;
         }
     }
     // create the blueprint
     $defaults = \CCConfig::create('shipyard');
     $blueprint = array('name' => $name, 'version' => $defaults->get('defaults.version'), 'description' => $defaults->get('defaults.description'), 'homepage' => $defaults->get('defaults.homepage'), 'keywords' => $defaults->get('defaults.keywords'), 'license' => $defaults->get('defaults.license'), 'authors' => $defaults->get('defaults.authors'), 'namespace' => $namespace);
     // create file
     \CCJson::write($target . 'blueprint.json', $blueprint, true);
     $ship = \CCOrbit_Ship::blueprint($blueprint, $target);
     // create event files
     if ($namespace) {
         // create forge instance
         $forge = new \CCForge_Php($namespace);
         // add header
         $forge->comment($this->make_comment_header($ship->name . ' ship', array('package' => $ship->name, 'authors' => $ship->authors, 'version' => $ship->version, 'copyright' => \CCConfig::create('shipyard')->get('defaults.copyright'))));
         // add class
         $forge->closure('class Ship extends \\CCOrbit_Ship', function () {
             $forge = new \CCForge_Php();
             // add init function
             echo $forge->closure('public function wake()', '// Do stuff', "initialize the ship\n\n" . "@return void");
             echo $forge->line(2);
             // add init function
             echo $forge->closure('public function install()', '// Do stuff', "install the ship\n\n" . "@return void");
             echo $forge->line(2);
             // add init function
             echo $forge->closure('public function unsintall()', '// Do stuff', "uninstall the ship\n\n" . "@return void");
         });
         \CCFile::write($target . CCDIR_CLASS . 'Ship' . EXT, $forge);
     } else {
         // create forge instance
         $forge = new \CCForge_Php();
         // add header
         $forge->comment($this->make_comment_header($ship->name, array('package' => $ship->name, 'authors' => $ship->authors, 'version' => $ship->version, 'copyright' => \CCConfig::create('shipyard')->get('defaults.copyright'))));
         \CCFile::write($target . 'shipyard/wake' . EXT, $forge);
         \CCFile::write($target . 'shipyard/install' . EXT, $forge);
         \CCFile::write($target . 'shipyard/uninstall' . EXT, $forge);
     }
     // sucess
     CCCli::line("'" . $name . "' succesfully created under: " . $target, 'green');
 }
예제 #3
0
 /**
  * Transporter instance constructor
  *
  * @param string 		$name
  * @param array 			$config
  * @return void
  */
 public function __construct($name, $config = null)
 {
     if (is_null($config)) {
         $config = \CCConfig::create('mail')->get('transporter.' . $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('mail')->get('transporter.' . $config);
         }
     }
     if (!is_array($config)) {
         throw new Exception("Auth\\Handler::create - Invalid auth handler (" . $name . ").");
     }
     // also don't forget to set the name manager name becaue we need him later.
     $this->name = $name;
     // assign defaults and create the configuration object
     $this->config = \CCDataObject::assign(\CCArr::merge(array('driver' => 'sendmail'), $config));
     // load the driver
     $driver_class = __NAMESPACE__ . '\\Transporter_' . ucfirst($this->config->driver);
     if (!class_exists($driver_class)) {
         throw new Exception("Invalid mail driver '" . $this->config->driver . "'");
     }
     $this->driver = new $driver_class($this->config);
 }
예제 #4
0
파일: Handler.php 프로젝트: clancats/core
 /**
  * Auth instance constructor
  *
  * @param string 		$name
  * @param array 			$config
  * @return void
  */
 public function __construct($name, $config = null)
 {
     if (is_null($config)) {
         $config = \CCConfig::create('auth')->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('auth')->get($config);
         }
     }
     if (!is_array($config)) {
         throw new Exception("Auth\\Handler::create - Invalid auth handler (" . $name . ").");
     }
     // also don't forget to set the name manager name becaue we need him later.
     $this->name = $name;
     // assign defaults and create the configuration object
     $this->config = \CCDataObject::assign(\CCArr::merge(array('session_manager' => null, 'session_key' => 'user_id', 'user_key' => 'id', 'user_model' => "\\Auth\\User", 'identifiers' => array('email'), 'logins' => array('handler' => null, 'table' => 'auth_logins'), 'restore' => array('id_cookie' => 'ccauth-restore-id', 'token_cookie' => 'ccauth-restore-token', 'lifetime' => \CCDate::months(1))), $config));
     // set the session handler
     $this->session = \CCSession::manager($this->config->session_manager);
     $user_model = $this->config->user_model;
     // set a empty default user object to avoid
     // on a non object errors
     $this->user = new $user_model();
     // do we already have a user id means are we
     // logged in?
     if (!is_null($session_key = $this->session_user_id())) {
         if ($user = $user_model::find($this->config->user_key, $session_key)) {
             $this->user = $user;
             return $this->authenticated = true;
         }
     } else {
         $restore_id_cookie = $this->config->get('restore.id_cookie');
         $restore_token_cookie = $this->config->get('restore.token_cookie');
         if (CCCookie::has($restore_id_cookie) && CCCookie::has($restore_token_cookie)) {
             // get the restore cookies
             $restore_id = CCCookie::get($restore_id_cookie);
             $restore_token = CCCookie::get($restore_token_cookie);
             // get the restore login
             $login = $this->select_logins()->where('restore_id', $restore_id)->where('restore_token', $restore_token)->limit(1);
             // if no login found kill the cookies and return
             if (!($login = $login->run())) {
                 $this->kill_restore();
                 return $this->authenticated = false;
             }
             // Invalid user? kill the cookies and return
             if (!($user = $user_model::find($this->config->user_key, $restore_id))) {
                 $this->kill_restore();
                 return $this->authenticated = false;
             }
             // validate the restore key if invalid
             // once again kill the cookies and return
             if ($login->restore_token != $this->restore_key($user)) {
                 $this->kill_restore();
                 return $this->authenticated = false;
             }
             // If everything is fine sign the user in and
             // update the restore keys
             $this->sign_in($user, true);
             return $this->authenticated = true;
         }
     }
     return $this->authenticated = false;
 }
예제 #5
0
파일: Class.php 프로젝트: clancats/core
 /**
  * generates an file header string
  *
  * @param string		$title
  * @param array 		$data
  * @return string
  */
 protected function file_header($title, $data = array())
 {
     $conf = \CCConfig::create('shipyard');
     $data = CCDataObject::assign($data);
     // Build the authors string
     $authors = $data->get('authors', $conf->get('defaults.authors'));
     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);
     }
     // Finish comment heeader
     return "{$title}\n" . "*\n" . "\n" . "@package       " . $data->get('package', $conf->get('defaults.package')) . "\n" . "@author        " . $author_str . "\n" . "@version       " . $data->get('version', $conf->get('defaults.version')) . "\n" . "@copyright     " . $data->get('copyright', $conf->get('defaults.copyright')) . "\n";
 }