当前位置: 首页>>代码示例>>PHP>>正文


PHP VQMod::fileModding方法代码示例

本文整理汇总了PHP中VQMod::fileModding方法的典型用法代码示例。如果您正苦于以下问题:PHP VQMod::fileModding方法的具体用法?PHP VQMod::fileModding怎么用?PHP VQMod::fileModding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VQMod的用法示例。


在下文中一共展示了VQMod::fileModding方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: applyMod

 /**
  * VQModObject::applyMod()
  *
  * @param array $mods Array of search add nodes
  * @param string $data File contents to be altered
  * @return null
  * @description Applies all modifications to the text data
  */
 public function applyMod($mods, &$data)
 {
     if ($this->_skip) {
         return;
     }
     $tmp = $data;
     foreach ($mods as $mod) {
         VQMod::$fileModding = $mod['fileToMod'] . '(' . $mod['opIndex'] . ')';
         if (!empty($mod['ignoreif'])) {
             if ($mod['ignoreif']->regex == 'true') {
                 if (preg_match($mod['ignoreif']->getContent(), $tmp)) {
                     continue;
                 }
             } else {
                 if (strpos($tmp, $mod['ignoreif']->getContent()) !== false) {
                     continue;
                 }
             }
         }
         $indexCount = 0;
         $tmp = $this->_explodeData($tmp);
         $lineMax = count($tmp) - 1;
         switch ($mod['search']->position) {
             case 'top':
                 $tmp[$mod['search']->offset] = $mod['add']->getContent() . $tmp[$mod['search']->offset];
                 break;
             case 'bottom':
                 $offset = $lineMax - $mod['search']->offset;
                 if ($offset < 0) {
                     $tmp[-1] = $mod['add']->getContent();
                 } else {
                     $tmp[$offset] .= $mod['add']->getContent();
                 }
                 break;
             default:
                 $changed = false;
                 foreach ($tmp as $lineNum => $line) {
                     if (strlen($mod['search']->getContent()) == 0) {
                         if ($mod['error'] == 'log' || $mod['error'] == 'abort') {
                             VQMod::$log->write('VQModObject::applyMod - EMPTY SEARCH CONTENT ERROR', $this);
                         }
                         break;
                     }
                     if ($mod['search']->regex == 'true') {
                         $pos = @preg_match($mod['search']->getContent(), $line);
                         if ($pos === false) {
                             if ($mod['error'] == 'log' || $mod['error'] == 'abort') {
                                 VQMod::$log->write('VQModObject::applyMod - INVALID REGEX ERROR - ' . $mod['search']->getContent(), $this);
                             }
                             continue 2;
                         } elseif ($pos == 0) {
                             $pos = false;
                         }
                     } else {
                         $pos = strpos($line, $mod['search']->getContent());
                     }
                     if ($pos !== false) {
                         $indexCount++;
                         $changed = true;
                         if (!$mod['search']->indexes() || $mod['search']->indexes() && in_array($indexCount, $mod['search']->indexes())) {
                             switch ($mod['search']->position) {
                                 case 'before':
                                     $offset = $lineNum - $mod['search']->offset < 0 ? -1 : $lineNum - $mod['search']->offset;
                                     $tmp[$offset] = empty($tmp[$offset]) ? $mod['add']->getContent() : $mod['add']->getContent() . "\n" . $tmp[$offset];
                                     break;
                                 case 'after':
                                     $offset = $lineNum + $mod['search']->offset > $lineMax ? $lineMax : $lineNum + $mod['search']->offset;
                                     $tmp[$offset] = $tmp[$offset] . "\n" . $mod['add']->getContent();
                                     break;
                                 case 'ibefore':
                                     $tmp[$lineNum] = str_replace($mod['search']->getContent(), $mod['add']->getContent() . $mod['search']->getContent(), $line);
                                     break;
                                 case 'iafter':
                                     $tmp[$lineNum] = str_replace($mod['search']->getContent(), $mod['search']->getContent() . $mod['add']->getContent(), $line);
                                     break;
                                 default:
                                     if (!empty($mod['search']->offset)) {
                                         for ($i = 1; $i <= $mod['search']->offset; $i++) {
                                             if (isset($tmp[$lineNum + $i])) {
                                                 $tmp[$lineNum + $i] = '';
                                             }
                                         }
                                     }
                                     if ($mod['search']->regex == 'true') {
                                         $tmp[$lineNum] = preg_replace($mod['search']->getContent(), $mod['add']->getContent(), $line);
                                     } else {
                                         $tmp[$lineNum] = str_replace($mod['search']->getContent(), $mod['add']->getContent(), $line);
                                     }
                                     break;
                             }
                         }
                     }
//.........这里部分代码省略.........
开发者ID:honeynatividad,项目名称:mircatu,代码行数:101,代码来源:vqmod.php

示例2: _parseMods

 /**
  * VQModObject::_parseMods()
  *
  * @param DOMNode $node <modification> node to be parsed
  * @return null
  * @description Parses modifications in preparation for the applyMod method to work
  */
 private function _parseMods(DOMNode $node)
 {
     $files = $node->getElementsByTagName('file');
     $replaces = VQMod::$replaces;
     foreach ($files as $file) {
         $path = $file->getAttribute('path') ? $file->getAttribute('path') : '';
         $filesToMod = explode(',', $file->getAttribute('name'));
         foreach ($filesToMod as $filename) {
             $fileToMod = $path . $filename;
             if (!empty($replaces)) {
                 foreach ($replaces as $r) {
                     if (count($r) == 2) {
                         $fileToMod = preg_replace($r[0], $r[1], $fileToMod);
                     }
                 }
             }
             $error = $file->hasAttribute('error') ? $file->getAttribute('error') : 'log';
             $fullPath = VQMod::_realpath($fileToMod);
             if (!$fullPath || !file_exists($fullPath)) {
                 if (strpos($fileToMod, '*') !== false) {
                     $fullPath = VQMod::getCwd() . $fileToMod;
                 } else {
                     if ($error == 'log' || $error == 'abort') {
                         $skip = $error == 'log' ? ' (SKIPPED)' : ' (ABORTING MOD)';
                         VQMod::$log->write('VQModObject::parseMods - Could not resolve path for [' . $fileToMod . ']' . $skip, $this);
                     }
                     if ($error == 'log' || $error == 'skip') {
                         continue;
                     } elseif ($error == 'abort') {
                         return false;
                     }
                 }
             }
             $operations = $file->getElementsByTagName('operation');
             foreach ($operations as $opIndex => $operation) {
                 VQMod::$fileModding = $fileToMod . '(' . $opIndex . ')';
                 $skipOperation = false;
                 $error = $operation->hasAttribute('error') ? $operation->getAttribute('error') : 'abort';
                 $ignoreif = $operation->getElementsByTagName('ignoreif')->item(0);
                 if ($ignoreif) {
                     $ignoreif = new VQSearchNode($ignoreif);
                 } else {
                     $ignoreif = false;
                 }
                 $search = $operation->getElementsByTagName('search')->item(0);
                 $add = $operation->getElementsByTagName('add')->item(0);
                 if (!$search) {
                     VQMod::$log->write('Operation <search> tag missing', $this);
                     $skipOperation = true;
                 }
                 if (!$add) {
                     VQMod::$log->write('Operation <add> tag missing', $this);
                     $skipOperation = true;
                 }
                 if (!$skipOperation) {
                     $this->mods[$fullPath][] = array('search' => new VQSearchNode($search), 'add' => new VQAddNode($add), 'ignoreif' => $ignoreif, 'error' => $error, 'fileToMod' => $fileToMod, 'opIndex' => $opIndex);
                 }
             }
             VQMod::$fileModding = false;
         }
     }
 }
开发者ID:sabasco,项目名称:gnscms,代码行数:69,代码来源:vqmod.php


注:本文中的VQMod::fileModding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。