Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x] Remove the deprecated BaseUrlNotSetException class #1760

Merged
merged 4 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This serves two purposes:
- Minor: Methods in the `Includes` facade now return `HtmlString` objects instead of `string` in https://github.com/hydephp/develop/pull/1738. For more information, see below.
- Minor: `Includes::path()` and `Includes::get()` methods now normalizes paths to be basenames to match the behaviour of the other include methods in https://github.com/hydephp/develop/pull/1738. This means that nested directories are no longer supported, as you should use a data collection for that.
- Minor: The `processing_time_ms` attribute in the `sitemap.xml` file has now been removed in https://github.com/hydephp/develop/pull/1744
- Minor: Updated the `Hyde::url()` helper to return `null` instead of throwing a `BaseUrlNotSetException` when no site URL is set and no path was provided to the method in https://github.com/hydephp/develop/pull/1760
- Improved the sitemap data generation to be smarter and more dynamic in https://github.com/hydephp/develop/pull/1744
- Skipped build tasks will now exit with an exit code of 3 instead of 0 in https://github.com/hydephp/develop/pull/1749
- The `hasFeature` method on the Hyde facade and HydeKernel now only accepts a Feature enum value instead of a string for its parameter.
Expand All @@ -45,6 +46,7 @@ This serves two purposes:
- Breaking: Removed the build task `\Hyde\Framework\Actions\PostBuildTasks\GenerateSearch` (see upgrade guide below)
- Breaking: Removed the deprecated `\Hyde\Framework\Services\BuildService::transferMediaAssets()` method (see upgrade guide below)
- Removed the deprecated global`unslash()` function, replaced with the namespaced `\Hyde\unslash()` function in https://github.com/hydephp/develop/pull/1754
- Removed the deprecated `BaseUrlNotSetException` class, with the `Hyde::url()` helper now returning `null` if no base URL is set in https://github.com/hydephp/develop/pull/1760
- Internal: Removed the internal `DocumentationSearchPage::generate()` method as it was unused in https://github.com/hydephp/develop/pull/1569

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function asset(string $name, bool $preferQualifiedUrl = false): string
return $this->hyperlinks->asset($name, $preferQualifiedUrl);
}

public function url(string $path = ''): string
public function url(string $path = ''): ?string
{
return $this->hyperlinks->url($path);
}
Expand Down
9 changes: 3 additions & 6 deletions packages/framework/src/Foundation/Kernel/Hyperlinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Hyde\Facades\Config;
use Hyde\Support\Models\Route;
use Hyde\Foundation\HydeKernel;
use Hyde\Framework\Exceptions\BaseUrlNotSetException;
use Hyde\Framework\Exceptions\FileNotFoundException;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -140,10 +139,9 @@ public function hasSiteUrl(): bool
* Return a qualified URL to the supplied path if a base URL is set.
*
* @param string $path An optional relative path suffix. Omit to return the base URL.
*
* @throws BaseUrlNotSetException If no site URL is set and no path is provided.
* @return string|null The qualified URL, or null if the base URL is not set and no path is provided.
*/
public function url(string $path = ''): string
public function url(string $path = ''): ?string
{
$path = $this->formatLink(trim($path, '/'));

Expand All @@ -162,8 +160,7 @@ public function url(string $path = ''): string
}

// User is trying to get the base URL, but it's not set
// This exception is deprecated and will be removed in v2.0.0, and we will return null instead.
throw new BaseUrlNotSetException();
return null;
}

/**
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/framework/src/Hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @method static string relativeLink(string $destination)
* @method static string mediaLink(string $destination, bool $validate = false)
* @method static string asset(string $name, bool $preferQualifiedUrl = false)
* @method static string url(string $path = '')
* @method static string|null url(string $path = '')
* @method static Route|null route(string $key)
* @method static string makeTitle(string $value)
* @method static string normalizeNewlines(string $string)
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function route(string $key): ?Hyde\Support\Models\Route
/**
* Get a qualified URL to the supplied path if a base URL is set.
*/
function url(string $path = ''): string
function url(string $path = ''): ?string
{
return hyde()->url($path);
}
Expand Down
2 changes: 0 additions & 2 deletions packages/framework/tests/Feature/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,13 @@ public function testUrlFunctionWithoutBaseUrl()
public function testUrlFunctionWithoutBaseUrlOrPath()
{
$this->app['config']->set(['hyde.url' => null]);
$this->expectException(\Hyde\Framework\Exceptions\BaseUrlNotSetException::class);
$this->assertNull(url());
}

/** @covers ::url */
public function testUrlFunctionWithLocalhostBaseUrlButNoPath()
{
$this->app['config']->set(['hyde.url' => 'http://localhost']);
$this->expectException(\Hyde\Framework\Exceptions\BaseUrlNotSetException::class);
$this->assertNull(url());
}

Expand Down
12 changes: 0 additions & 12 deletions packages/framework/tests/Unit/CustomExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Hyde\Framework\Exceptions\FileConflictException;
use Hyde\Framework\Exceptions\FileNotFoundException;
use Hyde\Framework\Exceptions\RouteNotFoundException;
use Hyde\Framework\Exceptions\BaseUrlNotSetException;
use Hyde\Framework\Exceptions\UnsupportedPageTypeException;
use Hyde\Framework\Exceptions\ParseException;
use RuntimeException;
Expand All @@ -19,7 +18,6 @@
* @covers \Hyde\Framework\Exceptions\FileConflictException
* @covers \Hyde\Framework\Exceptions\FileNotFoundException
* @covers \Hyde\Framework\Exceptions\RouteNotFoundException
* @covers \Hyde\Framework\Exceptions\BaseUrlNotSetException
* @covers \Hyde\Framework\Exceptions\UnsupportedPageTypeException
* @covers \Hyde\Framework\Exceptions\ParseException
*/
Expand Down Expand Up @@ -82,11 +80,6 @@ public function testUnsupportedPageTypeExceptionWithPage()
$this->assertSame('The page type [foo] is not supported.', (new UnsupportedPageTypeException('foo'))->getMessage());
}

public function testBaseUrlNotSetException()
{
$this->assertSame('No site URL has been set in config (or .env).', (new BaseUrlNotSetException())->getMessage());
}

public function testFileConflictExceptionCode()
{
$this->assertSame(409, (new FileConflictException())->getCode());
Expand All @@ -107,11 +100,6 @@ public function testUnsupportedPageTypeExceptionCode()
$this->assertSame(400, (new UnsupportedPageTypeException())->getCode());
}

public function testBaseUrlNotSetExceptionCode()
{
$this->assertSame(500, (new BaseUrlNotSetException())->getCode());
}

public function testParseExceptionCode()
{
$this->assertSame(422, (new ParseException())->getCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

use Hyde\Foundation\HydeKernel;
use Hyde\Foundation\Kernel\Hyperlinks;
use Hyde\Framework\Exceptions\BaseUrlNotSetException;
use Hyde\Testing\TestCase;

/**
* @covers \Hyde\Foundation\Kernel\Hyperlinks
* @covers \Hyde\Framework\Exceptions\BaseUrlNotSetException
*/
class HyperlinksUrlPathHelpersTest extends TestCase
{
Expand Down Expand Up @@ -155,14 +153,11 @@ public function testQualifiedUrlHelperWithAlreadyQualifiedUrlStillFormatsPathWit
$this->assertSame('http://localhost/foo/bar', $this->class->url('http://localhost/foo/bar/'));
}

public function testQualifiedUrlThrowsExceptionWhenNoSiteUrlIsSet()
public function testQualifiedUrlReturnsNullWhenNoSiteUrlIsSet()
{
$this->withSiteUrl(null);

$this->expectException(BaseUrlNotSetException::class);
$this->expectExceptionMessage('No site URL has been set in config (or .env).');

$this->class->url();
$this->assertNull($this->class->url());
}

public function testHelperFallsBackToRelativeLinksWhenNoSiteUrlIsSet()
Expand Down