コード例 #1
0
ファイル: xml_parser.php プロジェクト: williammoran/DBSteward
 /**
  * Validate the passed XML string against the DBSteward DTD
  * 
  * @param type $xml
  * @param type $echo_status
  * @throws exception
  */
 public static function validate_xml($xml, $echo_status = TRUE)
 {
     // because of the various ways PEAR may be installed for or by the user
     // streamline DTD use out of the box by
     // creating a list of possible relative paths where the DTD can be found
     // @NOTICE: the FIRST path that is readable will be used
     $dtd_file_paths = array(__DIR__ . '/../DBSteward/dbsteward.dtd', $dtd_file = __DIR__ . '/../data/DBSteward/DBSteward/dbsteward.dtd', $dtd_file = __DIR__ . '/../../data/DBSteward/DBSteward/dbsteward.dtd', $dtd_file = __DIR__ . '/../../../data/DBSteward/DBSteward/dbsteward.dtd');
     foreach ($dtd_file_paths as $dtd_file_path) {
         if (is_readable($dtd_file_path)) {
             $dtd_file = $dtd_file_path;
         }
     }
     if (!is_readable($dtd_file)) {
         throw new exception("DTD file dbsteward.dtd not readable from any known source paths:\n" . implode("\n", $dtd_file_paths));
     }
     // attempt to verify that xmllint exists on the system
     if ($echo_status) {
         dbsteward::debug("Locating xmllint executable...");
     }
     // which will return 1 on failure to find executable, so dbsteward::cmd will throw an exception
     try {
         $whereIsCommand = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? 'where' : 'which';
         dbsteward::cmd("{$whereIsCommand} xmllint");
     } catch (Exception $ex) {
         throw new Exception("Could not locate xmllint executable. Please ensure it is in your PATH, or install libxml2 from http://xmlsoft.org");
     }
     if ($echo_status) {
         dbsteward::debug("Found xmllint");
     }
     // realpath the dtd_file so when it is announced it is simplified to remove relative directory pathing
     $dtd_file = realpath($dtd_file);
     if ($echo_status) {
         dbsteward::info("Validating XML (size = " . strlen($xml) . ") against {$dtd_file}");
     }
     $tmp_file = tempnam(sys_get_temp_dir(), 'dbsteward_validate_');
     if (file_put_contents($tmp_file, $xml) === FALSE) {
         throw new exception("Failed to write to temporary validation file: " . $tmp_file);
     }
     dbsteward::cmd("xmllint --noout --dtdvalid " . $dtd_file . " " . $tmp_file . " 2>&1");
     if ($echo_status) {
         dbsteward::info("XML Validates (size = " . strlen($xml) . ") against {$dtd_file} OK");
     }
     unlink($tmp_file);
 }
コード例 #2
0
 protected function pipe_file_to_client($file_name)
 {
     dbsteward::cmd(sprintf("mysql -v --host=%s --port=%s --user=%s --database=%s --password=%s < '%s'", $this->dbhost, $this->dbport, $this->dbuser, $this->dbname, $this->dbpass, $file_name));
 }
コード例 #3
0
 protected function pipe_file_to_client($file_name)
 {
     dbsteward::cmd(sprintf("PGPASSWORD='******' psql --host=%s --port=%s --username=%s --dbname=%s -v ON_ERROR_STOP=1 --file '%s' 2>&1", $this->dbpass_mgmt, $this->dbhost, $this->dbport, $this->dbuser, $this->dbname, $file_name));
 }