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


PHP eZSys::backupFilename方法代码示例

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


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

示例1: apply


//.........这里部分代码省略.........
             $currentBlocks = array();
             $currentTag = false;
             for ($i = 0; $i < count($split); ++$i) {
                 $part = $split[$i];
                 if ($i % 2 == 1) {
                     // The tag element
                     if ($currentTag === false) {
                         preg_match($tagRegexp, trim($part), $matches);
                         $currentTag = $matches[2];
                         if ($matches[1] == 'END') {
                             eZDebug::writeError("Tag {$currentTag} was finished before it was started, skipping it", 'eZClassTemplate::apply');
                             $currentTag = false;
                             $error = true;
                         } else {
                             if (count($currentBlocks) > 0) {
                                 $blocks[] = array('blocks' => $currentBlocks);
                             }
                             $currentBlocks = array();
                         }
                     } else {
                         preg_match($tagRegexp, trim($part), $matches);
                         $tag = $matches[2];
                         if ($matches[1] == 'END') {
                             if ($tag == $currentTag) {
                                 if (count($currentBlocks) > 0) {
                                     $blocks[] = array('tag' => $currentTag, 'blocks' => $currentBlocks);
                                 }
                                 $currentTag = false;
                                 $currentBlocks = array();
                             } else {
                                 eZDebug::writeError("End tag {$tag} does not match start tag {$currentTag}, skipping it", 'eZClassTemplate::apply');
                                 $error = true;
                             }
                         } else {
                             eZDebug::writeError("Start tag {$tag} found while {$currentTag} is active, skipping it", 'eZClassTemplate::apply');
                             $error = true;
                         }
                     }
                 } else {
                     // Plain text
                     $currentBlocks[] = $part;
                 }
             }
             if ($currentTag === false) {
                 if (count($currentBlocks) > 0) {
                     $blocks[] = array('blocks' => $currentBlocks);
                 }
             } else {
                 if (count($currentBlocks) > 0) {
                     $blocks[] = array('tag' => $currentTag, 'blocks' => $currentBlocks);
                 }
             }
             // Build new code with blocks to include
             $resultText = '';
             foreach ($blocks as $block) {
                 if (isset($block['tag'])) {
                     if (in_array($block['tag'], $parameters)) {
                         $resultText .= implode('', $block['blocks']);
                     }
                 } else {
                     $resultText .= implode('', $block['blocks']);
                 }
             }
             // Remove any end-of-line whitespaces unless keep-whitespace is used
             if (!in_array('keep-whitespace', $parameters)) {
                 $resultText = preg_replace('#[ \\t]+$#m', '', $resultText);
             }
             // Output text before the template-block
             fwrite($fd, substr($text, $offset, $createPos - $offset));
             fwrite($fd, substr($text, $createPos, $end - $createPos));
             $offset = $end;
             // Remove any existing auto-generated code
             $autogenRegexp = '#^[ \\t]*// code-template::auto-generated:START.+[ \\t]*// code-template::auto-generated:END\\n#ms';
             $postText = substr($text, $offset);
             $postText = preg_replace($autogenRegexp, '', $postText);
             $text = substr($text, 0, $offset) . $postText;
             unset($postText);
             // Output the template code with markers
             fwrite($fd, "{$indentText}// code-template::auto-generated:START {$templateName}\n" . "{$indentText}// This code is automatically generated from {$templateFile}\n" . "{$indentText}// DO NOT EDIT THIS CODE DIRECTLY, CHANGE THE TEMPLATE FILE INSTEAD\n" . "\n");
             fwrite($fd, $resultText);
             fwrite($fd, "\n{$indentText}// This code is automatically generated from {$templateFile}\n" . "{$indentText}// code-template::auto-generated:END\n");
         } else {
             fwrite($fd, substr($text, $offset));
             break;
         }
     }
     fclose($fd);
     if (!$error) {
         $backupFile = $filePath . eZSys::backupFilename();
         // Make a backup and make the temporary file the real one
         if (file_exists($backupFile)) {
             unlink($backupFile);
         }
         rename($filePath, $backupFile);
         rename($tempFile, $filePath);
         return true;
     }
     unlink($tempFile);
     return false;
 }
开发者ID:runelangseid,项目名称:ezpublish,代码行数:101,代码来源:ezclasstemplate.php

示例2: save

 function save($fileName = false, $suffix = false, $useOverride = false, $onlyModified = false, $useRootDir = true, $resetArrays = false, $encapsulateInPHP = true)
 {
     $lineSeparator = eZSys::lineSeparator();
     $pathArray = array();
     $dirArray = array();
     if ($fileName === false) {
         $fileName = $this->FileName;
     }
     if ($useRootDir === true) {
         $pathArray[] = $this->RootDir;
         $dirArray[] = $this->RootDir;
     } else {
         if (is_string($useRootDir)) {
             $pathArray[] = $useRootDir;
             $dirArray[] = $useRootDir;
         }
     }
     if ($useOverride) {
         $pathArray[] = 'override';
         $dirArray[] = 'override';
     }
     if ($useOverride === 'append') {
         $fileName .= '.append';
     }
     if ($suffix !== false) {
         $fileName .= $suffix;
     }
     /* Try to guess which filename would fit better: 'xxx.apend' or 'xxx.append.php'.
      * We choose 'xxx.append.php' in all cases except when
      * 'xxx.append' exists already and 'xxx.append.php' does not exist.
      */
     if (strstr($fileName, '.append')) {
         $fnAppend = preg_replace('#\\.php$#', '', $fileName);
         $fnAppendPhp = $fnAppend . '.php';
         $fpAppend = eZDir::path(array_merge($pathArray, array($fnAppend)));
         $fpAppendPhp = eZDir::path(array_merge($pathArray, array($fnAppendPhp)));
         $fileName = file_exists($fpAppend) && !file_exists($fpAppendPhp) ? $fnAppend : $fnAppendPhp;
     }
     $originalFileName = $fileName;
     $backupFileName = $originalFileName . eZSys::backupFilename();
     $fileName .= '.tmp';
     $dirPath = eZDir::path($dirArray);
     if (!file_exists($dirPath)) {
         eZDir::mkdir($dirPath, octdec('777'), true);
     }
     $filePath = eZDir::path(array_merge($pathArray, array($fileName)));
     $originalFilePath = eZDir::path(array_merge($pathArray, array($originalFileName)));
     $backupFilePath = eZDir::path(array_merge($pathArray, array($backupFileName)));
     $fp = @fopen($filePath, "w+");
     if (!$fp) {
         eZDebug::writeError("Failed opening file '{$filePath}' for writing", __METHOD__);
         return false;
     }
     $writeOK = true;
     $written = 0;
     $charset = $this->Codec ? $this->Codec->RequestedOutputCharsetCode : $this->Charset;
     if ($encapsulateInPHP) {
         $written = fwrite($fp, "<?php /* #?ini charset=\"{$charset}\"?{$lineSeparator}{$lineSeparator}");
     } else {
         $written = fwrite($fp, "#?ini charset=\"{$charset}\"?{$lineSeparator}{$lineSeparator}");
     }
     if ($written === false) {
         $writeOK = false;
     }
     $i = 0;
     if ($writeOK) {
         foreach (array_keys($this->BlockValues) as $blockName) {
             if ($onlyModified) {
                 $groupHasModified = false;
                 if (isset($this->ModifiedBlockValues[$blockName])) {
                     foreach ($this->ModifiedBlockValues[$blockName] as $modifiedValue) {
                         if ($modifiedValue) {
                             $groupHasModified = true;
                         }
                     }
                 }
                 if (!$groupHasModified) {
                     continue;
                 }
             }
             $written = 0;
             if ($i > 0) {
                 $written = fwrite($fp, "{$lineSeparator}");
             }
             if ($written === false) {
                 $writeOK = false;
                 break;
             }
             $written = fwrite($fp, "[{$blockName}]{$lineSeparator}");
             if ($written === false) {
                 $writeOK = false;
                 break;
             }
             foreach (array_keys($this->BlockValues[$blockName]) as $blockVariable) {
                 if ($onlyModified) {
                     if (!isset($this->ModifiedBlockValues[$blockName][$blockVariable]) or !$this->ModifiedBlockValues[$blockName][$blockVariable]) {
                         continue;
                     }
                 }
                 $varKey = $blockVariable;
//.........这里部分代码省略.........
开发者ID:runelangseid,项目名称:ezpublish,代码行数:101,代码来源:ezini.php

示例3: apply


//.........这里部分代码省略.........
                {
                    if ( isset( $block['tag'] ) )
                    {
                        $tagText = $block['tag'];
                        if ( strpos( $tagText, '&' ) !== false )
                        {
                            $tags = explode( '&', $tagText );
                            // Check if all tags are present in parameters (and match)
                            if ( count( array_intersect( $parameters, $tags ) ) == count( $tags ) )
                            {
                                $resultText .= implode( '', $block['blocks'] );
                            }
                        }
                        else if ( strpos( $tagText, '|' ) !== false )
                        {
                            $tags = explode( '|', $tagText );
                            // Check if at least one tag is present in parameters (or match)
                            if ( count( array_intersect( $parameters, $tags ) ) == count( $tags ) )
                            {
                                $resultText .= implode( '', $block['blocks'] );
                            }
                        }
                        else
                        {
                            if ( in_array( $tagText, $parameters ) )
                            {
                                $resultText .= implode( '', $block['blocks'] );
                            }
                        }
                    }
                    else
                    {
                        $resultText .= implode( '', $block['blocks'] );
                    }
                }

                // Remove any end-of-line whitespaces unless keep-whitespace is used
                if ( !in_array( 'keep-whitespace', $parameters ) )
                    $resultText = preg_replace( '#[ \t]+$#m', '', $resultText );

                // Output text before the template-block
                fwrite( $fd, substr( $text, $offset, $createPos - $offset ) );
                fwrite( $fd, substr( $text, $createPos, $end - $createPos ) );

                $offset = $end;

                // Remove any existing auto-generated code
                $autogenRegexp = '#^[ \t]*// code-template::auto-generated:START ' . $templateName . '.+[ \t]*// code-template::auto-generated:END ' . $templateName . '\n#ms';
                $postText = substr( $text, $offset );
                $postText = preg_replace( $autogenRegexp, '', $postText );
                $text = substr( $text, 0, $offset ) . $postText;
                unset( $postText );

                // Output the template code with markers
                fwrite( $fd, ( "$indentText// code-template::auto-generated:START $templateName\n" .
                               "$indentText// This code is automatically generated from $templateFile\n" .
                               "$indentText// DO NOT EDIT THIS CODE DIRECTLY, CHANGE THE TEMPLATE FILE INSTEAD\n" .
                               "\n" ) );

                fwrite( $fd, $resultText );
                fwrite( $fd, ( "\n$indentText// This code is automatically generated from $templateFile\n" .
                               "$indentText// code-template::auto-generated:END $templateName\n" ) );

            }
            else
            {
                fwrite( $fd, substr( $text, $offset ) );
                break;
            }
        }

        fclose( $fd );
        if ( !$error )
        {
            $originalMD5 = md5_file( $filePath );
            $updatedMD5 = md5_file( $tempFile );
            if ( $originalMD5 == $updatedMD5 )
            {
                unlink( $tempFile );
                return self::STATUS_NO_CHANGE;
            }
            else if ( $checkOnly )
            {
                unlink( $tempFile );
                return self::STATUS_OK;
            }
            else
            {
                $backupFile = $filePath . eZSys::backupFilename();
                // Make a backup and make the temporary file the real one
                if ( file_exists( $backupFile ) )
                    unlink( $backupFile );
                rename( $filePath, $backupFile );
                rename( $tempFile, $filePath );
                return self::STATUS_OK;
            }
        }
        unlink( $tempFile );
        return self::STATUS_FAILED;
    }
开发者ID:robinmuilwijk,项目名称:ezpublish,代码行数:101,代码来源:ezcodetemplate.php


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