N98\Magento\Application\ConfigLocator::getProjectConfigFile PHP Method

getProjectConfigFile() public method

Obtain the project-config-file, it is placed in the magento app/etc dir, e.g. app/etc/n98-magerun2.yaml
public getProjectConfigFile ( ) : ConfigFile | null
return ConfigFile | null
    public function getProjectConfigFile()
    {
        if (!strlen($this->magentoRootFolder)) {
            return;
        }
        $projectConfigFilePath = $this->magentoRootFolder . '/app/etc/' . $this->customConfigFilename;
        if (!is_readable($projectConfigFilePath)) {
            return;
        }
        try {
            $projectConfigFile = ConfigFile::createFromFile($projectConfigFilePath);
            $projectConfigFile->applyVariables($this->magentoRootFolder);
        } catch (InvalidArgumentException $e) {
            $projectConfigFile = null;
        }
        return $projectConfigFile;
    }

Usage Example

 /**
  * MAGENTO_ROOT/app/etc/n98-magerun.yaml
  *
  * @param string $magentoRootFolder
  * @param string $magerunStopFileFolder
  * @param array $config
  *
  * @return array
  */
 public function loadProjectConfig($magentoRootFolder, $magerunStopFileFolder, array $config)
 {
     if (null !== $this->_projectConfig) {
         return ArrayFunctions::mergeArrays($config, $this->_projectConfig);
     }
     $this->_projectConfig = array();
     $locator = new ConfigLocator($this->_customConfigFilename, $magentoRootFolder);
     if ($projectConfigFile = $locator->getProjectConfigFile()) {
         $this->_projectConfig = $projectConfigFile->toArray();
     }
     if ($stopFileConfigFile = $locator->getStopFileConfigFile($magerunStopFileFolder)) {
         $this->_projectConfig = $stopFileConfigFile->mergeArray($this->_projectConfig);
     }
     return ArrayFunctions::mergeArrays($config, $this->_projectConfig);
 }