Skip to content

Commit

Permalink
Merge pull request #1412 from hydephp/set-build-flag-in-runtime-confi…
Browse files Browse the repository at this point in the history
…guration

Add runtime configuration option for the `--no-api` build flag hydephp/develop@285f819
  • Loading branch information
github-actions committed Oct 28, 2023
1 parent 2e55141 commit 1a645df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Foundation/Internal/LoadConfiguration.php
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);
}
}
}
}
3 changes: 1 addition & 2 deletions src/Framework/Features/Blogging/Models/FeaturedImage.php
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 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'));
}
}

0 comments on commit 1a645df

Please sign in to comment.