Generating under Windows does not compute relative path correctly
Describe the bug
Under Windows, running the command to generate code includes a relative path to the configuration file that goes all the way to the root of the Windows drive. So instead of having something like that:
public static function config(): string
{
return \Safe\realpath(__DIR__ . '/../../../../../sailor.php');
}
We obtain something like the following:
public static function config(): string
{
return \Safe\realpath(__DIR__ . '/../../../../../../C:\Users\johndoe\Documents\dev\project\website\sailor.php');
}
Expected behavior/Solution
Regardless of operating system, we should get the short form of relative path.
Steps to reproduce
- Be under Windows
- Run the code generator
Output/Logs
Nothing of importance.
How to get around the issue
Change \Spawnia\Sailor\Codegen\Generator::configPath this way:
protected function configPath(string $directory): string
{
// $from = explode('/', $directory);
// $to = explode('/', $this->configFile);
$from = preg_split('~[\\\\/]~', $directory);
$to = preg_split('~[\\\\/]~', $this->configFile);
I am not having much time on my hand to do a PR. If nobody does, I'll see if I can get to it.
I have never used PHP on Windows and I have no plans to do it, so supporting it is really low on my list of priorities. If you can provide a merge request that fixes the issue, I will consider it. If possible, it should add tests, preferrably by setting up automated tests that run on Windows in GitHub actions.