Skip to content

Commit

Permalink
Merge pull request #1753 from hydephp/deprecate-global-unslash-function
Browse files Browse the repository at this point in the history
[1.x] Deprecate the global `unslash` function
  • Loading branch information
caendesilva authored Jun 28, 2024
2 parents 1bd214e + 2fa5278 commit 3757b46
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This serves two purposes:
- Updated the `.env.example` file to contain more details on the site URL setting's usages in https://github.com/hydephp/develop/pull/1746

### Deprecated
- for soon-to-be removed features.
- Deprecated the global `unslash()` function, replaced with the existing namespaced `\Hyde\unslash()` function in https://github.com/hydephp/develop/pull/1753

### Removed
- for now removed features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use function file_exists;
use function in_array;
use function str_replace;
use function unslash;
use function Hyde\unslash;

/**
* Build a single static site file.
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Foundation/Kernel/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use function array_map;
use function is_array;
use function str_starts_with;
use function unslash;
use function Hyde\unslash;
use function unlink;
use function touch;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use function basename;
use function in_array;
use function str_contains;
use function unslash;
use function Hyde\unslash;
use function rtrim;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use function array_unique;
use function array_merge;
use function base_path;
use function unslash;
use function Hyde\unslash;

/**
* This trait registers the file paths for important Hyde locations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use function str_starts_with;
use function is_string;
use function unslash;
use function Hyde\unslash;

class FeaturedImageFactory extends Concerns\PageDataFactory implements FeaturedImageSchema
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use function Hyde\unixsum_file;
use function str_replace;
use function in_array;
use function unslash;
use function Hyde\unslash;
use function glob;

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Pages/Concerns/HydePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Hyde\Support\Models\RouteKey;
use Illuminate\Support\Str;

use function unslash;
use function Hyde\unslash;
use function filled;
use function ltrim;
use function rtrim;
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Pages/DocumentationPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use function trim;
use function sprintf;
use function unslash;
use function Hyde\unslash;
use function basename;

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Support/DataCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use function implode;
use function json_decode;
use function sprintf;
use function unslash;
use function Hyde\unslash;
use function str_starts_with;

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Support/Models/RouteKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Stringable;

use function unslash;
use function Hyde\unslash;

/**
* Route keys provide the core bindings of the HydePHP routing system as they are what canonically identifies a page.
Expand Down
8 changes: 7 additions & 1 deletion packages/framework/src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace {
use Hyde\Foundation\HydeKernel;
use JetBrains\PhpStorm\Deprecated;

if (! function_exists('hyde')) {
/**
Expand All @@ -18,10 +19,15 @@ function hyde(): HydeKernel
if (! function_exists('unslash')) {
/**
* Remove trailing slashes from the start and end of a string.
*
* @deprecated This function will be replaced by {@see \Hyde\unslash()} in v2.0
*
* @codeCoverageIgnore This function is deprecated and will be removed in a future release.
*/
#[Deprecated(reason: 'Replaced by the \Hyde\unslash() function', replacement: '\Hyde\unslash(%parametersList%)', since: '1.7.0')]
function unslash(string $string): string
{
return trim($string, '/\\');
return \Hyde\unslash($string);
}
}

Expand Down
14 changes: 7 additions & 7 deletions packages/framework/tests/Feature/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ public function testCanCallMethodsOnReturnedHydeClass()
$this->assertSame(Hyde::path(), hyde()->path());
}

/** @covers ::unslash */
/** @covers ::\Hyde\unslash */
public function testUnslashFunctionExists()
{
$this->assertTrue(function_exists('unslash'));
$this->assertTrue(function_exists('Hyde\unslash'));
}

/** @covers ::unslash */
/** @covers ::\Hyde\unslash */
public function testUnslashFunctionTrimsTrailingSlashes()
{
$tests = ['foo', '/foo', 'foo/', '/foo/', '\foo\\', '\\/foo/\\'];

foreach ($tests as $test) {
$this->assertSame('foo', unslash($test));
$this->assertSame('foo', \Hyde\unslash($test));
}

$tests = ['', '/', '\\', '/\\'];

foreach ($tests as $test) {
$this->assertSame('', unslash($test));
$this->assertSame('', \Hyde\unslash($test));
}

$tests = ['foo/bar', 'foo/bar/', 'foo/bar\\', '\\/foo/bar/\\'];

foreach ($tests as $test) {
$this->assertSame('foo/bar', unslash($test));
$this->assertSame('foo/bar', \Hyde\unslash($test));
}
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public function testUnslashFunctionExistsInHydeNamespace()
/** @covers ::\Hyde\unslash */
public function testNamespacedUnslashFunction()
{
$this->assertSame(unslash('foo'), \Hyde\unslash('foo'));
$this->assertSame(\Hyde\unslash('foo'), \Hyde\unslash('foo'));
}

/** @covers ::\Hyde\unixsum */
Expand Down
2 changes: 1 addition & 1 deletion packages/realtime-compiler/src/Routing/PageRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static function handle(Request $request): Response

protected function getPageFromRoute(): HydePage
{
if (unslash($this->request->path) === DocumentationSearchPage::routeKey() && DocumentationSearchPage::enabled()) {
if (\Hyde\unslash($this->request->path) === DocumentationSearchPage::routeKey() && DocumentationSearchPage::enabled()) {
// Since this page is not present within the search index (as it's normally generated by a build task)
// we instantiate and return it here.
return new DocumentationSearchPage();
Expand Down

0 comments on commit 3757b46

Please sign in to comment.