Esempio n. 1
0
 public static function bootstrap($approot = null)
 {
     static $done = 0;
     if ($done) {
         return;
     }
     $done = 1;
     foreach ((array) xenon::config('framework.preload') as $preload) {
         class_exists($preload, true);
     }
     $dm = (int) xenon::config('framework.debuglevel');
     if ($dm == 0) {
         setenv("DEBUG=0");
     }
     if ($dm >= 1) {
         setenv("DEBUG=1");
     }
     if ($dm >= 2) {
         setenv("DEBUG_VERBOSE=1");
     }
     $path = getenv("CHERRY_LIB");
     require_once $path . '/lib/bootstrap.php';
     if (!$approot) {
         $approot = getcwd();
     } else {
         $approot = realpath($approot);
     }
     \Cherry\Base\PathResolver::getInstance()->setAppPath($approot);
     define("XENON_FWAPI", '\\xenon\\frameworks\\cherryphp');
 }
Esempio n. 2
0
 /**
  *
  *
  *
  *
  */
 public function loadView($view)
 {
     $path = PathResolver::getInstance()->getPath("{APP}/views/{$view}");
     require $path;
 }
Esempio n. 3
0
 public function __construct($uri, $opts = array())
 {
     $opts = (array) $opts;
     if (!empty($opts['pool'])) {
         $this->pool = $opts['pool'];
     } else {
         $this->pool = $uri;
     }
     if (!$uri) {
         throw new \UnexpectedValueException("DatabaseConnection::__construct() expects an URI");
     }
     $ci = parse_url($uri);
     $this->uri = $uri;
     if (strpos($uri, "://") === false) {
         // Connectionstring is in PDO format
         throw new \Exception("Invalid URI: {$uri}");
     } else {
         $type = $ci['scheme'];
         if (!$type) {
             throw new \UnexpectedArgumentException("'{$type}' is not a supported database type");
         }
         if ($type == "mysql") {
             $username = !empty($ci['user']) ? $ci['user'] : get_current_user();
             $password = !empty($ci['pass']) ? $ci['pass'] : null;
             $host = !empty($ci['host']) ? $ci['host'] : 'localhost';
             $database = !empty($ci['path']) ? trim($ci['path'], "/") : null;
             $dsn = "mysql:host={$host};";
             if (!empty($ci['port']) && $ci['port'] != 3306) {
                 $port = $ci['port'];
                 $dsn .= "port={$port}";
             }
             $dsn .= "dbname={$database}";
             $options = [];
             $this->database = $database;
             if (!$password) {
                 $password = $this->getKeystorePassword($type, $username, $host, $database);
             }
             $this->connid = "MySQL:{$host}/{$database}";
         } elseif ($type == "sqlite") {
             $database = "{APP}/{$ci['host']}";
             if (!empty($ci['path'])) {
                 $database .= '/' . $ci['path'];
             }
             $database = \Cherry\Base\PathResolver::path($database);
             $this->debug("SQLite3: Using database {$database}");
             $dsn = "sqlite:{$database}";
             $username = null;
             $password = null;
             $options = [];
             $this->connid = "SQLite3:{$database}";
         } else {
             throw new \Exception("Invalid connection uri '{$uri}'");
         }
     }
     $this->type = $type;
     // Temporarily change the PHP exception handler while we . . .
     set_exception_handler(array(__CLASS__, 'exception_handler'));
     // . . . create a PDO object
     $this->conn = new PDO($dsn, $username, $password, $options);
     $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     // Change the exception handler back to whatever it was before
     restore_exception_handler();
 }