diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-09-14 09:05:07 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-09-14 09:05:07 +0200 |
commit | f00fa7c860e3da817fd4b88a2d58cae130a70d50 (patch) | |
tree | dcc52f9240bba929edd761b84a64686cd4ae1acc | |
parent | 139d4d06e0fd97aa5783d7ea24c5d37e703cd19a (diff) | |
download | savane-gray-f00fa7c860e3da817fd4b88a2d58cae130a70d50.tar.gz savane-gray-f00fa7c860e3da817fd4b88a2d58cae130a70d50.tar.bz2 |
Synchronize meta-variable expansion rules in frontend with backend
Port the expandvars method from Savane::Feature to PHP, so that
the meta-variables such as PROJECT and REPO are handled similarly
by both backend and frontend.
* frontend/php/include/Group.class (_expandvars)
(_expandfield): New private functions.
(getTypeUrl,getTypeDir)
(getSubRepoUrl,getSubRepoDir): Rewrite using _expandfield.
-rw-r--r-- | frontend/php/include/Group.class | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/frontend/php/include/Group.class b/frontend/php/include/Group.class index e5b1a71..2880f6e 100644 --- a/frontend/php/include/Group.class +++ b/frontend/php/include/Group.class @@ -132,25 +132,63 @@ class Group extends Error # Url, Dir, CanUse, Permission # (all takes an argument) + private function _expandvars($subject, $repl) + { + $res = ''; + while (preg_match('/(?<pref>[^{%]*)%(?:\{(?<x>[A-Z]+)\}|(?<y>[A-Z]+))(?<tail>.*)/', $subject, $matches)) + { + $var = $matches['x'] ? $matches['x'] : $matches['y']; + + if (isset($repl[$var]) && $repl[$var] != '') + { + $res .= $matches['pref'] . $repl[$var]; + $subject = $matches['tail']; + } + else if (preg_match('/(.*)\/$/', $matches['pref'], $m0) + && preg_match('/^(?:([\/.].*))?$/', + $matches['tail'], + $m1)) + { + $res .= $m0[1]; + $subject = $m1[1]; + } + else + { + $res .= $matches['pref']; + $subject = $matches['tail']; + } + } + return $res.$subject; + } + + private function _expandfield($field, $repl) + { + return $this->_expandvars($this->type_data_array[$field], $repl); + } + function getTypeUrl($artifact) - { return ereg_replace("%PROJECT", $this->getUnixName(), - $this->type_data_array['url_'.$artifact]); + { + return $this->_expandvars('url_'.$artifact, + array('PROJECT' => $this->getUnixName())); } function getTypeDir($artifact) - { return ereg_replace("%PROJECT", $this->getUnixName(), - $this->type_data_array['dir_'.$artifact]); + { + return $this->_expandvars('dir_'.$artifact, + array('PROJECT' => $this->getUnixName())); } function getSubRepoUrl($name,$artifact) { - return ereg_replace("%PROJECT", $this->getUnixName() . "/" . $name, - $this->type_data_array['url_'.$artifact]); + return $this->_expandvars('url_'.$artifact, + array('PROJECT' => $this->getUnixName(), + 'REPO' => $name)); } function getSubRepoDir($name,$artifact) { - return ereg_replace("%PROJECT", $this->getUnixName() . "/" . $name, - $this->type_data_array['dir_'.$artifact]); + return $this->_expandvars('dir_'.$artifact, + array('PROJECT' => $this->getUnixName(), + 'REPO' => $name)); } function CanUse($artifact) |