Skip to content

Commit da5ef06

Browse files
committed
Merge branch 'master' into 2.x-dev
2 parents c5de14c + aa06e42 commit da5ef06

File tree

7 files changed

+82
-8
lines changed

7 files changed

+82
-8
lines changed

packages/framework/config/commands.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
NunoMaduro\LaravelConsoleSummary\SummaryCommand::class,
5959
Symfony\Component\Console\Command\DumpCompletionCommand::class,
6060
Symfony\Component\Console\Command\HelpCommand::class,
61+
\Illuminate\Cache\Console\ClearCommand::class,
6162
\Hyde\Console\Commands\DebugCommand::class,
6263
\Torchlight\Commands\Install::class,
6364
],

packages/framework/src/Foundation/Kernel/Hyperlinks.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function mediaLink(string $destination, bool $validate = false): string
110110
*/
111111
public function asset(string $name, bool $preferQualifiedUrl = false): string
112112
{
113-
if (str_starts_with($name, 'http')) {
113+
if (static::isRemote($name)) {
114114
return $name;
115115
}
116116

@@ -145,7 +145,7 @@ public function url(string $path = ''): ?string
145145
{
146146
$path = $this->formatLink(trim($path, '/'));
147147

148-
if (str_starts_with($path, 'http')) {
148+
if (static::isRemote($path)) {
149149
return $path;
150150
}
151151

@@ -170,4 +170,12 @@ public function route(string $key): ?Route
170170
{
171171
return $this->kernel->routes()->get($key);
172172
}
173+
174+
/**
175+
* Determine if the given URL is a remote link.
176+
*/
177+
public static function isRemote(string $url): bool
178+
{
179+
return str_starts_with($url, 'http') || str_starts_with($url, '//');
180+
}
173181
}

packages/framework/src/Framework/Factories/FeaturedImageFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use RuntimeException;
99
use Illuminate\Support\Str;
1010
use Hyde\Markdown\Models\FrontMatter;
11+
use Hyde\Foundation\Kernel\Hyperlinks;
1112
use Hyde\Framework\Features\Blogging\Models\FeaturedImage;
1213
use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\FeaturedImageSchema;
1314

@@ -72,7 +73,7 @@ protected function makeSource(): string
7273
throw new RuntimeException(sprintf('No featured image source was found in "%s"', $this->filePath ?? 'unknown file'));
7374
}
7475

75-
if (FeaturedImage::isRemote($value)) {
76+
if (Hyperlinks::isRemote($value)) {
7677
return $value;
7778
}
7879

packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
use Hyde\Facades\Config;
1010
use Illuminate\Support\Str;
1111
use Hyde\Support\BuildWarnings;
12+
use JetBrains\PhpStorm\Deprecated;
1213
use Illuminate\Support\Facades\Http;
14+
use Hyde\Foundation\Kernel\Hyperlinks;
1315
use Hyde\Framework\Exceptions\FileNotFoundException;
1416
use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\FeaturedImageSchema;
1517

@@ -19,7 +21,6 @@
1921
use function filesize;
2022
use function sprintf;
2123
use function key;
22-
use function str_starts_with;
2324

2425
/**
2526
* Object representation of a blog post's featured image.
@@ -63,7 +64,7 @@ public function __construct(
6364
protected readonly ?string $licenseUrl = null,
6465
protected readonly ?string $copyrightText = null
6566
) {
66-
$this->type = self::isRemote($source) ? self::TYPE_REMOTE : self::TYPE_LOCAL;
67+
$this->type = Hyperlinks::isRemote($source) ? self::TYPE_REMOTE : self::TYPE_LOCAL;
6768
$this->source = $this->setSource($source);
6869
}
6970

@@ -241,8 +242,14 @@ protected function getContentLengthForRemoteImage(): int
241242
return 0;
242243
}
243244

245+
/**
246+
* @codeCoverageIgnore Deprecated method.
247+
*
248+
* @deprecated This method will be removed in v2.0. Please use `Hyperlinks::isRemote` instead.
249+
*/
250+
#[Deprecated(reason: 'Replaced by the \Hyde\Foundation\Kernel\Hyperlinks::isRemote method', replacement: '\Hyde\Foundation\Kernel\Hyperlinks::isRemote(%parametersList%)', since: '1.8.0')]
244251
public static function isRemote(string $source): bool
245252
{
246-
return str_starts_with($source, 'http') || str_starts_with($source, '//');
253+
return Hyperlinks::isRemote($source);
247254
}
248255
}

packages/framework/src/Framework/Features/Metadata/PageMetadataBag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Hyde\Facades\Meta;
88
use Hyde\Pages\Concerns\HydePage;
99
use Hyde\Pages\MarkdownPost;
10+
use Hyde\Foundation\Kernel\Hyperlinks;
1011

11-
use function str_starts_with;
1212
use function substr_count;
1313
use function str_repeat;
1414

@@ -77,7 +77,7 @@ protected function resolveImageLink(string $image): string
7777
{
7878
// Since this is run before the page is rendered, we don't have the currentPage property.
7979
// So we need to run some of the same calculations here to resolve the image path link.
80-
return str_starts_with($image, 'http') ? $image
80+
return Hyperlinks::isRemote($image) ? $image
8181
: str_repeat('../', substr_count(MarkdownPost::outputDirectory().'/'.$this->page->identifier, '/')).$image;
8282
}
8383
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hyde\Framework\Testing\Feature\Commands;
6+
7+
use Hyde\Testing\TestCase;
8+
use Illuminate\Support\Facades\Cache;
9+
10+
/**
11+
* @coversNothing
12+
*/
13+
class CacheClearCommandTest extends TestCase
14+
{
15+
public function testCacheClearCommand()
16+
{
17+
Cache::remember('foo', 60, fn () => 'bar');
18+
19+
$this->assertSame('bar', Cache::get('foo'));
20+
21+
$this->artisan('cache:clear')
22+
->expectsOutputToContain('Application cache cleared successfully.')
23+
->assertExitCode(0);
24+
25+
$this->assertNull(Cache::get('foo'));
26+
}
27+
}

packages/framework/tests/Feature/Foundation/HyperlinksTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,34 @@ public function testRouteHelperWithInvalidRoute()
127127
{
128128
$this->assertNull($this->class->route('foo'));
129129
}
130+
131+
public function testIsRemoteWithHttpUrl()
132+
{
133+
$this->assertTrue(Hyperlinks::isRemote('http://example.com'));
134+
}
135+
136+
public function testIsRemoteWithHttpsUrl()
137+
{
138+
$this->assertTrue(Hyperlinks::isRemote('https://example.com'));
139+
}
140+
141+
public function testIsRemoteWithProtocolRelativeUrl()
142+
{
143+
$this->assertTrue(Hyperlinks::isRemote('//example.com'));
144+
}
145+
146+
public function testIsRemoteWithRelativeUrl()
147+
{
148+
$this->assertFalse(Hyperlinks::isRemote('/path/to/resource'));
149+
}
150+
151+
public function testIsRemoteWithAbsoluteLocalPath()
152+
{
153+
$this->assertFalse(Hyperlinks::isRemote('/var/www/html/index.php'));
154+
}
155+
156+
public function testIsRemoteWithEmptyString()
157+
{
158+
$this->assertFalse(Hyperlinks::isRemote(''));
159+
}
130160
}

0 commit comments

Comments
 (0)