123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- include_once 'phing/mappers/FileNameMapper.php';
- class GlobMapper implements FileNameMapper {
-
- private $fromPrefix = null;
-
- private $fromPostfix = null;
-
- private $prefixLength;
-
- private $postfixLength;
-
- private $toPrefix = null;
-
- private $toPostfix = null;
- function main($_sourceFileName) {
- if (($this->fromPrefix === null)
- || !StringHelper::startsWith($this->fromPrefix, $_sourceFileName)
- || !StringHelper::endsWith($this->fromPostfix, $_sourceFileName)) {
- return null;
- }
- $varpart = $this->_extractVariablePart($_sourceFileName);
- $substitution = $this->toPrefix.$varpart.$this->toPostfix;
- return array($substitution);
- }
- function setFrom($from) {
- $index = strrpos($from, '*');
- if ($index === false) {
- $this->fromPrefix = $from;
- $this->fromPostfix = "";
- } else {
- $this->fromPrefix = substr($from, 0, $index);
- $this->fromPostfix = substr($from, $index+1);
- }
- $this->prefixLength = strlen($this->fromPrefix);
- $this->postfixLength = strlen($this->fromPostfix);
- }
-
- function setTo($to) {
- $index = strrpos($to, '*');
- if ($index === false) {
- $this->toPrefix = $to;
- $this->toPostfix = "";
- } else {
- $this->toPrefix = substr($to, 0, $index);
- $this->toPostfix = substr($to, $index+1);
- }
- }
- private function _extractVariablePart($_name) {
-
- $start = ($this->prefixLength === 0) ? 0 : $this->prefixLength;
- $end = ($this->postfixLength === 0) ? strlen($_name) : strlen($_name) - $this->postfixLength;
- $len = $end-$start;
- return substr($_name, $start, $len);
- }
- }
|