Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Move debug output information into verbose level #1

Merged
merged 3 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# Spiral Application installer

[App Skeleton](https://github.com/spiral/app) | [**Documentation**](https://spiral.dev/docs) | [Discord](https://discord.gg/TFeEmCs) | [Twitter](https://twitter.com/spiralphp) | [Contributing](https://spiral.dev/docs/about-contributing/)
[App Skeleton](https://github.com/spiral/app) | [**Documentation
**](https://spiral.dev/docs) | [Discord](https://discord.gg/TFeEmCs) | [Twitter](https://twitter.com/spiralphp) | [Contributing](https://spiral.dev/docs/about-contributing/)

![Installer](https://user-images.githubusercontent.com/773481/208850084-891a9d6f-3e70-4a06-af57-4e63c37c9c47.png)

Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components. The Framework execution model based on a hybrid runtime where some services (GRPC, Queue, WebSockets, etc.) handled by Application Server [RoadRunner](https://github.com/roadrunner-server/roadrunner) and the PHP code of your application stays in memory permanently (anti-memory leak tools included).
Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components.
The Framework execution model based on a hybrid runtime where some services (GRPC, Queue, WebSockets, etc.) handled by
Application Server [RoadRunner](https://github.com/roadrunner-server/roadrunner) and the PHP code of your application
stays in memory permanently (anti-memory leak tools included).

<br />

## Server Requirements

Make sure that your server is configured with following PHP version and extensions:

* PHP 8.1+, 64bit
* [mb-string](https://www.php.net/manual/en/intro.mbstring.php) extension
* PDO Extension with desired database drivers
Expand All @@ -21,7 +26,8 @@ Make sure that your server is configured with following PHP version and extensio
composer create-project spiral/installer my-app
```

> **Note**: Application server will be downloaded automatically (`php-curl` and `php-zip` required).
> **Note**:
> Application server will be downloaded automatically (`php-curl` and `php-zip` required).

<br />

Expand All @@ -35,10 +41,13 @@ cd my-app

<br />

Once you have started RoadRunner server, your application will be accessible in your web browser at `http://localhost:8080`.
Once you have started RoadRunner server, your application will be accessible in your web browser
at `http://localhost:8080`.

> **Note**: Read more about application server configuration [here](https://roadrunner.dev/docs).
> **Note**:
> Read more about application server configuration [here](https://roadrunner.dev/docs).

## License:

MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained by [Spiral Scout](https://spiralscout.com).
MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained
by [Spiral Scout](https://spiralscout.com).
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"require": {
"php": ">=8.1",
"spiral/roadrunner-cli": "^2.4",
"spiral/framework": "^3.2"
"spiral/framework": "^3.3"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
Expand Down
4 changes: 2 additions & 2 deletions installer/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function showInstructions(): void

// from application
foreach ($this->application->getInstructions() as $index => $instruction) {
$this->io->write(\sprintf(' %s. %s', (int) $index + 1, $instruction));
$this->io->write(\sprintf(' %s. %s', (int)$index + 1, $instruction));
}

$showPackageInstruction = function (Package $package): void {
Expand All @@ -122,7 +122,7 @@ private function showInstructions(): void
}

foreach ($package->getInstructions() as $index => $instruction) {
$this->io->write(\sprintf(' %s. %s', (int) $index + 1, $instruction));
$this->io->write(\sprintf(' %s. %s', (int)$index + 1, $instruction));
}
};

Expand Down
8 changes: 4 additions & 4 deletions installer/Generator/BootloaderGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function append(string $bootloader, string $afterBootloader): void
foreach ($this->bootloaders as $pos => $value) {
if ($afterBootloader === $value) {
$this->bootloaders = \array_merge(
\array_slice($this->bootloaders, 0, (int) $pos + 1),
\array_slice($this->bootloaders, 0, (int)$pos + 1),
[$bootloader],
\array_slice($this->bootloaders, (int) $pos + 1)
\array_slice($this->bootloaders, (int)$pos + 1)
);
break;
}
Expand All @@ -52,9 +52,9 @@ public function prepend(string $bootloader, string $beforeBootloader): void
foreach ($this->bootloaders as $pos => $value) {
if ($beforeBootloader === $value) {
$this->bootloaders = \array_merge(
\array_slice($this->bootloaders, 0, (int) $pos),
\array_slice($this->bootloaders, 0, (int)$pos),
[$bootloader],
\array_slice($this->bootloaders, (int) $pos)
\array_slice($this->bootloaders, (int)$pos)
);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions installer/Generator/Bootloaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public function updateDeclaration(ClassDeclaration $class, PhpNamespace $namespa
{
\uasort(
$this->groups,
static fn (BootloaderGroup $a, BootloaderGroup $b) => $a->priority <=> $b->priority
static fn(BootloaderGroup $a, BootloaderGroup $b) => $a->priority <=> $b->priority
);

$groups = \array_map(
static fn (BootloaderGroup $group) => $group->render($namespace),
static fn(BootloaderGroup $group) => $group->render($namespace),
\array_values($this->groups)
);

Expand Down
4 changes: 2 additions & 2 deletions installer/Generator/EnvConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public function __construct(

public function __destruct()
{
\uasort($this->groups, static fn (EnvGroup $a, EnvGroup $b) => $a->priority <=> $b->priority);
\uasort($this->groups, static fn(EnvGroup $a, EnvGroup $b) => $a->priority <=> $b->priority);

$groups = \array_map(
static fn (EnvGroup $group) => $group->render(),
static fn(EnvGroup $group) => $group->render(),
\array_values($this->groups)
);

Expand Down
48 changes: 31 additions & 17 deletions installer/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ final class Installer extends AbstractInstaller
/** @var array<string, BasePackage::STABILITY_*> */
private array $stabilityFlags = [];

private readonly bool $verbose;

/**
* @throws ParsingException
*/
Expand All @@ -54,16 +56,16 @@ public static function install(Event $event): void
{
$installer = new self($event->getIO(), $event->getComposer());

$installer->io->write('<info>Setting up application preset</info>');
$installer->writeInfo('<info>Setting up application preset</info>');
$installer->setApplicationType($installer->requestApplicationType());

$installer->io->write('<info>Setting up required packages</info>');
$installer->writeInfo('<info>Setting up required packages</info>');
$installer->setRequiredPackages();

$installer->io->write('<info>Setting up optional packages</info>');
$installer->writeInfo('<info>Setting up optional packages</info>');
$installer->promptForOptionalPackages();

$installer->io->write('<info>Setting up application files</info>');
$installer->writeInfo('<info>Setting up application files</info>');
$installer->setApplicationFiles();

$installer->removeInstallerFromDefinition();
Expand Down Expand Up @@ -130,12 +132,12 @@ private function requestApplicationType(): int
];
foreach ($this->config as $key => $app) {
if ($app instanceof ApplicationInterface) {
$query[] = \sprintf(" [<comment>%s</comment>] %s\n", (int) $key + 1, $app->getName());
$query[] = \sprintf(" [<comment>%s</comment>] %s\n", (int)$key + 1, $app->getName());
}
}
$query[] = \sprintf(' Make your selection <comment>(%s)</comment>: ', 1);

return (int) $this->io->ask(\implode($query), 1) - 1;
return (int)$this->io->ask(\implode($query), 1) - 1;
}

private function setApplicationType(int $type): void
Expand All @@ -152,31 +154,33 @@ private function setApplicationType(int $type): void

private function askQuestion(QuestionInterface $question): int
{
$answer = $this->io->ask($question->getQuestion(), (string) $question->getDefault());
$answer = $this->io->ask($question->getQuestion(), (string)$question->getDefault());

// Handling "y", "Y", "n", "N"
if (\strtolower((string) $answer) === 'n') {
if (\strtolower((string)$answer) === 'n') {
$answer = 0;
}
if (\strtolower((string) $answer) === 'y' && count($question->getOptions()) === 2) {
if (\strtolower((string)$answer) === 'y' && count($question->getOptions()) === 2) {
$answer = 1;
}

if (!$question->hasOption((int) $answer)) {
if (!$question->hasOption((int)$answer)) {
$this->io->write('<error>Invalid answer</error>');
exit;
}

return (int) $answer;
return (int)$answer;
}

private function addPackage(Package $package): void
{
$this->io->write(\sprintf(
' - Adding package <info>%s</info> (<comment>%s</comment>)',
$package->getName(),
$package->getVersion()
));
$this->writeInfo(
\sprintf(
' - Adding package <info>%s</info> (<comment>%s</comment>)',
$package->getName(),
$package->getVersion()
)
);

$versionParser = new VersionParser();
$constraint = $versionParser->parseConstraints($package->getVersion());
Expand Down Expand Up @@ -209,6 +213,7 @@ private function addPackage(Package $package): void
'RC' => BasePackage::STABILITY_RC,
default => null
};

if ($stability !== null) {
$this->stabilityFlags[$package->getName()] = $stability;
}
Expand Down Expand Up @@ -239,7 +244,7 @@ private function updateRootPackage(): void

private function removeInstallerFromDefinition(): void
{
$this->io->write('<info>Remove Installer from composer.json</info>');
$this->writeInfo('<info>Remove Installer from composer.json</info>');

unset(
$this->composerDevRequires['composer/composer'],
Expand All @@ -265,4 +270,13 @@ private function addBooleanAnswer(QuestionInterface $question, BooleanOption $an
$this->composerDefinition['extra']['spiral']['options'][$question::class] = $answer->value;
}
}

private function writeInfo(string $message): void
{
if (!$this->io->isVerbose()) {
return;
}

$this->io->write($message);
}
}
6 changes: 4 additions & 2 deletions installer/Question/AbstractQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ private function setOptions(array $options): void
if ($option instanceof Option && $option->getPackages() === []) {
$this->options[0] = $option;
} else {
$this->options[(int) $key + 1] = $option;
$this->options[(int)$key + 1] = $option;
}
}

if ($this->required !== true && !isset($this->options[0])) {
$this->options[self::NONE_OPTION] = new Option(name: \count($this->options) === 1 ? 'No' : 'None of the above');
$this->options[self::NONE_OPTION] = new Option(
name: \count($this->options) === 1 ? 'No' : 'None of the above'
);
}
}

Expand Down
4 changes: 4 additions & 0 deletions installer/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public function getSource(): string

private function writeInfo(string $destination): void
{
if (!$this->io?->isVerbose()) {
return;
}

$this->io?->write(\sprintf(' - Copying <info>%s</info>', $destination));
}
}
4 changes: 2 additions & 2 deletions installer/Resources/applications/custom/psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="app/src" />
<directory name="app/src"/>
<ignoreFiles>
<directory name="vendor" />
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
</psalm>
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public function testJobPushed(): void
{
$this->connection->push(Ping::class, ['value' => 'hello world']);

$this->connection->assertPushed(Ping::class, fn (array $data) =>
$data['handler'] instanceof Ping && $data['payload']['value'] === 'hello world'
$this->connection->assertPushed(
Ping::class,
fn(array $data) => $data['handler'] instanceof Ping && $data['payload']['value'] === 'hello world'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function fetchLocales(ServerRequestInterface $request): \Generator
$header = $request->getHeaderLine('accept-language');
foreach (\explode(',', $header) as $value) {
$pos = \strpos($value, ';');
if ($pos!== false) {
if ($pos !== false) {
yield \substr($value, 0, $pos);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function dumprr(mixed $value, mixed ...$values): mixed
$cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);

// Set new handler and store previous one
$prevent = VarDumper::setHandler(static fn ($value) => $dumper->dump($cloner->cloneVar($value)));
$prevent = VarDumper::setHandler(static fn($value) => $dumper->dump($cloner->cloneVar($value)));
$result = VarDumper::dump($value);

foreach ($values as $v) {
Expand Down
Loading