Skip to content

Commit

Permalink
Implemented a better path resolver for getTemporaryDirectoryPath and …
Browse files Browse the repository at this point in the history
…added some comments & annotations.
  • Loading branch information
ArclightHub committed Nov 27, 2023
1 parent b653141 commit ba820fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions camel/Camel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class Camel
{
public static function cacheDir(PathConfig $pathConfiguration): string
{
return $pathConfiguration->getTemporaryDirectoryPath() . "/endpoints.cache";
return $pathConfiguration->getTemporaryDirectoryPath('endpoints.cache');
}

public static function camelDir(PathConfig $pathConfiguration): string
{
return $pathConfiguration->getTemporaryDirectoryPath() . "/endpoints";
return $pathConfiguration->getTemporaryDirectoryPath('endpoints');
}

/**
Expand Down
18 changes: 13 additions & 5 deletions src/Configuration/PathConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,44 @@ class PathConfig
* @param string $scribeConfig
* @param bool $isHidden
*/
public function __construct(string $cacheDir, string$scribeConfig, bool $isHidden = true)
public function __construct(string $cacheDir, string $scribeConfig, bool $isHidden = true)
{
$this->cacheDir = $cacheDir;
$this->scribeConfig = $scribeConfig;
$this->isHidden = $isHidden;
}

/**
* Path to the scribe.php (default) or otherwise named configuration file.
*
* @param string|null $resolvePath
* @param string $separator
* @return string
*/
public function getScribeConfigurationPath(string $resolvePath = null, string $separator = '/'): string
{
if (is_null($resolvePath)) {
return $this->scribeConfig;
}
// Separate the path with a /
// Separate the path with a / (default) or an override via $separator
return sprintf("%s%s%s", $this->scribeConfig, $separator, $resolvePath);
}

/**
* Get the path to the .scribe (default) or otherwise named temporary file path.
*
* @param string|null $resolvePath
* @param string $separator
* @return string
*/
public function getTemporaryDirectoryPath(string $resolvePath = null): string
public function getTemporaryDirectoryPath(string $resolvePath = null, string $separator = '/'): string
{
$path = ($this->isHidden ? '.' : '') . $this->cacheDir;
if (is_null($resolvePath)) {
return $path;
}
// Separate the path with a /
return sprintf("%s/%s", $path, $resolvePath);
// Separate the path with a / (default) or an override via $separator
return sprintf("%s%s%s", $path, $separator, $resolvePath);

}
}

0 comments on commit ba820fe

Please sign in to comment.