Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtime configuration option for the --no-api build flag #1412

Merged
merged 3 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ private function loadRuntimeConfiguration(Application $app, RepositoryContract $
if (in_array('--pretty-urls', $_SERVER['argv'], true)) {
$repository->set('hyde.pretty_urls', true);
}

// Check if the `--no-api` CLI argument is set, and if so, set the config value accordingly.
if (in_array('--no-api', $_SERVER['argv'], true)) {
$repository->set('hyde.api_calls', false);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Hyde\Framework\Exceptions\FileNotFoundException;
use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\FeaturedImageSchema;

use function in_array;
use function array_key_exists;
use function array_flip;
use function file_exists;
Expand Down Expand Up @@ -226,7 +225,7 @@ protected function getContentLengthForLocalImage(): int
protected function getContentLengthForRemoteImage(): int
{
// Check if the --no-api flag is set when running the build command, and if so, skip the API call.
if (! (isset($_SERVER['argv']) && in_array('--no-api', $_SERVER['argv'], true))) {
if (Config::getBool('hyde.api_calls', true)) {
$headers = Http::withHeaders([
'User-Agent' => Config::getString('hyde.http_user_agent', 'RSS Request Client'),
])->head($this->getSource())->headers();
Expand Down
4 changes: 3 additions & 1 deletion packages/framework/tests/Unit/LoadConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ public function testItLoadsRuntimeConfiguration()
{
$serverBackup = $_SERVER;

$_SERVER['argv'] = ['--pretty-urls'];
$_SERVER['argv'] = ['--pretty-urls', '--no-api'];

$app = new Application(getcwd());

$loader = new LoadConfiguration();
$loader->bootstrap($app);

$this->assertTrue(config('hyde.pretty_urls'));
$this->assertFalse(config('hyde.api_calls'));

$_SERVER = $serverBackup;

$loader->bootstrap($app);
$this->assertFalse(config('hyde.pretty_urls'));
$this->assertNull(config('hyde.api_calls'));
}
}
Loading