Skip to content

Commit

Permalink
Merge pull request #906 from hydephp/move-project-configuration-prope…
Browse files Browse the repository at this point in the history
…rties-to-the-hyde-kernel

Move internal data store for the site output directory to the HydeKernel
  • Loading branch information
caendesilva authored Feb 1, 2023
2 parents fbcf709 + 96c5b5d commit e2c2492
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
7 changes: 2 additions & 5 deletions packages/framework/src/Facades/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Hyde\Framework\Features\Metadata\GlobalMetadataBag;
use Hyde\Hyde;
use function unslash;

/**
* Object representation for the HydePHP site and its configuration.
Expand All @@ -15,8 +14,6 @@
*/
final class Site
{
protected static string $outputPath = '_site';

public static function url(): ?string
{
return config('site.url');
Expand All @@ -39,11 +36,11 @@ public static function metadata(): GlobalMetadataBag

public static function getOutputPath(): string
{
return self::$outputPath;
return Hyde::kernel()->getOutputPath();
}

public static function setOutputPath(string $outputPath): void
{
self::$outputPath = unslash(Hyde::pathToRelative($outputPath));
Hyde::kernel()->setOutputPath($outputPath);
}
}
10 changes: 10 additions & 0 deletions packages/framework/src/Foundation/Concerns/ManagesHydeKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public function setSourceRoot(string $sourceRoot): void
$this->sourceRoot = rtrim($sourceRoot, '/\\');
}

public function getOutputPath(): string
{
return $this->outputPath;
}

public function setOutputPath(string $outputPath): void
{
$this->outputPath = rtrim($outputPath, '/\\');
}

/**
* Developer Information.
*
Expand Down
1 change: 1 addition & 0 deletions packages/framework/src/Foundation/HydeKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class HydeKernel implements SerializableContract

protected string $basePath;
protected string $sourceRoot = '';
protected string $outputPath = '_site';

protected Filesystem $filesystem;
protected Hyperlinks $hyperlinks;
Expand Down
11 changes: 11 additions & 0 deletions packages/framework/tests/Feature/HydeKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,17 @@ public function test_can_set_source_root()
$this->assertSame('foo', Hyde::getSourceRoot());
}

public function test_can_get_output_path()
{
$this->assertSame('_site', Hyde::getOutputPath());
}

public function test_can_set_output_path()
{
Hyde::setOutputPath('foo');
$this->assertSame('foo', Hyde::getOutputPath());
}

public function test_can_access_kernel_fluently_using_the_facade()
{
$this->assertInstanceOf(HydeKernel::class, Hyde::kernel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,9 @@ public function test_site_output_directory_can_be_changed_in_configuration()
File::deleteDirectory(Hyde::path('_site/build'));
}

public function test_site_output_directory_path_is_normalized_to_be_relative()
{
Site::setOutputPath(Hyde::path('_site'));
$this->assertEquals('_site', Site::getOutputPath());

Site::setOutputPath('_site');
}

public function test_site_output_directory_path_is_normalized_to_trim_trailing_slashes()
{
Site::setOutputPath('foo/bar/');
$this->assertEquals('foo/bar', Site::getOutputPath());

Site::setOutputPath('_site');
}
}

0 comments on commit e2c2492

Please sign in to comment.