This commit is contained in:
Bastian Allgeier
2020-07-07 12:40:13 +02:00
parent 5f025ac2c2
commit f79d2e960c
176 changed files with 10532 additions and 5343 deletions

View File

@@ -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');
}