Skip to content

Commit

Permalink
feat(chore): optimize and implement default value for prevent error
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisdugue committed Nov 10, 2024
1 parent a23aed3 commit dd15415
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions Core/H5POptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,33 @@ public function getUploadedH5pPath($set = null)
}

/**
* @return mixed|string|null
* Helper function to ensure storage_dir always starts with a '/'.
*
* @return string
*/
public function getRelativeH5PPath()
private function formatStorageDir(): string
{
$dir = $this->getOption('storage_dir');
// Setup the default value to empty string
$dir = $this->getOption('storage_dir', [""]);
return $dir[0] === '/' ? $dir : "/{$dir}";
}

public function getAbsoluteH5PPathWithSlash(): string
/**
* @return string
*/
public function getRelativeH5PPath(): string
{
$dir = $this->getOption('storage_dir');
$dir = $dir[0] === '/' ? $dir : "/{$dir}";
return $this->formatStorageDir();
}

return $this->getAbsoluteWebPath() . $dir . '/';
public function getAbsoluteH5PPathWithSlash(): string
{
return $this->getAbsoluteWebPath() . $this->formatStorageDir() . '/';
}

public function getAbsoluteH5PPath(): string
{
$dir = $this->getOption('storage_dir');
$dir = $dir[0] === '/' ? $dir : "/{$dir}";
return rtrim($this->getAbsoluteWebPath(), '/') . $dir;
return rtrim($this->getAbsoluteWebPath(), '/') . $this->formatStorageDir();
}

public function getAbsoluteWebPath(): string
Expand Down

0 comments on commit dd15415

Please sign in to comment.