本文整理汇总了PHP中FileUtil::getTempDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::getTempDirectory方法的具体用法?PHP FileUtil::getTempDirectory怎么用?PHP FileUtil::getTempDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtil
的用法示例。
在下文中一共展示了FileUtil::getTempDirectory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string $name lock name
* @throws LockException
*/
public function __construct($name)
{
$this->name = $name;
$fileUtil = new FileUtil();
$lockFile = $fileUtil->getTempDirectory() . DIRECTORY_SEPARATOR . $name;
$this->handle = fopen($lockFile, "w");
if (!is_resource($this->handle)) {
throw new LockException("Could not open lock file {$lockFile}.");
}
}
示例2: testAutomaticUpdatePlan
/**
* @expectedException \PHPUnit_Framework_Error_Notice
* @medium
*/
public function testAutomaticUpdatePlan()
{
$fileUtil = new FileUtil();
$file = tempnam($fileUtil->getTempDirectory(), 'bavtest');
touch($file, strtotime("-1 year"));
$backend = new FileDataBackend($file);
$updatePlan = new AutomaticUpdatePlan();
$this->assertTrue($updatePlan->isOutdated($backend));
$updatePlan->perform($backend);
$this->assertFalse($updatePlan->isOutdated($backend));
}
示例3: testAutomaticUpdate
/**
* Tests automatic installation.
*/
public function testAutomaticUpdate()
{
$updatePlan = new AutomaticUpdatePlan();
$updatePlan->setNotice(false);
ConfigurationRegistry::getConfiguration()->setUpdatePlan($updatePlan);
$fileUtil = new FileUtil();
$container = new FileDataBackendContainer(tempnam($fileUtil->getTempDirectory(), 'bavtest'));
$backend = $container->getDataBackend();
touch($backend->getFile(), strtotime("-1 year"));
$this->assertTrue($updatePlan->isOutdated($backend));
$container->applyUpdatePlan($backend);
$this->assertFalse($updatePlan->isOutdated($backend));
$backend->uninstall();
ConfigurationRegistry::getConfiguration()->setUpdatePlan(null);
}
示例4: downloadFile
/**
* Downloads a file.
*
* @param string $uri URI
* @return string local path to downloaded file.
* @throws DownloaderException
*/
public function downloadFile($uri)
{
$fileUtil = new FileUtil();
$file = tempnam($fileUtil->getTempDirectory(), "bavdownload");
$fp = fopen($file, 'w');
if (!($file && $fp)) {
throw new DownloaderException("Failed opening a temporary file");
}
curl_setopt($this->handle, CURLOPT_FILE, $fp);
if (!$this->download($uri)) {
fclose($fp);
unlink($file);
throw new DownloaderException(curl_error($this->handle), curl_errno($this->handle));
}
return $file;
}
示例5: provideInstallationBackends
/**
* @return DataBackend[]
*/
public function provideInstallationBackends()
{
$backends = array();
$backends[] = new PDODataBackend(PDOFactory::makePDO(), "bavtest_");
$fileUtil = new FileUtil();
$backends[] = new FileDataBackend(tempnam($fileUtil->getTempDirectory(), "bavtest"));
$conn = array("driver" => "pdo_sqlite", "path" => ":memory:");
$doctrineContainer = DoctrineBackendContainer::buildByConnection($conn, true);
$backends[] = new DoctrineDataBackend($doctrineContainer->getEntityManager());
foreach ($backends as &$backend) {
if ($backend->isInstalled()) {
$backend->uninstall();
}
self::$freeableDatabackends[] = $backend;
$backend = array($backend);
}
return $backends;
}
示例6: update
/**
* @see DataBackend::update()
* @throws DataBackendException
*/
public function update()
{
$useTA = false;
try {
$fileUtil = new FileUtil();
$fileBackend = new FileDataBackend(tempnam($fileUtil->getTempDirectory(), 'bav'));
$fileBackend->install();
$insertBank = $this->pdo->prepare("INSERT INTO {$this->prefix}bank\n (id, validator, mainAgency)\n VALUES(:bankID, :validator, :mainAgency)");
$insertAgency = $this->pdo->prepare("INSERT INTO {$this->prefix}agency\n (id, name, postcode, city, shortTerm, pan, bic, bank)\n VALUES (:id, :name, :postcode, :city, :shortTerm, :pan, :bic, :bank)");
try {
$this->pdo->beginTransaction();
$useTA = true;
} catch (\PDOException $e) {
trigger_error("Your DBS doesn't support transactions. Your data may be corrupted.");
}
$this->pdo->exec("DELETE FROM {$this->prefix}agency");
$this->pdo->exec("DELETE FROM {$this->prefix}bank");
foreach ($fileBackend->getAllBanks() as $bank) {
try {
$insertBank->execute(array(":bankID" => $bank->getBankID(), ":validator" => $bank->getValidationType(), ":mainAgency" => $bank->getMainAgency()->getID()));
$agencies = $bank->getAgencies();
$agencies[] = $bank->getMainAgency();
foreach ($agencies as $agency) {
$insertAgency->execute(array(":id" => $agency->getID(), ":name" => $agency->getName(), ":postcode" => $agency->getPostcode(), ":city" => $agency->getCity(), ":shortTerm" => $agency->getShortTerm(), ":bank" => $bank->getBankID(), ":pan" => $agency->hasPAN() ? $agency->getPAN() : null, ":bic" => $agency->hasBIC() ? $agency->getBIC() : null));
}
} catch (NoMainAgencyException $e) {
trigger_error("Skipping bank {$e->getBank()->getBankID()} without any main agency.");
}
}
// Update modification timestamp
$modificationStmt = $this->pdo->prepare("UPDATE {$this->prefix}meta SET value=:value WHERE name=:name");
$modificationStmt->execute(array(":name" => MetaData::LASTMODIFIED, ":value" => time()));
if ($useTA) {
$this->pdo->commit();
$useTA = false;
}
$fileBackend->uninstall();
} catch (Exception $e) {
try {
if ($useTA) {
$this->pdo->rollback();
}
throw $e;
} catch (\PDOException $e2) {
throw new DataBackendIOException(get_class($e) . ": {$e->getMessage()}\nadditionally: {$e2->getMessage()}");
}
}
}
示例7: testLinuxTempDirectory
/**
* Tests getting /tmp.
*
* @requires OS Linux
*/
public function testLinuxTempDirectory()
{
$fileUtil = new FileUtil();
$this->assertEquals("/tmp", $fileUtil->getTempDirectory());
}