3.4.0
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
namespace Kirby\Form;
|
||||
|
||||
use Kirby\Cms\Nest;
|
||||
use Kirby\Exception\Exception;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Http\Remote;
|
||||
use Kirby\Http\Url;
|
||||
use Kirby\Toolkit\Properties;
|
||||
use Kirby\Toolkit\Query;
|
||||
use Kirby\Toolkit\Str;
|
||||
@@ -56,14 +59,31 @@ class OptionsApi
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
$content = @file_get_contents($this->url());
|
||||
if (Url::isAbsolute($this->url()) === true) {
|
||||
// URL, request via cURL
|
||||
$data = Remote::get($this->url())->json();
|
||||
} else {
|
||||
// local file, get contents locally
|
||||
|
||||
if (empty($content) === true) {
|
||||
return [];
|
||||
// ensure the file exists before trying to load it as the
|
||||
// file_get_contents() warnings need to be suppressed
|
||||
if (is_file($this->url()) !== true) {
|
||||
throw new Exception('Local file ' . $this->url() . ' was not found');
|
||||
}
|
||||
|
||||
$content = @file_get_contents($this->url());
|
||||
|
||||
if (is_string($content) !== true) {
|
||||
throw new Exception('Unexpected read error'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if (empty($content) === true) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$data = json_decode($content, true);
|
||||
}
|
||||
|
||||
$data = json_decode($content, true);
|
||||
|
||||
if (is_array($data) === false) {
|
||||
throw new InvalidArgumentException('Invalid options format');
|
||||
}
|
||||
|
Reference in New Issue
Block a user