public static function getHassCoreFile() { $filesystem = \Yii::createObject(["class" => LocalFilesystem::className(), "path" => __DIR__]); $classMaps = []; foreach ($filesystem->listContents() as $item) { if ($item["type"] == "dir") { $path = $filesystem->getAdapter()->applyPathPrefix($item["path"]); if (!file_exists($path . DIRECTORY_SEPARATOR . 'composer.json')) { continue; } $reader = new ConfigurationReader(); $configuration = $reader->read($path . DIRECTORY_SEPARATOR . 'composer.json'); foreach (array_keys($configuration->autoloadPsr4()) as $namespace) { $classMaps[$namespace] = $path; } } } return $classMaps; }
public function writeFile($classMaps) { /** @var LocalFilesystem $filesystem **/ $filesystem = \Yii::createObject(["class" => LocalFilesystem::className(), "path" => "@core"]); if ($filesystem->has("autoload_psr4.php")) { $filesystem->delete("autoload_psr4.php"); } $classMapsString = "<?php\n\n return " . var_export($classMaps, true) . ";"; $filesystem->write("autoload_psr4.php", $classMapsString); }