Skip to content

Commit

Permalink
avoid method name collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jan 22, 2025
1 parent f99ca6b commit 7f48f4f
Showing 1 changed file with 74 additions and 47 deletions.
121 changes: 74 additions & 47 deletions src/PackageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,20 @@ public function boot()
{
$this->bootingPackage();

$this->bootAssets();
$this->bootCommands();
$this->bootConsoleCommands();
$this->bootConfigs();
$this->bootInertia();
$this->bootMigrations();
$this->bootProviders();
$this->bootRoutes();
$this->bootTranslations();
$this->bootViews();
$this->bootViewComponents();
$this->bootViewComposers();
$this->bootViewSharedData();
$this
->bootPackageAssets()
->bootPackageCommands()
->bootPackageConsoleCommands()
->bootPackageConfigs()
->bootPackageInertia()
->bootPackageMigrations()
->bootPackageProviders()
->bootPackageRoutes()
->bootPackageTranslations()
->bootPackageViews()
->bootPackageViewComponents()
->bootPackageViewComposers()
->bootPackageViewSharedData();

$this->packageBooted();

Expand Down Expand Up @@ -104,37 +105,43 @@ public function packageView(?string $namespace): ?string
: $this->package->viewNamespace;
}

protected function bootAssets(): void
protected function bootPackageAssets(): static
{
if (! $this->package->hasAssets || ! $this->app->runningInConsole()) {
if (!$this->package->hasAssets || !$this->app->runningInConsole()) {
return;

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-stable - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-stable - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-lowest - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-lowest - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8 - L9.* - prefer-lowest - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L11.* - prefer-stable - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-lowest - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8 - L9.* - prefer-stable - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-lowest - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L11.* - prefer-lowest - ubuntu-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-stable - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-lowest - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-stable - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.* - prefer-lowest - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L11.* - prefer-stable - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-lowest - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-stable - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-stable - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8 - L9.* - prefer-lowest - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L11.* - prefer-lowest - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8 - L9.* - prefer-stable - windows-latest

A function with return type must return a value

Check failure on line 111 in src/PackageServiceProvider.php

View workflow job for this annotation

GitHub Actions / P8.2 - L9.* - prefer-lowest - windows-latest

A function with return type must return a value
}

$vendorAssets = $this->package->basePath('/../resources/dist');
$appAssets = public_path("vendor/{$this->package->shortName()}");

$this->publishes([$vendorAssets => $appAssets], "{$this->package->shortName()}-assets");

return $this;
}

protected function bootCommands()
protected function bootPackageCommands(): self
{
if (empty($this->package->commands)) {
return;
}

$this->commands($this->package->commands);

return $this;
}

protected function bootConsoleCommands()
protected function bootPackageConsoleCommands(): self
{
if (empty($this->package->consoleCommands) || ! $this->app->runningInConsole()) {
if (empty($this->package->consoleCommands) || !$this->app->runningInConsole()) {
return;
}

$this->commands($this->package->consoleCommands);

return $this;
}

protected function bootConfigs()
protected function bootPackageConfigs(): self
{
if ($this->app->runningInConsole()) {
foreach ($this->package->configFileNames as $configFileName) {
Expand All @@ -144,12 +151,14 @@ protected function bootConfigs()
$this->publishes([$vendorConfig => $appConfig], "{$this->package->shortName()}-config");
}
}

return $this;
}

protected function bootInertia()
protected function bootPackageInertia(): self
{
if (! $this->package->hasInertiaComponents) {
return;
if (!$this->package->hasInertiaComponents) {
return $this;
}

$namespace = $this->package->viewNamespace;
Expand All @@ -163,14 +172,16 @@ protected function bootInertia()
"{$this->packageView($namespace)}-inertia-components"
);
}

return $this;
}

protected function bootMigrations()
protected function bootPackageMigrations(): self
{
if ($this->package->discoversMigrations) {
$this->discoverMigrations();
$this->discoverPackageMigrations();

return;
return $this;
}

$now = Carbon::now();
Expand All @@ -180,7 +191,7 @@ protected function bootMigrations()
$appMigration = $this->generateMigrationName($migrationFileName, $now->addSecond());

// Support for the .stub file extension
if (! file_exists($vendorMigration)) {
if (!file_exists($vendorMigration)) {
$vendorMigration .= '.stub';
}

Expand All @@ -195,36 +206,42 @@ protected function bootMigrations()
$this->loadMigrationsFrom($vendorMigration);
}
}

return $this;
}

protected function bootProviders()
protected function bootPackageProviders(): self
{
if (! $this->package->publishableProviderName || ! $this->app->runningInConsole()) {
return;
if (!$this->package->publishableProviderName || !$this->app->runningInConsole()) {
return $this;
}

$providerName = $this->package->publishableProviderName;
$vendorProvider = $this->package->basePath("/../resources/stubs/{$providerName}.php.stub");
$appProvider = base_path("app/Providers/{$providerName}.php");

$this->publishes([$vendorProvider => $appProvider], "{$this->package->shortName()}-provider");

return $this;
}

protected function bootRoutes()
protected function bootPackageRoutes(): self
{
if (empty($this->package->routeFileNames)) {
return;
return $this;
}

foreach ($this->package->routeFileNames as $routeFileName) {
$this->loadRoutesFrom("{$this->package->basePath('/../routes/')}{$routeFileName}.php");
}

return $this;
}

protected function bootTranslations()
protected function bootPackageTranslations(): self
{
if (! $this->package->hasTranslations) {
return;
if (!$this->package->hasTranslations) {
return $this;
}

$vendorTranslations = $this->package->basePath('/../resources/lang');
Expand All @@ -243,12 +260,14 @@ protected function bootTranslations()
"{$this->package->shortName()}-translations"
);
}

return $this;
}

protected function bootViews()
protected function bootPackageViews(): self
{
if (! $this->package->hasViews) {
return;
if (!$this->package->hasViews) {
return $this;
}

$namespace = $this->package->viewNamespace;
Expand All @@ -260,12 +279,14 @@ protected function bootViews()
if ($this->app->runningInConsole()) {
$this->publishes([$vendorViews => $appViews], "{$this->packageView($namespace)}-views");
}

return $this;
}

protected function bootViewComponents()
protected function bootPackageViewComponents(): self
{
if (empty($this->package->viewComponents)) {
return;
return $this;
}

foreach ($this->package->viewComponents as $componentClass => $prefix) {
Expand All @@ -278,31 +299,37 @@ protected function bootViewComponents()

$this->publishes([$vendorComponents => $appComponents], "{$this->package->name}-components");
}

return $this;
}

protected function bootViewComposers()
protected function bootPackageViewComposers(): self
{
if (empty($this->package->viewComposers)) {
return;
return $this;
}

foreach ($this->package->viewComposers as $viewName => $viewComposer) {
View::composer($viewName, $viewComposer);
}

return $this;
}

protected function bootViewSharedData()
protected function bootPackageViewSharedData(): self
{
if (empty($this->package->sharedViewData)) {
return;
return $this;
}

foreach ($this->package->sharedViewData as $name => $value) {
View::share($name, $value);
}

return $this;
}

protected function discoverMigrations()
protected function discoverPackageMigrations(): void
{
$now = Carbon::now();
$migrationsPath = trim($this->package->migrationsPath, '/');
Expand Down Expand Up @@ -330,7 +357,7 @@ protected function discoverMigrations()

protected function generateMigrationName(string $migrationFileName, Carbon $now): string
{
$migrationsPath = 'migrations/'.dirname($migrationFileName).'/';
$migrationsPath = 'migrations/' . dirname($migrationFileName) . '/';
$migrationFileName = basename($migrationFileName);

$len = strlen($migrationFileName) + 4;
Expand All @@ -341,14 +368,14 @@ protected function generateMigrationName(string $migrationFileName, Carbon $now)
}

foreach (glob(database_path("{$migrationsPath}*.php")) as $filename) {
if ((substr($filename, -$len) === $migrationFileName.'.php')) {
if ((substr($filename, -$len) === $migrationFileName . '.php')) {
return $filename;
}
}

$timestamp = $now->format('Y_m_d_His');
$migrationFileName = Str::of($migrationFileName)->snake()->finish('.php');

return database_path($migrationsPath.$timestamp.'_'.$migrationFileName);
return database_path($migrationsPath . $timestamp . '_' . $migrationFileName);
}
}

0 comments on commit 7f48f4f

Please sign in to comment.