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


PHP File::lastChange方法代码示例

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


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

示例1: main

 /**
  * main method
  *
  * @param  string $tempDir an other directory to clear of all folders and files, if desired
  * @return void
  */
 public function main($tempDir = null)
 {
     if (empty($tempDir)) {
         $tempDir = Configure::read('Attachments.tmpUploadsPath');
     }
     if (!Folder::isAbsolute($tempDir)) {
         $this->out('The path must be absolute, "' . $tempDir . '" given.');
         exit;
     }
     $Folder = new Folder();
     if ($Folder->cd($tempDir) === false) {
         $this->out('Path "' . $tempDir . '" doesn\'t seem to exist.');
         exit;
     }
     $dir = new Folder($tempDir);
     $folders = $dir->read();
     $files = $dir->findRecursive();
     $deletedFiles = 0;
     $deletedFolders = 0;
     $this->out('Found ' . count($folders[0]) . ' folders and ' . count($files) . ' files');
     foreach ($files as $filePath) {
         $file = new File($filePath);
         // only delete if last change is longer than 24 hours ago
         if ($file->lastChange() < time() - 24 * 60 * 60 && $file->delete()) {
             $deletedFiles++;
         }
         $file->close();
     }
     foreach ($folders[0] as $folderName) {
         $folder = new Folder($dir->pwd() . $folderName);
         // only delete if folder is empty
         if ($folder->dirsize() === 0 && $folder->delete()) {
             $deletedFolders++;
         }
     }
     $this->out('Deleted ' . $deletedFolders . ' folders and ' . $deletedFiles . ' files.');
 }
开发者ID:cleptric,项目名称:cake-attachments,代码行数:43,代码来源:CleanTempShell.php

示例2: testLastChange

 /**
  * testLastChange method
  *
  * @return void
  */
 public function testLastChange()
 {
     $someFile = new File(TMP . 'some_file.txt', false);
     $this->assertFalse($someFile->lastChange());
     $this->assertTrue($someFile->open('r+'));
     $this->assertWithinRange(time(), $someFile->lastChange(), 2);
     $someFile->write('something');
     $this->assertWithinRange(time(), $someFile->lastChange(), 2);
     $someFile->close();
     $someFile->delete();
 }
开发者ID:Slayug,项目名称:castor,代码行数:16,代码来源:FileTest.php

示例3: runjobs

 /**
  * Process the tasks when they need to run
  *
  * @access private
  * @return void
  */
 private function runjobs()
 {
     $dir = new Folder(TMP);
     // set processing flag so function takes place only once at any given time
     $processing = count($dir->find('\\.scheduler_running_flag'));
     $processingFlag = new File($dir->slashTerm($dir->pwd()) . '.scheduler_running_flag');
     if ($processing && time() - $processingFlag->lastChange() < $this->processingTimeout) {
         $this->out("Scheduler already running! Exiting.");
         return false;
     } else {
         $processingFlag->delete();
         $processingFlag->create();
     }
     if (!$this->storePath) {
         $this->storePath = TMP;
     }
     // look for a store of the previous run
     $store = "";
     $storeFilePath = $this->storePath . $this->storeFile;
     if (file_exists($storeFilePath)) {
         $store = file_get_contents($storeFilePath);
     }
     $this->out('Reading from: ' . $storeFilePath);
     // build or rebuild the store
     if ($store != '') {
         $store = json_decode($store, true);
     } else {
         $store = $this->schedule;
     }
     // run the jobs that need to be run, record the time
     foreach ($this->schedule as $name => $job) {
         $now = new DateTime();
         $task = $job['task'];
         $action = $job['action'];
         // if the job has never been run before, create it
         if (!isset($store[$name])) {
             $store[$name] = $job;
         }
         // figure out the last run date
         $tmptime = $store[$name]['lastRun'];
         if ($tmptime == null) {
             $tmptime = new DateTime("1969-01-01 00:00:00");
         } elseif (is_array($tmptime)) {
             $tmptime = new DateTime($tmptime['date'], new DateTimeZone($tmptime['timezone']));
         } elseif (is_string($tmptime)) {
             $tmptime = new DateTime($tmptime);
         }
         // determine the next run time based on the last
         if (substr($job['interval'], 0, 1) === 'P') {
             $tmptime->add(new DateInterval($job['interval']));
             // "P10DT4H" http://www.php.net/manual/en/class.dateinterval.php
         } else {
             $tmptime->modify($job['interval']);
             // "next day 10:30" http://www.php.net/manual/en/datetime.formats.relative.php
         }
         // is it time to run? has it never been run before?
         if ($tmptime <= $now) {
             $this->hr();
             $this->out("Running {$name}");
             $this->hr();
             if (!isset($this->{$task})) {
                 $this->{$task} = $this->Tasks->load($task);
                 // load models if they aren't already
                 // foreach ($this->$task->uses as $mk => $mv) {
                 // 	if (!isset($this->$task->$mv)) {
                 // 		App::uses('AppModel', 'Model');
                 // 		App::uses($mv, 'Model');
                 // 		$this->$task->$mv = new $mv();
                 // 	}
                 // }
             }
             // grab the entire schedule record incase it was updated..
             $store[$name] = $this->schedule[$name];
             // execute the task and store the result
             $store[$name]['lastResult'] = call_user_func_array(array($this->{$task}, $action), $job['args']);
             // assign it the current time
             $now = new DateTime();
             $store[$name]['lastRun'] = $now->format('Y-m-d H:i:s');
         }
     }
     // write the store back to the file
     file_put_contents($this->storePath . $this->storeFile, json_encode($store));
     // remove processing flag
     $processingFlag->delete();
 }
开发者ID:kajas90,项目名称:cakephp-scheduler,代码行数:91,代码来源:SchedulerShell.php

示例4: upload

 public function upload($system, $path)
 {
     // UPLOAD THE FILE TO THE RIGHT SYSTEM
     if ($system == 'production') {
         $other = 'development';
     } else {
         $other = 'production';
     }
     $path = str_replace('___', '/', $path);
     $file = new File('../../' . $other . $path);
     $file2 = new File('../../' . $system . $path);
     if (!$file2->exists()) {
         $dirs = explode('/', $path);
         $prod = new Folder('../../' . $system);
         for ($i = 0; $i < sizeof($dirs) - 1; $i++) {
             if (!$prod->cd($dirs[$i])) {
                 $prod->create($dirs[$i]);
                 $prod->cd($dirs[$i]);
             }
         }
     }
     if ($file->copy('../../' . $system . $path)) {
         if (touch('../../' . $system . $path, $file->lastChange())) {
             $this->Flash->success(__('File copied successfully.'));
         } else {
             $this->Flash->success(__('File copied successfully, but time not updated.'));
         }
     } else {
         $this->Flash->error(__('Unable copy file. '));
     }
     return $this->redirect($this->referer());
 }
开发者ID:jaambageek,项目名称:cakeboot-template,代码行数:32,代码来源:FilesController.php

示例5: isNotModified

 /**
  * Check the not modified header.
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request The request to check.
  * @param \Cake\Filesystem\File $file The file object to compare.
  * @return bool
  */
 protected function isNotModified($request, $file)
 {
     $modifiedSince = $request->getHeaderLine('If-Modified-Since');
     if (!$modifiedSince) {
         return false;
     }
     return strtotime($modifiedSince) === $file->lastChange();
 }
开发者ID:markstory,项目名称:cakephp-spekkoek,代码行数:15,代码来源:AssetMiddleware.php

示例6: _removeExpiredLock

 /**
  * _removeExpiredLock
  *
  * @return void
  */
 protected function _removeExpiredLock()
 {
     $dir = new Folder(CONFIG . $this->_config['lockout']['file_path'], true);
     $files = $dir->find();
     foreach ($files as $fileName) {
         $file = new File($dir->pwd() . DS . $fileName);
         $lastChange = Time::createFromTimestamp($file->lastChange());
         if ($lastChange->wasWithinLast($this->_config['lockout']['expires'])) {
             continue;
         }
         $file->delete();
     }
 }
开发者ID:crabstudio,项目名称:authenticate,代码行数:18,代码来源:AdvanceAuthenticate.php

示例7: fetch

 /**
  * Processes/minify/combines queued files of the requested type.
  * @param string type - 'js' or 'css'. This should be the end result type
  * @param string how - 'link' for <script src="">, 'async' for <script src="" async>, 'embed' for <script>...js code...</script>
  * @param array files - string name of a file or array containing multiple string of files
  * @return string - the <script> or <link>
  */
 function fetch($type, $how = 'link', $files = array())
 {
     if ($type == 'script') {
         $type = 'js';
     }
     if (!$files) {
         $files =& $this->files;
     }
     if (!$files) {
         return '';
     }
     // ensure the layout files are before the view files
     $files[$type] = array_merge($files[$type]['layout'], $files[$type]['view']);
     // determine the cache file path
     $cacheFile = $this->settings['prefix'] . md5(implode('_', $files[$type])) . '.' . $type;
     $cacheFilePath = preg_replace('/(\\/+|\\+)/', DS, WWW_ROOT . DS . $this->settings[$type]['cachePath'] . DS . $cacheFile);
     $cacheFileObj = new File($cacheFilePath);
     $webCacheFilePath = $this->settings['url'] . preg_replace('/\\/+/', '/', '/' . $this->extraPath . '/' . $this->settings[$type]['cachePath'] . $cacheFile);
     // create Cake file objects and get the max date
     $maxAge = 0;
     foreach ($files[$type] as $k => $v) {
         //$caminho = preg_replace('/(\/+|\\+)/', DS, WWW_ROOT .DS. ($v[0]=='/'? '':$this->settings[$type]['path']) .DS. $v);
         $tmpf = new File(preg_replace('/(\\/+|\\+)/', DS, WWW_ROOT . DS . ($v[0] == '/' ? '' : $this->settings[$type]['path']) . DS . $v));
         //var_dump($tmpf); //path
         //echo '<br><br><br>';
         $files[$type][$k] = array('file' => $tmpf, 'rel_path' => $v);
         $srcMod = $tmpf->lastChange();
         if ($srcMod > $maxAge) {
             $maxAge = $srcMod;
         }
     }
     // has the cache expired (we're debugging, the cache doesn't exist, or too old)?
     $expired = false;
     if ($this->debugging || !$cacheFileObj->exists() || $maxAge > $cacheFileObj->lastChange()) {
         $expired = true;
     }
     // rebuild if it has expired
     if ($expired) {
         $output = '';
         foreach ($files[$type] as $k => $v) {
             $lang = $v['file']->ext();
             // load compiler if it is not already
             if (!isset($this->compilers[$lang])) {
                 $this->compilers[$lang] = ShrinkType::getCompiler($lang, $this->settings);
             }
             $resultType = $this->compilers[$lang]->resultType;
             // load the compressor if it is not already
             $compressorName = $this->settings[$type]['minifier'];
             if (!isset($this->compressors[$compressorName])) {
                 $this->compressors[$compressorName] = ShrinkType::getCompressor($compressorName, $this->settings);
             }
             // compile, compress, combine
             if ($resultType == $type && $v['file']->exists()) {
                 $output .= "/* " . $v['rel_path'] . " */\n";
                 $code = $this->compilers[$lang]->compile($v['file']);
                 // INICIA MODIFICAÇÃO FEITA PELO AUTOR DO "PROJETO STORES"
                 //$code = $this->compressors[$compressorName]->compress($code);
                 $isMinified = strpos($v['file']->path, '.min');
                 if ($type == 'css' && $isMinified === false) {
                     $code = $this->compressors[$compressorName]->compress($code);
                 }
                 if ($type == 'js' && $isMinified === false) {
                     $jshrinkCompressor = new ShrinkCompressorJshrink();
                     $code = $jshrinkCompressor->compress($code);
                 }
                 if ($isMinified !== false) {
                     $patter = '/\\/\\*(.|[\\r\\n])*?\\*\\//';
                     $replacement = ' ';
                     $code = preg_replace($patter, $replacement, $code);
                 }
                 // TERMINA MODIFICAÇÃO FEITA PELO AUTOR DO "PROJETO STORES"
                 $output .= $code . "\n";
             }
         }
         // be sure no duplicate charsets
         if ($type == 'css') {
             $output = preg_replace('/@charset\\s+[\'"].+?[\'"];?/i', '', $output);
             $output = '@charset "' . $this->settings['css']['charset'] . "\";\n" . $output;
         }
         // write the file
         $cacheFileObj->write($output);
     }
     // files will be @$this->files, so this clears them
     $files[$type] = array('layout' => array(), 'view' => array());
     // print them how the user wants
     if ($how == 'embed') {
         $output = $cacheFileObj->read();
         if ($type == 'css') {
             return '<style type="text/css">' . $output . '</style>';
         } else {
             return '<script type="text/javascript">' . $output . '</script>';
         }
     } else {
//.........这里部分代码省略.........
开发者ID:ricardohenriq,项目名称:shooping,代码行数:101,代码来源:ShrinkHelper.php

示例8: build

 /**
  * build - Compile, Compress, Combile the array of files
  * @param array $files - filenames to process
  * @param string $type - js or css to indicate how to compress and which options to use
  * @param string $cacheFile - filename to write the results to, relative to cachePath option
  * @return array - array with the cache file object and the new web path ['file','webPath']
  */
 function build($files, $type, $cacheFile = '')
 {
     // determine the cache file path
     if ($cacheFile === '') {
         $cacheFile = $this->settings['prefix'] . md5(implode('_', $files)) . '.' . $type;
     }
     $cacheFilePath = preg_replace('/(\\/+|\\+)/', DS, WWW_ROOT . DS . $this->settings[$type]['cachePath'] . DS . $cacheFile);
     $cacheFileObj = new File($cacheFilePath);
     $webCacheFilePath = $this->settings['url'] . preg_replace('/\\/+/', '/', '/' . $this->extraPath . '/' . $this->settings[$type]['cachePath'] . $cacheFile);
     // create Cake file objects and get the max date
     $maxAge = 0;
     foreach ($files as $k => $v) {
         $tmpf = new File(preg_replace('/(\\/+|\\+)/', DS, WWW_ROOT . DS . ($v[0] == '/' ? '' : $this->settings[$type]['path']) . DS . $v));
         $files[$k] = ['file' => $tmpf, 'rel_path' => $v];
         $srcMod = $tmpf->lastChange();
         if ($srcMod > $maxAge) {
             $maxAge = $srcMod;
         }
     }
     // has the cache expired (we're debugging, the cache doesn't exist, or too old)?
     $expired = false;
     if ($this->debugging || !$cacheFileObj->exists() || $maxAge > $cacheFileObj->lastChange()) {
         $expired = true;
     }
     // rebuild if it has expired
     if ($expired) {
         $output = '';
         foreach ($files as $k => $v) {
             $lang = $v['file']->ext();
             // load compiler if it is not already
             if (!isset($this->compilers[$lang])) {
                 $this->compilers[$lang] = ShrinkType::getCompiler($lang, $this->settings);
             }
             $resultType = $this->compilers[$lang]->resultType;
             // load the compressor if it is not already
             $compressorName = $this->settings[$type]['minifier'];
             if (!isset($this->compressors[$compressorName])) {
                 $this->compressors[$compressorName] = ShrinkType::getCompressor($compressorName, $this->settings);
             }
             // compile, compress, combine
             if ($resultType == $type && $v['file']->exists()) {
                 $output .= "/* " . $v['rel_path'] . " */\n";
                 $code = $this->compilers[$lang]->compile($v['file']);
                 $code = $this->compressors[$compressorName]->compress($code);
                 $output .= $code . "\n";
             }
             // we are done with this file, close it
             $v['file']->close();
         }
         // be sure no duplicate charsets
         if ($type == 'css') {
             $output = preg_replace('/@charset\\s+[\'"].+?[\'"];?/i', '', $output);
             $output = '@charset "' . $this->settings['css']['charset'] . "\";\n" . $output;
         }
         // write the file
         $cacheFileObj->write($output);
     }
     $ret = ['path' => $cacheFileObj->path, 'webPath' => $webCacheFilePath];
     $cacheFileObj->close();
     return $ret;
 }
开发者ID:edukondaluetg,项目名称:cakephp-shrink,代码行数:68,代码来源:Shrink.php

示例9: getRichCakeboxYaml

 /**
  * Returns rich information for the Cakebox.yaml file.
  *
  * @return array Hash with raw file data and timestamp.
  * @throws Exception
  */
 public function getRichCakeboxYaml()
 {
     try {
         $fileHandle = new File($this->cakeboxMeta['host']['yaml']);
         return ['timestamp' => $fileHandle->lastChange(), 'raw' => $fileHandle->read()];
     } catch (\Exception $e) {
         throw new \Exception("Error reading " . $this->cakeboxMeta['yamlFile'] . ": " . $e->getMessage());
     }
 }
开发者ID:alt3,项目名称:cakebox-console,代码行数:15,代码来源:CakeboxInfo.php


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