本文整理汇总了PHP中Magento\Framework\App\Filesystem\DirectoryList类的典型用法代码示例。如果您正苦于以下问题:PHP DirectoryList类的具体用法?PHP DirectoryList怎么用?PHP DirectoryList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DirectoryList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Loads the configuration file
*
* @param string $fileKey
* @return array
* @throws \Exception
*/
public function load($fileKey = null)
{
$path = $this->dirList->getPath(DirectoryList::CONFIG);
if ($fileKey) {
$result = @(include $path . '/' . $this->configFilePool->getPath($fileKey));
} else {
$configFiles = $this->configFilePool->getPaths();
$result = [];
foreach (array_keys($configFiles) as $fileKey) {
$configFile = $path . '/' . $this->configFilePool->getPath($fileKey);
$fileData = @(include $configFile);
if (!empty($fileData)) {
$intersection = array_intersect_key($result, $fileData);
if (!empty($intersection)) {
$displayList = '';
foreach (array_keys($intersection) as $key) {
$displayList .= $key . PHP_EOL;
}
throw new \Exception("Key collision! The following keys occur in multiple config files:" . PHP_EOL . $displayList);
}
$result = array_merge($result, $fileData);
}
}
}
return $result ?: [];
}
示例2: __construct
public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Module\ModuleList $moduleList, \Magento\Framework\App\Config\MutableScopeConfigInterface $scopeConfig, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\Session\SessionManagerInterface $session, \Wyomind\Core\Helper\Data $coreHelper, \Magento\Framework\Filesystem\Directory\ReadFactory $directoryRead, \Magento\Framework\Filesystem\File\ReadFactory $fileRead, \Magento\Framework\App\Filesystem\DirectoryList $directoryList, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
{
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
$this->_magentoVersion = $coreHelper->getMagentoVersion();
$this->_moduleList = $moduleList;
$this->_scopeConfig = $scopeConfig;
$this->_urlBuilder = $urlBuilder;
$this->_cacheManager = $context->getCacheManager();
$this->_session = $session;
$this->_coreHelper = $coreHelper;
$root = $directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::ROOT);
if (file_exists($root . "/vendor/wyomind/")) {
$this->_directoryRead = $directoryRead->create($root . "/vendor/wyomind/");
} else {
$this->_directoryRead = $directoryRead->create($root . "/app/code/Wyomind/");
}
$this->_httpRead = $fileRead;
$this->_directoryList = $directoryList;
$this->_version = $this->_moduleList->getOne("Wyomind_Core")['setup_version'];
$this->_refreshCache = false;
$this->getValues();
foreach ($this->_values as $ext) {
$this->checkActivation($ext);
}
if ($this->_refreshCache) {
$this->_cacheManager->clean(['config']);
}
}
示例3: create
/**
* Create \Composer\Composer
*
* @return \Composer\Composer
* @throws \Exception
*/
public function create()
{
if (!getenv('COMPOSER_HOME')) {
putenv('COMPOSER_HOME=' . $this->directoryList->getPath(DirectoryList::COMPOSER_HOME));
}
return \Composer\Factory::create(new BufferIO(), $this->composerJsonFinder->findComposerJson());
}
示例4: check
/**
* Check var/generation read and write access
*
* @return bool
*/
public function check()
{
$initParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM);
$filesystemDirPaths = isset($initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : [];
$directoryList = new DirectoryList(BP, $filesystemDirPaths);
$generationDirectoryPath = $directoryList->getPath(DirectoryList::GENERATION);
$driverPool = new DriverPool();
$fileWriteFactory = new WriteFactory($driverPool);
/** @var \Magento\Framework\Filesystem\DriverInterface $driver */
$driver = $driverPool->getDriver(DriverPool::FILE);
$directoryWrite = new Write($fileWriteFactory, $driver, $generationDirectoryPath);
if ($directoryWrite->isExist()) {
if ($directoryWrite->isDirectory() || $directoryWrite->isReadable()) {
try {
$probeFilePath = $generationDirectoryPath . DIRECTORY_SEPARATOR . uniqid(mt_rand()) . 'tmp';
$fileWriteFactory->create($probeFilePath, DriverPool::FILE, 'w');
$driver->deleteFile($probeFilePath);
} catch (\Exception $e) {
return false;
}
} else {
return false;
}
} else {
try {
$directoryWrite->create();
} catch (\Exception $e) {
return false;
}
}
return true;
}
示例5: remove
/**
* Run 'composer remove'
*
* @param array $packages
* @return void
*/
public function remove(array $packages)
{
$this->composerApp->resetComposer();
$this->composerApp->setAutoExit(false);
$vendor = (include $this->directoryList->getPath(DirectoryList::CONFIG) . '/vendor_path.php');
$this->composerApp->run(new ArrayInput(['command' => 'remove', 'packages' => $packages, '--working-dir' => $this->directoryList->getRoot() . '/' . $vendor . '/..']));
}
示例6: load
/**
* Loads the configuration file
*
* @param string $fileKey
* @return array
* @throws \Exception
*/
public function load($fileKey = null)
{
$path = $this->dirList->getPath(DirectoryList::CONFIG);
$fileDriver = $this->driverPool->getDriver(DriverPool::FILE);
$result = [];
if ($fileKey) {
$filePath = $path . '/' . $this->configFilePool->getPath($fileKey);
if ($fileDriver->isExists($filePath)) {
$result = (include $filePath);
}
} else {
$configFiles = $this->configFilePool->getPaths();
$allFilesData = [];
$result = [];
foreach (array_keys($configFiles) as $fileKey) {
$configFile = $path . '/' . $this->configFilePool->getPath($fileKey);
if ($fileDriver->isExists($configFile)) {
$fileData = (include $configFile);
} else {
continue;
}
$allFilesData[$configFile] = $fileData;
if (!empty($fileData)) {
$intersection = array_intersect_key($result, $fileData);
if (!empty($intersection)) {
$displayMessage = $this->findFilesWithKeys(array_keys($intersection), $allFilesData);
throw new \Exception("Key collision! The following keys occur in multiple config files:" . PHP_EOL . $displayMessage);
}
$result = array_merge($result, $fileData);
}
}
}
return $result ?: [];
}
示例7: updateTranslationFileContent
/**
* @param string $content
* @return void
*/
public function updateTranslationFileContent($content)
{
$translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . \DIRECTORY_SEPARATOR . $this->assetRepo->getStaticViewFileContext()->getPath();
if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) {
$this->driverFile->createDirectory($translationDir);
}
$this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content);
}
示例8: updateTranslationFileContent
/**
* @param string $content
* @return void
*/
public function updateTranslationFileContent($content)
{
$translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . \DIRECTORY_SEPARATOR . $this->assetRepo->getStaticViewFileContext()->getPath();
if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) {
$this->driverFile->createDirectory($translationDir, \Magento\Framework\Filesystem\Driver\File::WRITEABLE_DIRECTORY_MODE);
}
$this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content);
}
示例9: findComposerJson
/**
* Find absolute path to root Composer json file
*
* @return string
* @throws \Exception
*/
public function findComposerJson()
{
$composerJson = $this->directoryList->getPath(DirectoryList::ROOT) . '/composer.json';
$composerJson = realpath($composerJson);
if ($composerJson === false) {
throw new \Exception('Composer file not found');
}
return $composerJson;
}
示例10: load
/**
* Loads the configuration file
*
* @param string $configFile
* @return array
*/
public function load($configFile = null)
{
if ($configFile) {
$file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $configFile;
} else {
$file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $this->file;
}
$result = @(include $file);
return $result ?: [];
}
示例11: getApplicationNonWritableDirectories
/**
* Retrieve list of recommended non-writable directories for application
*
* @return array
*/
public function getApplicationNonWritableDirectories()
{
if (!$this->applicationNonWritableDirectories) {
$data = [DirectoryList::CONFIG];
foreach ($data as $code) {
$this->applicationNonWritableDirectories[$code] = $this->directoryList->getPath($code);
}
}
return array_values($this->applicationNonWritableDirectories);
}
示例12: testDirectoriesCustomization
public function testDirectoriesCustomization()
{
$config = [DirectoryList::APP => [DirectoryList::PATH => 'foo', DirectoryList::URL_PATH => 'bar']];
$object = new DirectoryList('/root/dir', $config);
$this->assertFileExists($object->getPath(DirectoryList::SYS_TMP));
$this->assertEquals('/root/dir/foo', $object->getPath(DirectoryList::APP));
$this->assertEquals('bar', $object->getUrlPath(DirectoryList::APP));
$this->setExpectedException('\\Magento\\Framework\\Filesystem\\FilesystemException', "Unknown directory type: 'unknown'");
$object->getPath('unknown');
}
示例13: findComposerJson
/**
* Find absolute path to root Composer json file
*
* @return string
* @throws \Exception
*/
public function findComposerJson()
{
// composer.json is in same directory as vendor
$vendorPath = $this->directoryList->getPath(DirectoryList::CONFIG) . '/vendor_path.php';
$vendorDir = (require "{$vendorPath}");
$composerJson = $this->directoryList->getPath(DirectoryList::ROOT) . "/{$vendorDir}/../composer.json";
$composerJson = realpath($composerJson);
if ($composerJson === false) {
throw new \Exception('Composer file not found');
}
return $composerJson;
}
示例14: __construct
/**
* File constructor.
*
* @param Data $helper
* @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
* @param \Magento\Framework\Filesystem $filesystem
*/
public function __construct(\Dotdigitalgroup\Email\Helper\Data $helper, \Magento\Framework\App\Filesystem\DirectoryList $directoryList, \Magento\Framework\Filesystem $filesystem)
{
$this->helper = $helper;
$this->directoryList = $directoryList;
$this->filesystem = $filesystem;
$var = $directoryList->getPath('var');
$this->outputFolder = $var . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . 'email';
$this->outputArchiveFolder = $this->outputFolder . DIRECTORY_SEPARATOR . 'archive';
$this->delimiter = ',';
// tab character
$this->enclosure = '"';
}
示例15: setUp
public function setUp()
{
$this->composerJsonFinder = $this->getMock('Magento\\Framework\\Composer\\ComposerJsonFinder', [], [], '', false);
$this->composerJsonFinder->expects($this->once())->method('findComposerJson')->willReturn('composer.json');
$this->directoryList = $this->getMock('Magento\\Framework\\App\\Filesystem\\DirectoryList', [], [], '', false);
$this->directoryList->expects($this->exactly(2))->method('getPath')->willReturn('var');
$this->reqUpdDryRunCommand = $this->getMock('Magento\\Composer\\RequireUpdateDryRunCommand', [], [], '', false);
$this->file = $this->getMock('Magento\\Framework\\Filesystem\\Driver\\File', [], [], '', false);
$this->file->expects($this->once())->method('copy')->with('composer.json', 'var/composer.json');
$composerAppFactory = $this->getMock('Magento\\Framework\\Composer\\MagentoComposerApplicationFactory', [], [], '', false);
$composerAppFactory->expects($this->once())->method('createRequireUpdateDryRunCommand')->willReturn($this->reqUpdDryRunCommand);
$this->dependencyReadinessCheck = new DependencyReadinessCheck($this->composerJsonFinder, $this->directoryList, $this->file, $composerAppFactory);
}