DbPatch_Core_Parser::parse PHP Метод

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

public static parse ( $command, $params )
    public static function parse($command, $params)
    {
        if (!is_array($params)) {
            throw new DbPatch_Exception('params array expected');
        }
        $orgKeys = array_keys($params);
        $keys = array_map(array('DbPatch_Core_Parser', 'mapKeyParam'), $orgKeys);
        $values = array_values($params);
        // remove empty tags first
        preg_match_all('/({%([0-9A-Za-z_-]+)%})(.*?)({%\\2%})/', $command, $matches);
        foreach ($matches[2] as $index => $key) {
            if (in_array($key, $orgKeys) && !empty($params[$key])) {
                $command = str_replace($matches[1][$index], '', $command);
                continue;
            }
            $command = str_replace($matches[0][$index], '', $command);
        }
        $output = str_replace($keys, $values, $command);
        return $output;
    }

Usage Example

Пример #1
0
 /**
  * @param string $command Shell command template to execute,
  *                takes :configkey notation
  * @param string $filename Filename of patch or dump file
  * @return string Command to execute
  */
 protected function getCliCommand($command, $filename)
 {
     $config = $this->getAdapter()->getConfig();
     $params = array();
     $params['filename'] = $filename;
     $keys = array('host', 'port', 'username', 'password', 'dbname', 'charset', 'filename');
     foreach ($keys as $key) {
         if (isset($config[$key]) && !empty($config[$key])) {
             $params[$key] = escapeshellarg($config[$key]);
         }
     }
     return DbPatch_Core_Parser::parse($command, $params);
 }
All Usage Examples Of DbPatch_Core_Parser::parse
DbPatch_Core_Parser