generated from vormkracht10/laravel-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace curl with HTTP * Replace curl with http in getRemoteFileSize method * Change empty data check * Fix styling * Mark test skipped until we have a solution * Fix styling * Add try/catch to request * Http class to handle remote response in one place * Fix styling * Safe usage of new static by returning self --------- Co-authored-by: Baspa <[email protected]>
- Loading branch information
Showing
29 changed files
with
134 additions
and
109 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
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
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
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
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
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
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,90 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\Seo; | ||
|
||
use Illuminate\Support\Facades\Http as HttpFacade; | ||
|
||
class Http | ||
{ | ||
public string $url; | ||
|
||
public array $options = []; | ||
|
||
public array $headers = []; | ||
|
||
public HttpFacade $http; | ||
|
||
public function __construct(string $url) | ||
{ | ||
$this->url = $url; | ||
} | ||
|
||
public static function make(string $url): self | ||
{ | ||
return new self($url); | ||
} | ||
|
||
public function withOptions(array $options): self | ||
{ | ||
$this->options = $options; | ||
|
||
return $this; | ||
} | ||
|
||
public function withHeaders(array $headers): self | ||
{ | ||
$this->headers = $headers; | ||
|
||
return $this; | ||
} | ||
|
||
public function get(): object | ||
{ | ||
return HttpFacade::withOptions([ | ||
...config('seo.http.options', []), | ||
...$this->options, | ||
])->withHeaders([ | ||
...config('seo.http.headers', []), | ||
...$this->headers, | ||
])->get($this->url); | ||
} | ||
|
||
public function getRemoteResponse(): object | ||
{ | ||
$options = [ | ||
'timeout' => 30, | ||
'return_transfer' => true, | ||
'follow_location' => true, | ||
'no_body' => true, | ||
'header' => true, | ||
]; | ||
|
||
if (app()->runningUnitTests()) { | ||
$options = [ | ||
...$options, | ||
'ssl_verifyhost' => false, | ||
'ssl_verifypeer' => false, | ||
'ssl_verifystatus' => false, | ||
]; | ||
} | ||
|
||
$domain = parse_url($this->url, PHP_URL_HOST); | ||
|
||
if (in_array($domain, array_keys(config('seo.resolve')))) { | ||
$port = str_contains($this->url, 'https://') ? 443 : 80; | ||
|
||
$ipAddress = config('seo.resolve')[$domain]; | ||
|
||
if (! empty($ipAddress)) { | ||
$options = [ | ||
...$options, | ||
'resolve' => ["{$domain}:{$port}:{$ipAddress}"], | ||
]; | ||
} | ||
} | ||
|
||
$this->withOptions($options); | ||
|
||
return $this->get(); | ||
} | ||
} |
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
Oops, something went wrong.