示例#1
0
文件: File.php 项目: clancats/core
 /**
  * Read the configuration data 
  * Get the configuration data and return them as array
  *
  * @param string		$name
  * @return array
  */
 public function read($name)
 {
     // check for absolut path
     if (substr($name, 0, 1) == '/' && file_exists($name)) {
         return $this->read_file($name);
     }
     $in_namespace = false;
     // split the namespace
     if (strpos($name, '::') !== false) {
         $conf = explode('::', $name);
         $in_namespace = $conf[0];
         $name = $conf[1];
         unset($conf);
     }
     // the two holders
     $main = $default = array();
     /*
      * App config
      * if app config try to load the equal core config as defaults
      */
     if (!$in_namespace) {
         $core_conf = $this->path(CCCORE_NAMESPACE . '::' . $name, true);
         $app_conf = $this->path($name, true);
         if (file_exists($core_conf)) {
             $default = $this->read_file($core_conf);
         }
         if (file_exists($app_conf)) {
             $main = $this->read_file($app_conf);
         }
     } elseif ($in_namespace) {
         $main_conf = $this->path($in_namespace . '::' . $name, true);
         $app_conf = $this->path($name, true);
         if (file_exists($main_conf)) {
             $default = $this->read_file($main_conf);
         }
         if (file_exists($app_conf)) {
             $main = $this->read_file($app_conf);
         }
     }
     // finally return the data
     return CCArr::merge($default, $main);
 }
示例#2
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);
 }
示例#3
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;
 }
示例#4
0
文件: CCArr.php 项目: clancats/core
 /**
  * test values by key
  *
  * @expectedException        InvalidArgumentException
  */
 public function testArrayMergeException()
 {
     CCArr::merge('test');
 }