MageConfigSync\Magento::findMagentoRootDir PHP Méthode

findMagentoRootDir() public méthode

Given a start directory, work upwards and attempt to identify the Magento root directory. Throws an exception if it can't be found.
public findMagentoRootDir ( string $start_directory ) : string
$start_directory string
Résultat string
    public function findMagentoRootDir($start_directory)
    {
        $ds = DIRECTORY_SEPARATOR;
        $directory_tree = explode($ds, $start_directory);
        while (count($directory_tree) > 0) {
            $current_directory = join($ds, $directory_tree);
            $current_search_location = join($ds, array_merge($directory_tree, array('app', 'Mage.php')));
            if (file_exists($current_search_location)) {
                return $current_directory;
            }
            array_pop($directory_tree);
        }
        throw new \Exception("Unable to locate Magento root");
    }

Usage Example

 /**
  * @test
  * @expectedException \Exception
  */
 public function testFindMagentoRootDirNotFound()
 {
     $dir_prefix = __DIR__ . "/MagentoTest";
     $this->assertFileExists("{$dir_prefix}/a/b/app/Mage.php");
     $magento = new Magento("{$dir_prefix}/a/b");
     $this->assertFileNotExists("{$dir_prefix}/a/app/Mage.php");
     $magento->findMagentoRootDir("{$dir_prefix}/a");
 }