本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\WriteInterface::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP WriteInterface::delete方法的具体用法?PHP WriteInterface::delete怎么用?PHP WriteInterface::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\WriteInterface
的用法示例。
在下文中一共展示了WriteInterface::delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cleanGeneratedFiles
/**
* Clean var/generation, var/di and var/cache
*
* @return void
*/
public function cleanGeneratedFiles()
{
if ($this->write->isExist(self::REGENERATE_FLAG)) {
$enabledCacheTypes = [];
//TODO: to be removed in scope of MAGETWO-53476
$deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG);
$configPool = new ConfigFilePool();
$envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
if ($this->write->isExist($this->write->getRelativePath($envPath))) {
$enabledCacheTypes = $this->getEnabledCacheTypes();
$this->disableAllCacheTypes();
}
//TODO: Till here
$cachePath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::CACHE));
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
$diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));
// Clean var/generation dir
if ($this->write->isDirectory($generationPath)) {
$this->write->delete($generationPath);
}
// Clean var/di
if ($this->write->isDirectory($diPath)) {
$this->write->delete($diPath);
}
// Clean var/cache
if ($this->write->isDirectory($cachePath)) {
$this->write->delete($cachePath);
}
$this->write->delete(self::REGENERATE_FLAG);
$this->enableCacheTypes($enabledCacheTypes);
}
}
示例2: _deleteExpiredImagesForWebsite
/**
* Delete Expired Captcha Images for specific website
*
* @param \Magento\Captcha\Helper\Data $helper
* @param \Magento\Store\Model\Website|null $website
* @param \Magento\Store\Model\Store|null $store
* @return void
*/
protected function _deleteExpiredImagesForWebsite(\Magento\Captcha\Helper\Data $helper, \Magento\Store\Model\Website $website = null, \Magento\Store\Model\Store $store = null)
{
$expire = time() - $helper->getConfig('timeout', $store) * 60;
$imageDirectory = $this->_mediaDirectory->getRelativePath($helper->getImgDir($website));
foreach ($this->_mediaDirectory->read($imageDirectory) as $filePath) {
if ($this->_mediaDirectory->isFile($filePath) && pathinfo($filePath, PATHINFO_EXTENSION) == 'png' && $this->_mediaDirectory->stat($filePath)['mtime'] < $expire) {
$this->_mediaDirectory->delete($filePath);
}
}
}
示例3: tearDown
/**
* {@inheritDoc}
*/
protected function tearDown()
{
/** @var \Magento\TestFramework\App\State $appState */
$appState = $this->objectManager->get(\Magento\TestFramework\App\State::class);
$appState->setMode($this->origMode);
if ($this->staticDir->isExist('frontend/FrameworkViewMinifier')) {
$this->staticDir->delete('frontend/FrameworkViewMinifier');
}
parent::tearDown();
}
示例4: execute
/**
* Flash ISM_BaseRunner cache
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$dir = $this->_mediaDirectory->getAbsolutePath(Upload::UPLOAD_POST_IMAGE_DIR . 'cache/');
if (is_dir($dir)) {
$dir = $this->_mediaDirectory->getDriver()->readDirectory($dir);
foreach ($dir as $file) {
$this->_mediaDirectory->delete(Upload::UPLOAD_POST_IMAGE_DIR . 'cache/' . basename($file));
}
}
}
示例5: isProcessLocked
/**
* Check whether generation process has already locked
*
* @return bool
* @throws FileSystemException
*/
private function isProcessLocked()
{
if ($this->tmpDirectory->isExist($this->lockFilePath)) {
$lockTime = (int) $this->tmpDirectory->readFile($this->lockFilePath);
if (time() - $lockTime >= self::MAX_LOCK_TIME) {
$this->tmpDirectory->delete($this->lockFilePath);
return false;
}
return true;
}
return false;
}
示例6: _removeOutdatedCertFile
/**
* Check and remove outdated certificate file by website
*
* @return void
*/
protected function _removeOutdatedCertFile()
{
$pattern = sprintf('cert_%s*', $this->getWebsiteId());
$entries = $this->varDirectory->search($pattern, self::BASEPATH_PAYPAL_CERT);
foreach ($entries as $entry) {
$this->varDirectory->delete($entry);
}
}
示例7: uploadPreviewImage
/**
* Upload and create preview image
*
* @param string $scope the request key for file
* @return $this
*/
public function uploadPreviewImage($scope)
{
$tmpDirPath = $this->themeImagePath->getTemporaryDirectory();
$tmpFilePath = $this->uploader->uploadPreviewImage($scope, $tmpDirPath);
if ($tmpFilePath) {
if ($this->theme->getPreviewImage()) {
$this->removePreviewImage();
}
$this->createPreviewImage($tmpFilePath);
$this->mediaDirectory->delete($tmpFilePath);
}
return $this;
}
示例8: isProcessLocked
/**
* Check whether generation process has already locked
*
* @return bool
*/
protected function isProcessLocked()
{
$lockFilePath = $this->config->getLessMaterializationRelativePath() . '/' . self::LOCK_FILE;
if ($this->tmpDirectory->isExist($lockFilePath)) {
$lockTime = time() - (int) $this->tmpDirectory->readFile($lockFilePath);
if ($lockTime >= self::MAX_LOCK_TIME) {
$this->tmpDirectory->delete($lockFilePath);
return false;
}
return true;
}
return false;
}
示例9: setAddresses
/**
* Sets list of allowed IP addresses
*
* @param string $addresses
* @return bool
* @throws \InvalidArgumentException
*/
public function setAddresses($addresses)
{
$addresses = (string) $addresses;
if (empty($addresses)) {
if ($this->flagDir->isExist(self::IP_FILENAME)) {
return $this->flagDir->delete(self::IP_FILENAME);
}
return true;
}
if (!preg_match('/^[^\\s,]+(,[^\\s,]+)*$/', $addresses)) {
throw new \InvalidArgumentException("One or more IP-addresses is expected (comma-separated)\n");
}
$result = $this->flagDir->writeFile(self::IP_FILENAME, $addresses);
return false !== $result ? true : false;
}
示例10: setFlagValue
/**
* Create flag in case when value is set to 'true', remove it if value is set to 'false'.
*
* @param string $pathToFlagFile
* @param bool $value
* @return $this
*/
protected function setFlagValue($pathToFlagFile, $value)
{
if ($value) {
try {
$this->varReaderWriter->touch($pathToFlagFile);
} catch (FileSystemException $e) {
throw new \RuntimeException(sprintf('"%s" cannot be created.', $pathToFlagFile));
}
} else {
if ($this->varReaderWriter->isExist($pathToFlagFile)) {
$this->varReaderWriter->delete($pathToFlagFile);
}
}
return $this;
}
示例11: moveImageFromTmp
/**
* move image from tmp to catalog dir
*
* @param string $file
* @return string path
*/
public function moveImageFromTmp($file)
{
if (strrpos($file, '.tmp') == strlen($file) - 4) {
$file = substr($file, 0, strlen($file) - 4);
}
$destinationFile = $this->getUniqueFileName($file);
/** @var $storageHelper \Magento\MediaStorage\Helper\File\Storage\Database */
$storageHelper = $this->fileStorageDb;
if ($storageHelper->checkDbUsage()) {
$storageHelper->renameFile($this->mediaConfig->getTmpMediaShortUrl($file), $this->mediaConfig->getMediaShortUrl($destinationFile));
$this->mediaDirectory->delete($this->mediaConfig->getTmpMediaPath($file));
$this->mediaDirectory->delete($this->getAttributeSwatchPath($destinationFile));
} else {
$this->mediaDirectory->renameFile($this->mediaConfig->getTmpMediaPath($file), $this->getAttributeSwatchPath($destinationFile));
}
return str_replace('\\', '/', $destinationFile);
}
示例12: _copyImage
/**
* Copy image and return new filename.
*
* @param string $file
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _copyImage($file)
{
try {
$destinationFile = $this->_getUniqueFileName($file);
if (!$this->_mediaDirectory->isFile($this->_mediaConfig->getMediaPath($file))) {
throw new \Exception();
}
if ($this->_fileStorageDb->checkDbUsage()) {
$this->_fileStorageDb->copyFile($this->_mediaDirectory->getAbsolutePath($this->_mediaConfig->getMediaShortUrl($file)), $this->_mediaConfig->getMediaShortUrl($destinationFile));
$this->_mediaDirectory->delete($this->_mediaConfig->getMediaPath($destinationFile));
} else {
$this->_mediaDirectory->copyFile($this->_mediaConfig->getMediaPath($file), $this->_mediaConfig->getMediaPath($destinationFile));
}
return str_replace('\\', '/', $destinationFile);
} catch (\Exception $e) {
$file = $this->_mediaConfig->getMediaPath($file);
throw new LocalizedException(__('We couldn\'t copy file %1. Please delete media with non-existing images and try again.', $file));
}
}
示例13: open
/**
* Open backup file (write or read mode)
*
* @param bool $write
* @return $this
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Backup\Exception\NotEnoughPermissions
*/
public function open($write = false)
{
if ($this->getPath() === null) {
throw new \Magento\Framework\Exception\InputException(__('The backup file path was not specified.'));
}
if ($write && $this->varDirectory->isFile($this->_getFilePath())) {
$this->varDirectory->delete($this->_getFilePath());
}
if (!$write && !$this->varDirectory->isFile($this->_getFilePath())) {
throw new \Magento\Framework\Exception\InputException(__('The backup file "%1" does not exist.', $this->getFileName()));
}
$mode = $write ? 'wb' . self::COMPRESS_RATE : 'rb';
try {
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $varDirectory */
$varDirectory = $this->_filesystem->getDirectoryWrite(DirectoryList::VAR_DIR, DriverPool::ZLIB);
$this->_stream = $varDirectory->openFile($this->_getFilePath(), $mode);
} catch (\Magento\Framework\Exception\FileSystemException $e) {
throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions(__('Sorry, but we cannot read from or write to backup file "%1".', $this->getFileName()));
}
return $this;
}
示例14: fetchAndSave
/**
* Goes to specified host/path and fetches reports from there.
* Save reports to database.
*
* @param \Magento\Framework\Filesystem\Io\Sftp $connection
* @return int Number of report rows that were fetched and saved successfully
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection)
{
$fetched = 0;
$listing = $this->_filterReportsList($connection->rawls());
foreach ($listing as $filename => $attributes) {
$localCsv = 'PayPal_STL_' . uniqid(\Magento\Framework\Math\Random::getRandomNumber()) . time() . '.csv';
if ($connection->read($filename, $this->_tmpDirectory->getAbsolutePath($localCsv))) {
if (!$this->_tmpDirectory->isWritable($localCsv)) {
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create a target file for reading reports.'));
}
$encoded = $this->_tmpDirectory->readFile($localCsv);
$csvFormat = 'new';
$fileEncoding = mb_detect_encoding($encoded);
if (self::FILES_OUT_CHARSET != $fileEncoding) {
$decoded = @iconv($fileEncoding, self::FILES_OUT_CHARSET . '//IGNORE', $encoded);
$this->_tmpDirectory->writeFile($localCsv, $decoded);
$csvFormat = 'old';
}
// Set last modified date, this value will be overwritten during parsing
if (isset($attributes['mtime'])) {
$date = new \DateTime();
$lastModified = $date->setTimestamp($attributes['mtime']);
$this->setReportLastModified($lastModified->format('Y-m-d H:i:s'));
}
$this->setReportDate($this->_fileNameToDate($filename))->setFilename($filename)->parseCsv($localCsv, $csvFormat);
if ($this->getAccountId()) {
$this->save();
}
if ($this->_dataSaveAllowed) {
$fetched += count($this->_rows);
}
// clean object and remove parsed file
$this->unsetData();
$this->_tmpDirectory->delete($localCsv);
}
}
return $fetched;
}
示例15: removeImage
/**
* Remove image.
*
* @param $file
*/
public function removeImage($file)
{
$this->_mediaDirectory->delete(self::UPLOAD_POST_IMAGE_DIR . $file);
}