Skip to content

Commit

Permalink
Refactor classes instantiation for easier custom bindings (#822)
Browse files Browse the repository at this point in the history
* Refactor classes instantiation for easier custom binding

* Make class properties protected

---------

Co-authored-by: Peter Ragheb <peteragheb@gmail.com>
  • Loading branch information
Peterragheb and Peter Ragheb authored Mar 15, 2024
1 parent e8ac03d commit 32c5f08
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Commands/GenerateDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function handle(RouteMatcherInterface $routeMatcher, GroupedEndpointsFact
$this->writeExampleCustomEndpoint();
}

$writer = new Writer($this->docConfig, $this->paths);
$writer = app(Writer::class, ['config' => $this->docConfig, 'paths' => $this->paths]);
$writer->writeDocs($groupedEndpoints);

$this->upgradeConfigFileIfNeeded();
Expand Down
2 changes: 1 addition & 1 deletion src/ScribeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected function registerCommands(): void
public function loadCustomTranslationLayer(): void
{
$this->app->extend('translation.loader', function ($defaultFileLoader) {
return new CustomTranslationsLoader($defaultFileLoader);
return app(CustomTranslationsLoader::class, ['loader' => $defaultFileLoader]);
});
$this->app->forgetInstance('translator');
self::$customTranslationLayerLoaded = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public static function trans(string $key, array $replace = [])
{
// We only load our custom translation layer if we really need it
if (!ScribeServiceProvider::$customTranslationLayerLoaded) {
(new ScribeServiceProvider(app()))->loadCustomTranslationLayer();
app(ScribeServiceProvider::class, ['app' => app()])->loadCustomTranslationLayer();
}

$translation = trans($key, $replace);
Expand Down
10 changes: 5 additions & 5 deletions src/Writing/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

class Writer
{
private bool $isStatic;
private bool $isExternal;
protected bool $isStatic;
protected bool $isExternal;

private ?string $staticTypeOutputPath;
protected ?string $staticTypeOutputPath;

private ?string $laravelTypeOutputPath;
protected ?string $laravelTypeOutputPath;
protected array $generatedFiles = [
'postman' => null,
'openapi' => null,
Expand All @@ -31,7 +31,7 @@ class Writer
],
];

private string $laravelAssetsPath;
protected string $laravelAssetsPath;

public function __construct(protected DocumentationConfig $config, public PathConfig $paths)
{
Expand Down

0 comments on commit 32c5f08

Please sign in to comment.