Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
refactor: remove handle return
Browse files Browse the repository at this point in the history
  • Loading branch information
Muetze42 committed Oct 16, 2023
1 parent cafecd5 commit c83e1c8
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 63 deletions.
3 changes: 0 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
* text=auto

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

Expand Down
8 changes: 0 additions & 8 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# These are supported funding model platforms

github: [Muetze42]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: normanhuth
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: ['https://huth.it/coffee']
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ lura cache:clear

Use this template: [lura-installer-template](https://github.com/Muetze42/lura-installer-template)

### Upgrade 1 to 2

Remove the `int` return of the `runLura` method.

---

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://vshymanskyy.github.io/StandWithUkraine/)

Expand Down
4 changes: 2 additions & 2 deletions _ide_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11899,9 +11899,9 @@ public static function installerAuthor(): string
return 'Lura';
}

public function runLura(mixed $command): int
public function runLura(mixed $command)
{
return 0;
//
}
}
}
7 changes: 4 additions & 3 deletions bin/lura
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env php
<?php

$autoloader = file_exists(__DIR__.'/../../../autoload.php') ? __DIR__.'/../../../autoload.php' : __DIR__.'/../vendor/autoload.php';
$autoloader = file_exists(__DIR__ . '/../../../autoload.php') ?
__DIR__ . '/../../../autoload.php' : __DIR__ . '/../vendor/autoload.php';

require $autoloader;

use NormanHuth\ConsoleApp\App;

try {
new App('Lura by Norman Huth', 1, 'install');
new App('Lura by Norman Huth', 2, 'install');
} catch (Exception $exception) {
die('Error: '.$exception);
die('Error: ' . $exception);
}
2 changes: 1 addition & 1 deletion config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'disks' => [
'app' => [
'driver' => 'local',
'root' => dirname(__DIR__).'/app',
'root' => dirname(__DIR__) . '/app',
],
],
],
Expand Down
17 changes: 10 additions & 7 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class App

/**
* @param int|string|null $version
*
* @throws Exception
*/
public function __construct(string $appName = 'Console App', int|string $version = null, string $defaultCommand = null)
Expand All @@ -46,7 +47,7 @@ public function __construct(string $appName = 'Console App', int|string $version

$this->artisan->setName($appName);

$this->resolveCommands('Console'.DIRECTORY_SEPARATOR.'Commands');
$this->resolveCommands('Console' . DIRECTORY_SEPARATOR . 'Commands');

$this->artisan->run();
}
Expand All @@ -55,39 +56,41 @@ public function __construct(string $appName = 'Console App', int|string $version
* Get Version from the composer.json file or set default to 1
*
* @param int|string|null $version
*
* @return string
*/
protected function setVersion(int|string|null $version): string
{
if (!$version) {
$content = file_get_contents(__DIR__.'/../composer.json');
$content = file_get_contents(__DIR__ . '/../composer.json');
$data = json_decode($content, true);

$version = data_get($data, 'version', 1);
}

return (string)$version;
return (string) $version;
}

/**
* Register all the commands in the given directory.
*
* @param string $path
*
* @return void
*/
protected function resolveCommands(string $path): void
{
$path = trim($path, '/\\');
$items = glob(__DIR__.DIRECTORY_SEPARATOR.$path.'/*.php');
$items = glob(__DIR__ . DIRECTORY_SEPARATOR . $path . '/*.php');
foreach ($items as $item) {
$class = __NAMESPACE__.'\\'.$path.'\\'.pathinfo($item, PATHINFO_FILENAME);
$class = __NAMESPACE__ . '\\' . $path . '\\' . pathinfo($item, PATHINFO_FILENAME);
$class = str_replace('/', '\\', $class);
$this->artisan->resolve($class);
}

$directories = glob(__DIR__.DIRECTORY_SEPARATOR.$path.'/*', GLOB_ONLYDIR);
$directories = glob(__DIR__ . DIRECTORY_SEPARATOR . $path . '/*', GLOB_ONLYDIR);
foreach ($directories as $directory) {
$this->resolveCommands($path.DIRECTORY_SEPARATOR.basename($directory));
$this->resolveCommands($path . DIRECTORY_SEPARATOR . basename($directory));
}
}
}
7 changes: 1 addition & 6 deletions src/Console/Commands/CacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace NormanHuth\ConsoleApp\Console\Commands;

use NormanHuth\ConsoleApp\LuraCommand;
use Symfony\Component\Console\Command\Command as SymfonyCommand;

class CacheClearCommand extends LuraCommand
{
Expand All @@ -23,15 +22,11 @@ class CacheClearCommand extends LuraCommand

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
public function handle()
{
$this->cache->getStore()->flush();

$this->info('Application cache cleared successfully.');

return SymfonyCommand::SUCCESS;
}
}
7 changes: 1 addition & 6 deletions src/Console/Commands/ConfigFileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace NormanHuth\ConsoleApp\Console\Commands;

use NormanHuth\ConsoleApp\LuraCommand;
use Symfony\Component\Console\Command\Command as SymfonyCommand;

class ConfigFileCommand extends LuraCommand
{
Expand All @@ -23,14 +22,10 @@ class ConfigFileCommand extends LuraCommand

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
public function handle()
{
$this->info('Local Lura config file:');
$this->line($this->userConfigFile);

return SymfonyCommand::SUCCESS;
}
}
17 changes: 9 additions & 8 deletions src/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function handle()
$repositories = data_get($this->config, 'repositories', []);

foreach ($repositories as $repository) {
$classFile = $this->composerHome.'/vendor/'.$repository.'/Lura/Installer.php';
$composerFile = $this->composerHome.'/vendor/'.$repository.'/composer.json';
$classFile = $this->composerHome . '/vendor/' . $repository . '/Lura/Installer.php';
$composerFile = $this->composerHome . '/vendor/' . $repository . '/composer.json';
if (file_exists($classFile)) {
$content = file_get_contents($composerFile);
$data = json_decode($content, true);
Expand All @@ -49,19 +49,20 @@ public function handle()
return;
}

$installer = count($this->installers) == 1 ? 0 : $this->choice('Which installer do you want to use?', $this->installers);
$installer = count($this->installers) == 1 ? 0 :
$this->choice('Which installer do you want to use?', $this->installers);

if (!$installer) {
$installer = $this->installers[0];
}

$repositoryConfigFile = $this->composerHome.'/vendor/'.$installer.'/config/lura-config.json';
$repositoryConfigFile = $this->composerHome . '/vendor/' . $installer . '/config/lura-config.json';

$this->installerConfig = data_get($this->config, 'repositories-config.'.$installer, []);
$this->alert('Starting '.$installer);
$this->installerConfig = data_get($this->config, 'repositories-config.' . $installer, []);
$this->alert('Starting ' . $installer);

require_once $this->composerHome.'/vendor/'.$installer.'/Lura/Installer.php';
require_once $this->composerHome . '/vendor/' . $installer . '/Lura/Installer.php';

(new \Installer)->runLura($this);
(new \Installer())->runLura($this);
}
}
30 changes: 13 additions & 17 deletions src/Console/Commands/RegisterInstallerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace NormanHuth\ConsoleApp\Console\Commands;

use Illuminate\Support\Str;
use NormanHuth\ConsoleApp\LuraCommand;
use Symfony\Component\Console\Command\Command as SymfonyCommand;

class RegisterInstallerCommand extends LuraCommand
{
Expand All @@ -23,19 +23,17 @@ class RegisterInstallerCommand extends LuraCommand

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
public function handle()
{
$repository = $this->argument('repository');

$composerJson = $this->composerHome.'/composer.json';
$composerJson = $this->composerHome . '/composer.json';

if (!file_exists($composerJson)) {
$this->error('Composer home composer.json not found.');

return SymfonyCommand::FAILURE;
return;
}

$content = json_decode(file_get_contents($composerJson), true);
Expand All @@ -48,43 +46,41 @@ public function handle(): int
});

if (!in_array($repository, $repositories)) {
$this->error('The package '.$repository.' is not installed.');
$this->error('The package ' . $repository . ' is not installed.');

return SymfonyCommand::FAILURE;
return;
}

if (!is_dir($this->composerHome.'/vendor/'.$repository)) {
$this->error('The package '.$repository.' directory is missing.');
if (!is_dir($this->composerHome . '/vendor/' . $repository)) {
$this->error('The package ' . $repository . ' directory is missing.');

return SymfonyCommand::FAILURE;
return;
}

$configRepositories = data_get($this->config, 'repositories', []);
$configRepositories[] = $repository;
$configRepositories = array_unique($configRepositories);
data_set($this->config, 'repositories', $configRepositories);

$repositoryConfigFile = $this->composerHome.'/vendor/'.$repository.'/config/lura-config.json';
$repositoryConfigFile = $this->composerHome . '/vendor/' . $repository . '/config/lura-config.json';
if (file_exists($repositoryConfigFile)) {
$content = file_get_contents($repositoryConfigFile);
if (isJson($content)) {
if (Str::isJson($content)) {
$repositoryConfig = json_decode($content, true);
}
}

if (!empty($repositoryConfig)) {
$userItems = data_get($this->config, 'repositories-config.'.$repository, []);
$userItems = data_get($this->config, 'repositories-config.' . $repository, []);
foreach ($userItems as $key => $value) {
$repositoryConfig[$key] = $value;
}

data_set($this->config, 'repositories-config.'.$repository, $repositoryConfig);
data_set($this->config, 'repositories-config.' . $repository, $repositoryConfig);
}

$this->setUserConfig($this->config);

$this->info('Installer added!');

return SymfonyCommand::SUCCESS;
}
}
27 changes: 27 additions & 0 deletions src/LuraCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,41 @@ class LuraCommand extends Command
*/
public array $installerConfig;

/**
* @var \Illuminate\Filesystem\FilesystemManager
*/
public FilesystemManager $filesystemManager;
/**
* @var \Illuminate\Contracts\Filesystem\Filesystem
*/
public Filesystem $cwdDisk;
/**
* @var string
*/
public string $composer;
/**
* @var string
*/
public string $composerHome;
/**
* @var \Illuminate\Contracts\Cache\Repository
*/
public CacheRepository $cache;
/**
* @var array
*/
public array $config;
/**
* @var string
*/
public string $userConfigFile;
/**
* @var string
*/
public string $tempPath = '';
/**
* @var \Illuminate\Filesystem\Filesystem
*/
public \Illuminate\Filesystem\Filesystem $filesystem;

/**
Expand Down
3 changes: 1 addition & 2 deletions src/LuraInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ abstract class LuraInstaller
* Execute the installer console command.
*
* @param mixed|\NormanHuth\ConsoleApp\LuraCommand $command
* @return int
*/
abstract public function runLura(mixed $command): int;
abstract public function runLura(mixed $command);
}

0 comments on commit c83e1c8

Please sign in to comment.