-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uses Herd or Valet certificate when available (#46)
* use herd or valet cert * adds optional hostname * update server start output * rename parameter * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
- Loading branch information
1 parent
54ca735
commit 9ec4501
Showing
6 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb; | ||
|
||
class Certificate | ||
{ | ||
/** | ||
* Determine if the certificate exists. | ||
*/ | ||
public static function exists(string $url): bool | ||
{ | ||
return static::resolve($url) !== null; | ||
} | ||
|
||
/** | ||
* Resolve the certificate and key for the given URL. | ||
* | ||
* @return array<int, string>|null | ||
*/ | ||
public static function resolve(string $url): ?array | ||
{ | ||
$host = parse_url($url, PHP_URL_HOST) ?: $url; | ||
$certificate = $host.'.crt'; | ||
$key = $host.'.key'; | ||
|
||
foreach (static::paths() as $path) { | ||
if (file_exists($path.$certificate) && file_exists($path.$key)) { | ||
return [$path.$certificate, $path.$key]; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Get the certificate paths. | ||
* | ||
* @return array<int, string> | ||
*/ | ||
public static function paths(): array | ||
{ | ||
return [ | ||
static::herdPath(), | ||
static::valetPath(), | ||
]; | ||
} | ||
|
||
/** | ||
* Get the Herd certificate path. | ||
*/ | ||
public static function herdPath(): string | ||
{ | ||
return implode(DIRECTORY_SEPARATOR, [$_SERVER['HOME'], 'Library', 'Application Support', 'Herd', 'config', 'valet', 'Certificates', '']); | ||
} | ||
|
||
/** | ||
* Get the Valet certificate path. | ||
*/ | ||
public static function valetPath(): string | ||
{ | ||
return implode(DIRECTORY_SEPARATOR, [$_SERVER['HOME'], '.config', 'valet', 'Certificates', '']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters