Home directory of the current user
public static getHomeDir ( ) : string | false | ||
return | string | false | false in case there is no environment variable related to the home directory |
/** * @param array $scriptFolders * @param string $magentoRootFolder */ public function __construct(array $scriptFolders, $magentoRootFolder = null) { $this->_magentoRootFolder = $magentoRootFolder; if (OperatingSystem::isWindows()) { $this->_homeScriptFolder = OperatingSystem::getHomeDir() . '/n98-magerun2/scripts'; } else { $this->_homeScriptFolder = OperatingSystem::getHomeDir() . '/.n98-magerun2/scripts'; } $this->_scriptFolders = $scriptFolders; $this->_scriptFolders[] = $this->_homeScriptFolder; foreach ($this->_scriptFolders as $key => $scriptFolder) { if (!is_dir($scriptFolder)) { unset($this->_scriptFolders[$key]); } } if (count($this->_scriptFolders)) { $this->findScripts(); } }
/** * Load config from all installed bundles * * @param array $config * @param string $magentoRootFolder * * @return array */ public function loadPluginConfig(array $config, $magentoRootFolder) { if ($this->_pluginConfig == null) { $this->_pluginConfig = array(); $moduleBaseFolders = array(); $customFilename = $this->_customConfigFilename; $customName = pathinfo($customFilename, PATHINFO_FILENAME); if (OperatingSystem::isWindows()) { $config['plugin']['folders'][] = getenv('WINDIR') . '/' . $customName . '/modules'; $config['plugin']['folders'][] = OperatingSystem::getHomeDir() . '/' . $customName . '/modules'; } else { $config['plugin']['folders'][] = OperatingSystem::getHomeDir() . '/.' . $customName . '/modules'; } $config['plugin']['folders'][] = $magentoRootFolder . '/lib/' . $customName . '/modules'; foreach ($config['plugin']['folders'] as $folder) { if (is_dir($folder)) { $moduleBaseFolders[] = $folder; } } /** * Allow modules to be placed vendor folder if not in phar mode */ if (!$this->_isPharMode) { if (is_dir($this->getVendorDir())) { $finder = Finder::create(); $finder->files()->depth(2)->followLinks()->ignoreUnreadableDirs(true)->name($customFilename)->in($this->getVendorDir()); foreach ($finder as $file) { /* @var $file SplFileInfo */ $this->registerPluginConfigFile($magentoRootFolder, $file); } } } if (count($moduleBaseFolders) > 0) { // Glob plugin folders $finder = Finder::create(); $finder->files()->depth(1)->followLinks()->ignoreUnreadableDirs(true)->name($customFilename)->in($moduleBaseFolders); foreach ($finder as $file) { /* @var $file SplFileInfo */ $this->registerPluginConfigFile($magentoRootFolder, $file); } } } $config = ArrayFunctions::mergeArrays($config, $this->_pluginConfig); return $config; }
/** * @return string */ protected function _checkRootDirOption() { $specialGlobalOptions = getopt('', array('root-dir:')); if (count($specialGlobalOptions) > 0) { if (isset($specialGlobalOptions['root-dir'][0]) && $specialGlobalOptions['root-dir'][0] == '~') { $specialGlobalOptions['root-dir'] = OperatingSystem::getHomeDir() . substr($specialGlobalOptions['root-dir'], 1); } $folder = realpath($specialGlobalOptions['root-dir']); $this->_directRootDir = true; if (is_dir($folder)) { \chdir($folder); return; } } }
/** * @param InputInterface $input * @return string */ protected function _checkRootDirOption(InputInterface $input) { $definedRootDir = $input->getParameterOption('--root-dir'); if (!empty($definedRootDir)) { if ($definedRootDir[0] == '~') { $definedRootDir = OperatingSystem::getHomeDir() . substr($definedRootDir, 1); } $folder = realpath($definedRootDir); $this->_directRootDir = true; if (is_dir($folder)) { \chdir($folder); return; } } }
/** * Check if there is a user config file. ~/.n98-magerun.yaml * * @param array $config * @param string $magentoRootFolder * * @return array */ public function loadUserConfig($config, $magentoRootFolder = null) { if ($this->_userConfig == null) { $this->_userConfig = array(); $homeDirectory = OperatingSystem::getHomeDir(); if (OperatingSystem::isWindows()) { $personalConfigFile = $homeDirectory . DIRECTORY_SEPARATOR . $this->_customConfigFilename; } else { $personalConfigFile = $homeDirectory . DIRECTORY_SEPARATOR . '.' . $this->_customConfigFilename; } if ($homeDirectory && file_exists($personalConfigFile)) { $userConfig = $this->applyVariables(\file_get_contents($personalConfigFile), $magentoRootFolder, null); $this->_userConfig = Yaml::parse($userConfig); return $config; } } $config = ArrayFunctions::mergeArrays($config, $this->_userConfig); return $config; }
/** * Check if there is a user config file. ~/.n98-magerun.yaml * * @param array $config * @param string $magentoRootFolder * * @return array */ public function loadUserConfig($config, $magentoRootFolder = null) { if ($this->_userConfig == null) { $this->_userConfig = array(); $homeDirectory = OperatingSystem::getHomeDir(); if (OperatingSystem::isWindows()) { $personalConfigFile = $homeDirectory . DIRECTORY_SEPARATOR . $this->_customConfigFilename; } else { $personalConfigFile = $homeDirectory . DIRECTORY_SEPARATOR . '.' . $this->_customConfigFilename; } if ($homeDirectory && file_exists($personalConfigFile)) { $userConfig = $this->applyVariables(\file_get_contents($personalConfigFile), $magentoRootFolder, null); $this->_userConfig = Yaml::parse($userConfig); if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) { $this->_output->writeln('<debug>Load user config <comment>' . $personalConfigFile . '</comment></debug>'); } return $config; } } $config = ArrayFunctions::mergeArrays($config, $this->_userConfig); return $config; }
/** * @return array */ private function getUserConfigFilePaths() { $paths = array(); $homeDirectory = OperatingSystem::getHomeDir(); if (!strlen($homeDirectory)) { return $paths; } if (!is_dir($homeDirectory)) { throw new RuntimeException(sprintf("Home-directory '%s' is not a directory.", $homeDirectory)); } $basename = $this->customConfigFilename; if (OperatingSystem::isWindows()) { $paths[] = $homeDirectory . '/' . $basename; } $paths[] = $homeDirectory . '/.' . $basename; return $paths; }
/** * Set root dir (chdir()) of magento directory * * @param string $path to Magento directory */ private function setRootDir($path) { if (isset($path[0]) && '~' === $path[0]) { $path = OperatingSystem::getHomeDir() . substr($path, 1); } $folder = realpath($path); $this->_directRootDir = true; if (is_dir($folder)) { chdir($folder); } }
/** * @return string */ private function getUserConfigFilePath() { $homeDirectory = OperatingSystem::getHomeDir(); if (!$homeDirectory) { throw new RuntimeException('Unable to get home-directory to obtain user-config-file.'); } if (!is_dir($homeDirectory)) { throw new RuntimeException(sprintf("Home-directory '%s' is not a directory.", $homeDirectory)); } $basename = $this->customConfigFilename; if (!OperatingSystem::isWindows()) { $basename = ".{$basename}"; } return $homeDirectory . '/' . $basename; }