0 follower

Final Class Yiisoft\YiiDevTool\App\Component\PhpStorm\Folders

InheritanceYiisoft\YiiDevTool\App\Component\PhpStorm\Folders

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $ideaPath )
$ideaPath string

                public function __construct(string $ideaPath)
{
    if (!is_dir($ideaPath)) {
        throw new \InvalidArgumentException("No .idea at $ideaPath.");
    }
    $this->ideaPath = $ideaPath;
}

            
excludeFolder() public method

public mixed excludeFolder ( string $path )
$path string

                public function excludeFolder(string $path)
{
    $this->excludeFolders[] = $path;
}

            
sourceFolder() public method

public mixed sourceFolder ( string $path )
$path string

                public function sourceFolder(string $path)
{
    $this->sourceFolders[] = $path;
}

            
testsFolder() public method

public mixed testsFolder ( string $path )
$path string

                public function testsFolder(string $path)
{
    $this->testsFolders[] = $path;
}

            
write() public method

public void write ( )

                public function write(): void
{
    $entries = '';
    foreach ($this->excludeFolders as $excludeFolder) {
        $entries .= sprintf("      <excludeFolder url=\"file://\$MODULE_DIR$/%s\" />\n", $excludeFolder);
    }
    foreach ($this->sourceFolders as $sourceFolder) {
        $entries .= sprintf("      <sourceFolder url=\"file://\$MODULE_DIR$/%s\" isTestSource=\"false\" />\n", $sourceFolder);
    }
    foreach ($this->testsFolders as $testsFolder) {
        $entries .= sprintf("      <sourceFolder url=\"file://\$MODULE_DIR$/%s\" isTestSource=\"true\" />\n", $testsFolder);
    }
    $modulesContent = file_get_contents($this->ideaPath . '/modules.xml');
    if (!preg_match('~<module.*?filepath="\$PROJECT_DIR\$/\.idea/(.*?.iml)"~', $modulesContent, $matches)) {
        throw new \RuntimeException('Can not find module path in modules.xml.');
    }
    $imlPath = $this->ideaPath . '/' . $matches[1];
    $imlContent = file_get_contents($imlPath);
    $imlContent = preg_replace(
        '~<content url="file://\$MODULE_DIR\$">.*</content>~s',
        "<content url=\"file://\$MODULE_DIR\$\">\n" . $entries . '    </content>',
        $imlContent
    );
    file_put_contents($imlPath, $imlContent);
}