Skip to content

Commit

Permalink
Added attribute for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Sep 12, 2024
1 parent d374e1e commit 4d730e2
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Platform/Commands/AdminCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use Illuminate\Database\QueryException;
use Orchid\Platform\Models\User;
use Orchid\Support\Facades\Dashboard;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:admin')]
class AdminCommand extends Command
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Platform/Commands/ChartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Illuminate\Console\GeneratorCommand;
use Orchid\Platform\Dashboard;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:chart')]
class ChartCommand extends GeneratorCommand
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Platform/Commands/FilterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Illuminate\Console\GeneratorCommand;
use Orchid\Platform\Dashboard;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:filter')]
class FilterCommand extends GeneratorCommand
{
/**
Expand Down
44 changes: 44 additions & 0 deletions src/Platform/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

use Illuminate\Console\Command;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Traits\Conditionable;
use Orchid\Platform\Dashboard;
use Orchid\Platform\Events\InstallEvent;
use Orchid\Platform\Providers\ConsoleServiceProvider;

#[AsCommand(name: 'orchid:install')]

Check failure on line 14 in src/Platform/Commands/InstallCommand.php

View workflow job for this annotation

GitHub Actions / psalm

UndefinedAttributeClass

src/Platform/Commands/InstallCommand.php:14:3: UndefinedAttributeClass: Attribute class Orchid\Platform\Commands\AsCommand does not exist (see https://psalm.dev/241)
class InstallCommand extends Command
{
use Conditionable;

/**
* The console command signature.
*
Expand Down Expand Up @@ -50,6 +54,9 @@ public function handle()
->executeCommand('storage:link')
->changeUserModel()
->setValueEnv('SCOUT_DRIVER')
->when(class_exists(\App\Models\User::class), function () {
$this->replaceInFiles(app_path(), 'use Orchid\\Platform\\Models\\User;', 'use App\\Models\\User;');
})
->showMeLove();

$this->info('Completed!');
Expand Down Expand Up @@ -147,4 +154,41 @@ private function showMeLove(): self

return $this;
}


/**
* @param string $directory
* @param string $search
* @param string $replace
*
* @return void
*/
private function replaceInFiles(string $directory, string $search, string $replace): self
{
if (!is_dir($directory)) {
return $this;
}

$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));

// Проходим по всем файлам в директории
foreach ($files as $file) {
// Проверяем, что это файл и имеет расширение .php
if ($file->isFile() && $file->getExtension() === 'php') {
$filePath = $file->getRealPath();
$fileContents = file_get_contents($filePath);

// Если содержимое файла содержит старый namespace
if (strpos($fileContents, $search) !== false) {
// Заменяем старый namespace на новый
$updatedContents = str_replace($search, $replace, $fileContents);

// Сохраняем изменения
file_put_contents($filePath, $updatedContents);
}
}
}

return $this;
}
}
2 changes: 2 additions & 0 deletions src/Platform/Commands/ListenerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Illuminate\Console\GeneratorCommand;
use Orchid\Platform\Dashboard;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:listener')]
class ListenerCommand extends GeneratorCommand
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Platform/Commands/PresenterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Illuminate\Console\GeneratorCommand;
use Orchid\Platform\Dashboard;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:presenter')]
class PresenterCommand extends GeneratorCommand
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Platform/Commands/PublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Orchid\Platform\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:publish')]
class PublishCommand extends Command
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Platform/Commands/RowsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Illuminate\Console\GeneratorCommand;
use Orchid\Platform\Dashboard;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:rows')]
class RowsCommand extends GeneratorCommand
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Platform/Commands/ScreenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Illuminate\Console\GeneratorCommand;
use Orchid\Platform\Dashboard;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:screen')]
class ScreenCommand extends GeneratorCommand
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Platform/Commands/SelectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Illuminate\Console\GeneratorCommand;
use Orchid\Platform\Dashboard;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:selection')]
class SelectionCommand extends GeneratorCommand
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Platform/Commands/TabMenuCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Illuminate\Console\GeneratorCommand;
use Orchid\Platform\Dashboard;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:tab-menu')]
class TabMenuCommand extends GeneratorCommand
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Platform/Commands/TableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Illuminate\Console\GeneratorCommand;
use Orchid\Platform\Dashboard;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'orchid:table')]
class TableCommand extends GeneratorCommand
{
/**
Expand Down

0 comments on commit 4d730e2

Please sign in to comment.