當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Server::getDir方法代碼示例

本文整理匯總了PHP中Server::getDir方法的典型用法代碼示例。如果您正苦於以下問題:PHP Server::getDir方法的具體用法?PHP Server::getDir怎麽用?PHP Server::getDir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Server的用法示例。


在下文中一共展示了Server::getDir方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: deleteFiles

 /**
  * Deletes files.
  * @return void
  */
 private function deleteFiles(array $files)
 {
     rsort($files);
     $root = $this->server->getDir();
     foreach ($files as $num => $file) {
         $remoteFile = $root . $file;
         $this->writeProgress($num + 1, count($files), "Deleting {$file}", NULL, 'maroon');
         try {
             if (substr($file, -1) === '/') {
                 // is directory?
                 $this->server->removeDir($remoteFile);
             } else {
                 $this->server->removeFile($remoteFile);
             }
         } catch (ServerException $e) {
             $this->logger->log("Unable to delete {$remoteFile}", 'red');
         }
     }
 }
開發者ID:hranicka,項目名稱:dg-ftp-deployment,代碼行數:23,代碼來源:Deployer.php

示例2: deploy

 /**
  * Synchronize remote and local.
  * @return void
  */
 public function deploy()
 {
     $this->logger->log("Connecting to server");
     $this->server->connect();
     $this->remoteDir = $this->server->getDir();
     $runBefore = [NULL, NULL];
     foreach ($this->runBefore as $job) {
         $runBefore[is_string($job) && preg_match('#^local:#', $job)][] = $job;
     }
     if ($runBefore[1]) {
         $this->logger->log("\nLocal-jobs:");
         $this->runJobs($runBefore[1]);
         $this->logger->log('');
     }
     $remotePaths = $this->loadDeploymentFile();
     if (is_array($remotePaths)) {
         $this->logger->log("Loaded remote {$this->deploymentFile} file");
     } else {
         $this->logger->log("Remote {$this->deploymentFile} file not found");
         $remotePaths = [];
     }
     $this->logger->log("Scanning files in {$this->localDir}");
     $localPaths = $this->collectPaths();
     unset($localPaths["/{$this->deploymentFile}"], $remotePaths["/{$this->deploymentFile}"]);
     $toDelete = $this->allowDelete ? array_keys(array_diff_key($remotePaths, $localPaths)) : [];
     $toUpload = array_keys(array_diff_assoc($localPaths, $remotePaths));
     if ($localPaths !== $remotePaths) {
         // ignores allowDelete
         $deploymentFile = $this->writeDeploymentFile($localPaths);
         $toUpload[] = "/{$this->deploymentFile}";
         // must be last
     }
     if (!$toUpload && !$toDelete) {
         $this->logger->log('Already synchronized.', 'lime');
         return;
     } elseif ($this->testMode) {
         $this->logger->log("\nUploading:\n" . implode("\n", $toUpload), 'green', FALSE);
         $this->logger->log("\nDeleting:\n" . implode("\n", $toDelete), 'maroon', FALSE);
         if (isset($deploymentFile)) {
             unlink($deploymentFile);
         }
         return;
     }
     $this->logger->log("Creating remote file {$this->deploymentFile}.running");
     $runningFile = "{$this->remoteDir}/{$this->deploymentFile}.running";
     $this->server->createDir(str_replace('\\', '/', dirname($runningFile)));
     $this->server->writeFile(tempnam($this->tempDir, 'deploy'), $runningFile);
     if ($runBefore[0]) {
         $this->logger->log("\nBefore-jobs:");
         $this->runJobs($runBefore[0]);
     }
     if ($toUpload) {
         $this->logger->log("\nUploading:");
         $this->uploadPaths($toUpload);
         if ($this->runAfterUpload) {
             $this->logger->log("\nAfter-upload-jobs:");
             $this->runJobs($this->runAfterUpload);
         }
         $this->logger->log("\nRenaming:");
         $this->renamePaths($toUpload);
         unlink($deploymentFile);
     }
     if ($toDelete) {
         $this->logger->log("\nDeleting:");
         $this->deletePaths($toDelete);
     }
     foreach ((array) $this->toPurge as $path) {
         $this->logger->log("\nCleaning {$path}");
         $this->server->purge($this->remoteDir . '/' . $path, function ($path) {
             static $counter;
             $path = substr($path, strlen($this->remoteDir));
             $path = preg_match('#/(.{1,60})$#', $path, $m) ? $m[1] : substr(basename($path), 0, 60);
             $this->logger->progress(str_pad($path . ' ' . str_repeat('.', $counter++ % 30 + 60 - strlen($path)), 90));
         });
         $this->logger->progress(str_repeat(' ', 91));
     }
     if ($this->runAfter) {
         $this->logger->log("\nAfter-jobs:");
         $this->runJobs($this->runAfter);
     }
     $this->logger->log("\nDeleting remote file {$this->deploymentFile}.running");
     $this->server->removeFile($runningFile);
 }
開發者ID:dg,項目名稱:ftp-deployment,代碼行數:87,代碼來源:Deployer.php


注:本文中的Server::getDir方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。