示例#1
0
 /**
  * Get connection.
  */
 public function getConnection($reset = false)
 {
     static $conn;
     if ($reset === TRUE) {
         $conn = null;
         unset($conn);
         static $conn;
     }
     if (!$conn) {
         // Connecting to mysql
         if (empty(Config::get('db.DATABASE'))) {
             die('Database parameters needed.');
         } else {
             try {
                 // Config mysql link
                 $conn = new PDO('mysql:host=' . Config::get('db.HOSTNAME') . ';dbname=' . Config::get('db.DATABASE') . ';port=' . Config::get('db.PORT'), Config::get('db.USERNAME'), Config::get('db.PASSWORD'));
                 $conn->exec('SET CHARACTER SET utf8');
                 $conn->exec('SET time_zone = "' . date_default_timezone_get() . '"');
                 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                 if (Config::get('core.DEBUG_BAR') === true && $reset === false) {
                     $config = Config::getInstance();
                     $pdo = new \DebugBar\DataCollector\PDO\TraceablePDO($conn);
                     $config->debugbar->addCollector(new \DebugBar\DataCollector\PDO\PDOCollector($pdo));
                 }
             } catch (\PDOException $e) {
                 throw new QException($e->getMessage());
             }
         }
     }
     return $conn;
 }
示例#2
0
 /**
  * Constructor.
  */
 public function __construct($file = '')
 {
     // Set router
     if (php_sapi_name() !== 'cli') {
         $this->router = new Router();
     }
     if (php_sapi_name() === 'cli' && !file_exists(GLOBAL_PATH . '/App/Config.yml')) {
         $file = GLOBAL_PATH . '/App/Config_example.yml';
     }
     // Set config
     $config = Config::getInstance();
     $config->loadFile($file);
     // Set session vars
     ini_set('session.cookie_lifetime', $config['session']['cookie_lifetime']);
     ini_set('session.gc_probability', $config['session']['gc_probability']);
     ini_set('session.gc_divisor', $config['session']['gc_divisor']);
     ini_set('session.gc_maxlifetime', $config['session']['gc_maxlifetime']);
     ini_set('session.cookie_httponly', $config['session']['cookie_httponly']);
     if (!empty($config['session']['SESSION_PATH'])) {
         ini_set('session.save_path', GLOBAL_PATH . $config['session']['SESSION_PATH']);
     }
     if (Config::get('core.DEV_MODE', false)) {
         ini_set('display_errors', 1);
     }
 }
示例#3
0
 public function execute($args)
 {
     if (null === Config::get('app.THEME_PATH') || null === Config::get('app.THEME_BASE_PATH')) {
         exit($this->makeRed("Themes cannot be null (Check your Config.yml) \n"));
     }
     $resources = Config::get('app.RESOURCES', array());
     $resources[Config::get('app.THEME_PATH') . '/Resources'] = Config::get('app.THEME_URL');
     if (Config::get('app.THEME_PATH') !== Config::get('app.THEME_BASE_PATH')) {
         $resources[Config::get('app.THEME_BASE_PATH') . '/Resources'] = Config::get('app.THEME_BASE_URL');
     }
     // Copy all resources
     foreach ($resources as $source => $destRelative) {
         $dest = GLOBAL_PATH . '/public' . $destRelative;
         echo "Copying ";
         $this->makeGreen('/public' . $destRelative);
         echo "\n";
         if (!file_exists($dest)) {
             mkdir($dest, 0755, true);
         }
         $sourceIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($sourceIterator as $item) {
             $destPath = $dest . '/' . $sourceIterator->getSubPathName();
             if ($item->isDir()) {
                 if (!is_dir($destPath)) {
                     if (file_exists($destPath)) {
                         unlink($destPath);
                     }
                     mkdir($destPath, 0755);
                 }
             } else {
                 if (file_exists($destPath)) {
                     if (is_dir($destPath)) {
                         $filesIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($destPath, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
                         foreach ($filesIterator as $file) {
                             if ($file->isDir()) {
                                 rmdir($file->getRealPath());
                             } else {
                                 unlink($file->getRealPath());
                             }
                         }
                         rmdir($destPath);
                     } else {
                         unlink($destPath);
                     }
                 }
                 copy($item, $destPath);
             }
         }
     }
     // Remove old resources
     echo "Removing old files \n";
     foreach ($resources as $source => $destRelative) {
         $dest = GLOBAL_PATH . '/public' . $destRelative;
         $destIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dest, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($destIterator as $item) {
             $sourcePath = $source . '/' . $destIterator->getSubPathName();
             if (!file_exists($sourcePath)) {
                 if ($item->isDir()) {
                     rmdir($item->getRealPath());
                 } else {
                     unlink($item->getRealPath());
                 }
             }
         }
     }
     // Update randomVar
     if (Config::get('app.RANDOM_VAR')) {
         echo "Updating randomVar \n";
         $config = Config::getInstance();
         $elements = $config->importYML();
         $elements['app']['RANDOM_VAR'] = date('Ymd');
         if (file_exists(GLOBAL_PATH . '/App/Config.yml')) {
             rename(GLOBAL_PATH . '/App/Config.yml', GLOBAL_PATH . '/App/Config.yml.bak');
         }
         $config->exportYML('Config.yml', $elements);
     }
 }
示例#4
0
 public function execute($args)
 {
     echo "Insert database information: \n\n";
     for ($i = 0; $i < 6; $i++) {
         switch ($i) {
             case 0:
                 $command = $this->makeGreen("HOSTNAME (localhost): ", false);
                 break;
             case 1:
                 $command = $this->makeGreen("USERNAME (root): ", false);
                 break;
             case 2:
                 $command = $this->makeGreen("PASSWORD (root): ", false);
                 break;
             case 3:
                 $command = $this->makeGreen("DATABASE: ", false);
                 break;
             case 4:
                 $command = $this->makeGreen("PORT (3306): ", false);
                 break;
             case 5:
                 $command = $this->makeGreen("CIPHER_KEY (AAAAAAAA): ", false);
                 break;
         }
         $line = readline($command);
         readline_add_history($line);
     }
     // dump history
     $params = readline_list_history();
     $params[0] = empty($params[0]) ? 'localhost' : $params[0];
     $params[1] = empty($params[1]) ? 'root' : $params[1];
     $params[2] = empty($params[2]) ? 'root' : $params[2];
     $params[4] = empty($params[4]) ? '3306' : $params[4];
     $params[5] = empty($params[5]) ? 'AAAAAAAA' : $params[5];
     if (empty($params[3])) {
         $this->makeRed("\nDATABASE cannot be null\n");
         exit;
     }
     // Name of the file
     $filename = 'quaver-skeleton.sql';
     // MySQL host
     $mysql_host = $params[0];
     // MySQL username
     $mysql_username = $params[1];
     // MySQL password
     $mysql_password = $params[2];
     // Database name
     $mysql_database = $params[3];
     // Connect to MySQL server
     $mysqli = new \mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_database);
     if (mysqli_connect_errno()) {
         die($this->makeRed("Error connecting to MySQL server: (" . mysqli_connect_errno() . ") \n", false));
     }
     // Read in entire file
     $sql = file_get_contents(GLOBAL_PATH . '/vendor/millolab/quaver-cli/Quaver/' . $filename) or die($this->makeRed("Unable to open file! \n", false));
     // Execute statement
     if ($mysqli->multi_query($sql)) {
         $this->makeGreen("Tables imported successfully \n");
     } else {
         die($this->makeRed("An error has been occurred: " . $mysqli->error . " \n", false));
     }
     // Disconnect MySQL
     $mysqli->close();
     // Change Config.yml and export it
     $config = Config::getInstance();
     $configYML = $config->importYML();
     if (!isset($configYML)) {
         $configYML = $config->importYML(GLOBAL_PATH . '/App/Config_example.yml');
     }
     if (isset($configYML['db'])) {
         $configYML['db']['HOSTNAME'] = $mysql_host;
         $configYML['db']['USERNAME'] = $mysql_username;
         $configYML['db']['PASSWORD'] = $mysql_password;
         $configYML['db']['DATABASE'] = $mysql_database;
         $configYML['db']['PORT'] = (int) $params[4];
         $configYML['db']['CIPHER_KEY'] = $params[5];
         $config->exportYML('Config.yml', $configYML);
     } else {
         die($this->makeRed("An error has been occurred with Config.yml \n", false));
     }
     // Folders
     $class = new Folders();
     $class->execute(null);
     // Resources
     $class = new Resources();
     $class->execute(null);
 }