本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\WriteInterface::isWritable方法的典型用法代码示例。如果您正苦于以下问题:PHP WriteInterface::isWritable方法的具体用法?PHP WriteInterface::isWritable怎么用?PHP WriteInterface::isWritable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\WriteInterface
的用法示例。
在下文中一共展示了WriteInterface::isWritable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setDestDir
/**
* Set destination file path prefix
*
* @param string $path
* @return bool
*/
public function setDestDir($path)
{
if (is_string($path) && $this->_directory->isWritable($path)) {
$this->_destDir = $path;
return true;
}
return false;
}
示例2: makeConfig
/**
* @return string Path to config file
* @throws \Exception
*/
public function makeConfig()
{
if (!$this->directory->isExist($this->basePath)) {
//$this->directory->delete($this->basePath);
$this->directory->create($this->basePath);
$this->directory->changePermissions($this->basePath, 0777);
}
$jsonData = [];
$sphinxData = ['time' => date('d.m.Y H:i:s'), 'host' => $this->host, 'port' => $this->port, 'fallback_port' => $this->port - 1, 'logdir' => $this->directory->getAbsolutePath($this->basePath), 'sphinxdir' => $this->directory->getAbsolutePath($this->basePath), 'indexes' => '', 'localdir' => dirname(dirname(__FILE__)), 'custom' => $this->config->getAdditionalSearchdConfig()];
$sphinxTemplate = $this->config->getSphinxConfigurationTemplate();
$indexTemplate = $this->config->getSphinxIndexConfigurationTemplate();
/** @var \Mirasvit\Search\Model\Index $index */
foreach ($this->indexCollectionFactory->create() as $index) {
foreach (array_keys($this->storeManager->getStores()) as $storeId) {
$indexName = $index->getIndexInstance()->getIndexer()->getIndexName($storeId);
$data = ['name' => $indexName, 'min_word_len' => 1, 'path' => $this->directory->getAbsolutePath($this->basePath) . '/' . $indexName, 'custom' => $this->config->getAdditionalIndexConfig()];
$jsonAttributes = [];
$attributes = [];
foreach (array_keys($index->getIndexInstance()->getAttributes(true)) as $attribute) {
$attributes[] = " rt_field = {$attribute}";
$jsonAttributes[] = $attribute;
if (count($attributes) > 250) {
break;
}
}
$attributes[] = " rt_field = options";
$jsonAttributes[] = "options";
$data['attributes'] = implode(PHP_EOL, $attributes);
$sphinxData['indexes'] .= $this->helper->filterTemplate($indexTemplate, $data);
$jsonData[$indexName] = $jsonAttributes;
}
}
$config = $this->helper->filterTemplate($sphinxTemplate, $sphinxData);
if ($this->directory->isWritable($this->basePath)) {
$this->directory->writeFile($this->configFilePath, $config);
$this->directory->writeFile($this->configFilePath . '.attr', json_encode($jsonData));
} else {
if ($this->directory->isExist($this->configFilePath)) {
throw new \Exception(__('File %1 does not writable', $this->configFilePath));
} else {
throw new \Exception(__('Directory %1 does not writable', $this->basePath));
}
}
return $this->directory->getAbsolutePath($this->configFilePath);
}
示例3: disableAllCacheTypes
/**
* Disables all cache types by updating env.php.
*
* @return void
*/
private function disableAllCacheTypes()
{
$envPath = $this->getEnvPath();
if ($this->write->isWritable($this->write->getRelativePath($envPath))) {
$envData = (include $envPath);
if (isset($envData['cache_types'])) {
$cacheTypes = array_keys($envData['cache_types']);
foreach ($cacheTypes as $cacheType) {
$envData['cache_types'][$cacheType] = 0;
}
$formatter = new PhpFormatter();
$contents = $formatter->format($envData);
$this->write->writeFile($this->write->getRelativePath($envPath), $contents);
if (function_exists('opcache_invalidate')) {
opcache_invalidate($this->write->getAbsolutePath($envPath));
}
}
}
}
示例4: 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;
}