replaceProperties() публичный статический Метод

Replace ${} style constructions in the given value with the string value of the corresponding data types. This method is static.
public static replaceProperties ( Project $project, $value, $keys ) : string
$project Project
Результат string the replaced string or null if the string itself was null
 /**
  * Returns next query from SQL source, null if no more queries left
  *
  * In case of "row" delimiter type this searches for strings containing only
  * delimiters. In case of "normal" delimiter type, this uses simple regular
  * expression logic to search for delimiters.
  *
  * @return string|null
  */
 public function nextQuery()
 {
     $sql = "";
     $hasQuery = false;
     while (($line = $this->sqlReader->readLine()) !== null) {
         $delimiter = $this->parent->getDelimiter();
         $project = $this->parent->getOwningTarget()->getProject();
         $line = ProjectConfigurator::replaceProperties($project, trim($line), $project->getProperties());
         if ($line != $delimiter && (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line))) {
             continue;
         }
         if (strlen($line) > 4 && strtoupper(substr($line, 0, 4)) == "REM ") {
             continue;
         }
         // MySQL supports defining new delimiters
         if (preg_match('/DELIMITER [\'"]?([^\'" $]+)[\'"]?/i', $line, $matches)) {
             $this->parent->setDelimiter($matches[1]);
             continue;
         }
         if ($this->sqlBacklog !== "") {
             $sql = $this->sqlBacklog;
             $this->sqlBacklog = "";
         }
         $sql .= " " . $line . "\n";
         // SQL defines "--" as a comment to EOL
         // and in Oracle it may contain a hint
         // so we cannot just remove it, instead we must end it
         if (strpos($line, "--") !== false) {
             $sql .= "\n";
         }
         // DELIM_ROW doesn't need this (as far as i can tell)
         if ($this->delimiterType == PDOSQLExecTask::DELIM_NORMAL) {
             $reg = "#((?:\"(?:\\\\.|[^\"])*\"?)+|'(?:\\\\.|[^'])*'?|" . preg_quote($delimiter) . ")#";
             $sqlParts = preg_split($reg, $sql, 0, PREG_SPLIT_DELIM_CAPTURE);
             $this->sqlBacklog = "";
             foreach ($sqlParts as $sqlPart) {
                 // we always want to append, even if it's a delim (which will be stripped off later)
                 $this->sqlBacklog .= $sqlPart;
                 // we found a single (not enclosed by ' or ") delimiter, so we can use all stuff before the delim as the actual query
                 if ($sqlPart === $delimiter) {
                     $sql = $this->sqlBacklog;
                     $this->sqlBacklog = "";
                     $hasQuery = true;
                 }
             }
         }
         if ($hasQuery || $this->delimiterType == PDOSQLExecTask::DELIM_ROW && $line == $delimiter) {
             // this assumes there is always a delimter on the end of the SQL statement.
             $sql = StringHelper::substring($sql, 0, strlen($sql) - strlen($delimiter) - ($this->delimiterType == PDOSQLExecTask::DELIM_ROW ? 2 : 1));
             return $sql;
         }
     }
     // Catch any statements not followed by ;
     if ($sql !== "") {
         return $sql;
     }
     return null;
 }
 /**
  * Returns the filtered stream. 
  * The original stream is first read in fully, and the Phing properties are expanded.
  * 
  * @return mixed     the filtered stream, or -1 if the end of the resulting stream has been reached.
  * 
  * @exception IOException if the underlying stream throws an IOException
  * during reading
  */
 function read($len = null)
 {
     $buffer = $this->in->read($len);
     if ($buffer === -1) {
         return -1;
     }
     $project = $this->getProject();
     $buffer = ProjectConfigurator::replaceProperties($project, $buffer, $project->getProperties(), $this->logLevel);
     return $buffer;
 }
 /**
  * Returns entire SQL source
  *
  * @return string|null
  */
 public function nextQuery()
 {
     $sql = null;
     while (($line = $this->sqlReader->readLine()) !== null) {
         $delimiter = $this->parent->getDelimiter();
         $project = $this->parent->getOwningTarget()->getProject();
         $line = ProjectConfigurator::replaceProperties($project, trim($line), $project->getProperties());
         if ($line != $delimiter && (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line))) {
             continue;
         }
         $sql .= " " . $line . "\n";
     }
     return $sql;
 }
Пример #4
0
 protected function initPhingProperties(Project $project)
 {
     // Apply all file properties, then all non-file properties
     $properties = new Properties();
     foreach ($this->fileProps as $key => $value) {
         $properties->put($key, $value);
     }
     foreach ($this->customProps as $key => $value) {
         $properties->put($key, $value);
     }
     // Then swap out placeholder values
     foreach ($properties->getProperties() as $key => $value) {
         $value = ProjectConfigurator::replaceProperties($project, $value, $properties->getProperties());
         $project->setProperty($key, $value);
     }
 }
 /**
  * Returns entire SQL source
  *
  * @return string|null
  */
 public function nextQuery()
 {
     $sql = null;
     while (($line = $this->sqlReader->readLine()) !== null) {
         $delimiter = $this->parent->getDelimiter();
         $project = $this->parent->getOwningTarget()->getProject();
         $line = ProjectConfigurator::replaceProperties($project, trim($line), $project->getProperties());
         if ($line != $delimiter && (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line))) {
             continue;
         }
         $sql .= " " . $line . "\n";
         /**
          * fix issue with PDO and wrong formated multistatements
          * @issue 1108
          */
         if (StringHelper::endsWith($delimiter, $line)) {
             break;
         }
     }
     return $sql;
 }
 /**
  * Gets next symbol from the input, false if at end
  *
  * @return string|bool
  */
 public function getc()
 {
     if (!strlen($this->line) || $this->inputIndex >= strlen($this->line)) {
         if (null === ($line = $this->sqlReader->readLine())) {
             return false;
         }
         $project = $this->parent->getOwningTarget()->getProject();
         $this->line = ProjectConfigurator::replaceProperties($project, $line, $project->getProperties()) . "\n";
         $this->inputIndex = 0;
     }
     return $this->line[$this->inputIndex++];
 }
Пример #7
0
 /**
  * Replaces ${} style constructions in the given value with the
  * string value of the corresponding data types.
  *
  * @param string $value The value string to be scanned for property references.
  *                      May be <code>null</code>.
  *
  * @return string the given string with embedded property names replaced
  *                by values, or <code>null</code> if the given string is
  *                <code>null</code>.
  *
  * @exception BuildException if the given value has an unclosed
  *                           property name, e.g. <code>${xxx</code>
  */
 public function replaceProperties($value)
 {
     return ProjectConfigurator::replaceProperties($this, $value, $this->properties);
 }
Пример #8
0
 /**
  *  Tests if the property set in unlessCondition exists.
  *
  *  @return  boolean  <code>true</code> if the property specified
  *                    in <code>$this->unlessCondition</code> exists;
  *                    <code>false</code> otherwise
  */
 private function testUnlessCondition()
 {
     if ($this->unlessCondition === "") {
         return true;
     }
     $properties = explode(",", $this->unlessCondition);
     $result = true;
     foreach ($properties as $property) {
         $test = ProjectConfigurator::replaceProperties($this->getProject(), $property, $this->project->getProperties());
         $result = $result && $this->project->getProperty($test) === null;
     }
     return $result;
 }
 /**
  * read in lines and execute them
  * @param Reader $reader
  * @param null $out
  * @throws BuildException
  */
 public function runStatements(Reader $reader, $out = null)
 {
     $sql = "";
     $line = "";
     $buffer = '';
     if (is_array($this->filterChains) && !empty($this->filterChains)) {
         $in = FileUtils::getChainedReader(new BufferedReader($reader), $this->filterChains, $this->getProject());
         while (-1 !== ($read = $in->read())) {
             // -1 indicates EOF
             $buffer .= $read;
         }
         $lines = explode("\n", $buffer);
     } else {
         $in = new BufferedReader($reader);
         while (($line = $in->readLine()) !== null) {
             $lines[] = $line;
         }
     }
     try {
         foreach ($lines as $line) {
             $line = trim($line);
             $line = ProjectConfigurator::replaceProperties($this->project, $line, $this->project->getProperties());
             if (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line)) {
                 continue;
             }
             if (strlen($line) > 4 && strtoupper(substr($line, 0, 4)) == "REM ") {
                 continue;
             }
             $sql .= " " . $line;
             $sql = trim($sql);
             // SQL defines "--" as a comment to EOL
             // and in Oracle it may contain a hint
             // so we cannot just remove it, instead we must end it
             if (strpos($line, "--") !== false) {
                 $sql .= "\n";
             }
             if ($this->delimiterType == self::DELIM_NORMAL && StringHelper::endsWith($this->delimiter, $sql) || $this->delimiterType == self::DELIM_ROW && $line == $this->delimiter) {
                 $this->log("SQL: " . $sql, Project::MSG_VERBOSE);
                 $this->execSQL(StringHelper::substring($sql, 0, strlen($sql) - strlen($this->delimiter)), $out);
                 $sql = "";
             }
         }
         // Catch any statements not followed by ;
         if ($sql !== "") {
             $this->execSQL($sql, $out);
         }
     } catch (SQLException $e) {
         throw new BuildException("Error running statements", $e);
     }
 }
 /**
  * Read the statements from the .sql file and execute them.
  * Lines starting with '//', '--' or 'REM ' are ignored.
  *
  * Developer note:  must be public in order to be called from
  * sudo-"inner" class PropelSQLExecTransaction.
  *
  * @param      Reader $reader
  * @param      $out Optional output stream.
  * @throws     SQLException
  * @throws     IOException
  */
 public function runStatements(Reader $reader, $out = null)
 {
     $sql = "";
     $line = "";
     $sqlBacklog = "";
     $hasQuery = false;
     $in = new BufferedReader($reader);
     try {
         while (($line = $in->readLine()) !== null) {
             $line = trim($line);
             $line = ProjectConfigurator::replaceProperties($this->project, $line, $this->project->getProperties());
             if (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line)) {
                 continue;
             }
             if (strlen($line) > 4 && strtoupper(substr($line, 0, 4)) == "REM ") {
                 continue;
             }
             if ($sqlBacklog !== "") {
                 $sql = $sqlBacklog;
                 $sqlBacklog = "";
             }
             $sql .= " " . $line . "\n";
             // SQL defines "--" as a comment to EOL
             // and in Oracle it may contain a hint
             // so we cannot just remove it, instead we must end it
             if (strpos($line, "--") !== false) {
                 $sql .= "\n";
             }
             // DELIM_ROW doesn't need this (as far as i can tell)
             if ($this->delimiterType == self::DELIM_NORMAL) {
                 $reg = "#((?:\"(?:\\\\.|[^\"])*\"?)+|'(?:\\\\.|[^'])*'?|" . preg_quote($this->delimiter) . ")#";
                 $sqlParts = preg_split($reg, $sql, 0, PREG_SPLIT_DELIM_CAPTURE);
                 $sqlBacklog = "";
                 foreach ($sqlParts as $sqlPart) {
                     // we always want to append, even if it's a delim (which will be stripped off later)
                     $sqlBacklog .= $sqlPart;
                     // we found a single (not enclosed by ' or ") delimiter, so we can use all stuff before the delim as the actual query
                     if ($sqlPart === $this->delimiter) {
                         $sql = $sqlBacklog;
                         $sqlBacklog = "";
                         $hasQuery = true;
                     }
                 }
             }
             if ($hasQuery || $this->delimiterType == self::DELIM_ROW && $line == $this->delimiter) {
                 // this assumes there is always a delimter on the end of the SQL statement.
                 $sql = StringHelper::substring($sql, 0, strlen($sql) - 1 - strlen($this->delimiter));
                 $this->log("SQL: " . $sql, PROJECT_MSG_VERBOSE);
                 $this->execSQL($sql, $out);
                 $sql = "";
                 $hasQuery = false;
             }
         }
         // Catch any statements not followed by ;
         if ($sql !== "") {
             $this->execSQL($sql, $out);
         }
     } catch (SQLException $e) {
         throw $e;
     }
 }
Пример #11
0
 /**
  * Read the statements from the .sql file and execute them.
  * Lines starting with '//', '--' or 'REM ' are ignored.
  *
  * Developer note:  must be public in order to be called from
  * sudo-"inner" class PropelSQLExecTransaction.
  *
  * @param      Reader $reader
  * @param      $out Optional output stream.
  * @throws     PDOException
  * @throws     IOException
  */
 public function runStatements(Reader $reader, $out = null)
 {
     $sql = "";
     $line = "";
     $sqlBacklog = "";
     $hasQuery = false;
     $in = new BufferedReader($reader);
     $parser['pointer'] = 0;
     $parser['isInString'] = false;
     $parser['stringQuotes'] = "";
     $parser['backslashCount'] = 0;
     $parser['parsedString'] = "";
     $sqlParts = array();
     while (($line = $in->readLine()) !== null) {
         $line = trim($line);
         $line = ProjectConfigurator::replaceProperties($this->project, $line, $this->project->getProperties());
         if (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line)) {
             continue;
         }
         if (strlen($line) > 4 && strtoupper(substr($line, 0, 4)) == "REM ") {
             continue;
         }
         if ($sqlBacklog !== "") {
             $sql = $sqlBacklog;
             $sqlBacklog = "";
         }
         $sql .= " " . $line . PHP_EOL;
         // SQL defines "--" as a comment to EOL
         // and in Oracle it may contain a hint
         // so we cannot just remove it, instead we must end it
         if (strpos($line, "--") !== false) {
             $sql .= PHP_EOL;
         }
         // DELIM_ROW doesn't need this (as far as i can tell)
         if ($this->delimiterType == self::DELIM_NORMAL) {
             // old regex, being replaced due to segfaults:
             // See: http://propel.phpdb.org/trac/ticket/294
             //$reg = "#((?:\"(?:\\\\.|[^\"])*\"?)+|'(?:\\\\.|[^'])*'?|" . preg_quote($this->delimiter) . ")#";
             //$sqlParts = preg_split($reg, $sql, 0, PREG_SPLIT_DELIM_CAPTURE);
             $i = $parser['pointer'];
             $c = strlen($sql);
             while ($i < $c) {
                 $char = $sql[$i];
                 switch ($char) {
                     case "\\":
                         $parser['backslashCount']++;
                         $this->log("c{$i}: found " . $parser['backslashCount'] . " backslash(es)", Project::MSG_VERBOSE);
                         break;
                     case "'":
                     case "\"":
                         if ($parser['isInString'] && $parser['stringQuotes'] == $char) {
                             if (($parser['backslashCount'] & 1) == 0) {
                                 #$this->log("$i: out of string", Project::MSG_VERBOSE);
                                 $parser['isInString'] = false;
                             } else {
                                 $this->log("c{$i}: rejected quoted delimiter", Project::MSG_VERBOSE);
                             }
                         } elseif (!$parser['isInString']) {
                             $parser['stringQuotes'] = $char;
                             $parser['isInString'] = true;
                             #$this->log("$i: into string with $parser['stringQuotes']", Project::MSG_VERBOSE);
                         }
                         break;
                 }
                 if ($char == $this->delimiter && !$parser['isInString']) {
                     $this->log("c{$i}: valid end of command found!", Project::MSG_VERBOSE);
                     $sqlParts[] = $parser['parsedString'];
                     $sqlParts[] = $this->delimiter;
                     break;
                 }
                 $parser['parsedString'] .= $char;
                 if ($char !== "\\") {
                     if ($parser['backslashCount']) {
                         $this->log("{$i}: backslash reset", Project::MSG_VERBOSE);
                     }
                     $parser['backslashCount'] = 0;
                 }
                 $i++;
                 $parser['pointer']++;
             }
             $sqlBacklog = "";
             foreach ($sqlParts as $sqlPart) {
                 // we always want to append, even if it's a delim (which will be stripped off later)
                 $sqlBacklog .= $sqlPart;
                 // we found a single (not enclosed by ' or ") delimiter, so we can use all stuff before the delim as the actual query
                 if ($sqlPart === $this->delimiter) {
                     $sql = $sqlBacklog;
                     $sqlBacklog = "";
                     $hasQuery = true;
                 }
             }
         }
         if ($hasQuery || $this->delimiterType == self::DELIM_ROW && $line == $this->delimiter) {
             // this assumes there is always a delimter on the end of the SQL statement.
             $sql = StringHelper::substring($sql, 0, strlen($sql) - 1 - strlen($this->delimiter));
             $this->log("SQL: " . $sql, Project::MSG_VERBOSE);
             $this->execSQL($sql, $out);
             $sql = "";
             $hasQuery = false;
             $parser['pointer'] = 0;
             $parser['isInString'] = false;
             $parser['stringQuotes'] = "";
             $parser['backslashCount'] = 0;
             $parser['parsedString'] = "";
             $sqlParts = array();
         }
     }
     // Catch any statements not followed by ;
     if ($sql !== "") {
         $this->execSQL($sql, $out);
     }
 }
 /**
  * read in lines and execute them
  * @throws SQLException, IOException 
  */
 public function runStatements(Reader $reader, $out = null)
 {
     $sql = "";
     $line = "";
     $in = new BufferedReader($reader);
     try {
         while (($line = $in->readLine()) !== null) {
             $line = trim($line);
             $line = ProjectConfigurator::replaceProperties($this->project, $line, $this->project->getProperties());
             if (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line)) {
                 continue;
             }
             if (strlen($line) > 4 && strtoupper(substr($line, 0, 4)) == "REM ") {
                 continue;
             }
             $sql .= " " . $line;
             $sql = trim($sql);
             // SQL defines "--" as a comment to EOL
             // and in Oracle it may contain a hint
             // so we cannot just remove it, instead we must end it
             if (strpos($line, "--") !== false) {
                 $sql .= "\n";
             }
             if ($this->delimiterType == self::DELIM_NORMAL && StringHelper::endsWith($this->delimiter, $sql) || $this->delimiterType == self::DELIM_ROW && $line == $this->delimiter) {
                 $this->log("SQL: " . $sql, PROJECT_MSG_VERBOSE);
                 $this->execSQL(StringHelper::substring($sql, 0, strlen($sql) - strlen($this->delimiter) - 1), $out);
                 $sql = "";
             }
         }
         // Catch any statements not followed by ;
         if ($sql !== "") {
             $this->execSQL($sql, $out);
         }
     } catch (SQLException $e) {
         throw new BuildException("Error running statements", $e);
     }
 }