Skip to content

Instantly share code, notes, and snippets.

@TheSETJ
Created November 6, 2023 10:20
Show Gist options
  • Save TheSETJ/90a404d11202977b51520b4afda06049 to your computer and use it in GitHub Desktop.
Save TheSETJ/90a404d11202977b51520b4afda06049 to your computer and use it in GitHub Desktop.
A trait that helps with formatting URI
<?php
trait WorksWithUri
{
private function makeFullUri($baseUri, $path)
{
return $this->formatBaseUri($baseUri) . $this->formatRelativePath($path);
}
private function formatBaseUri($baseUri)
{
return rtrim($baseUri, '/');
}
private function formatRelativePath($path)
{
return '/' . ltrim($path, '/');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment