Skip to content

Commit

Permalink
🎮
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Apr 5, 2024
1 parent de1e737 commit 7c02abd
Show file tree
Hide file tree
Showing 138 changed files with 59 additions and 5,428 deletions.
34 changes: 13 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
# The PHP framework that gets out of your way.
[![Coverage Status](https://coveralls.io/repos/github/tempestphp/tempest-framework/badge.svg?branch=main)](https://coveralls.io/github/tempestphp/tempest-framework?branch=main)
# tempest/console

Read how to get started with Tempest [here](https://github.com/tempestphp/tempest-docs/blob/main/app/Content/01-getting-started.md).
```php
composer require tempest/console
```

Zero config, zero overhead. This is Tempest:
Getting started:

```php
final readonly class BookController
{
#[Get('/blog')]
public function index() { /* … */ }

#[Get('/blog/{post}')]
public function show(Post $post) { /* … */ }
}
#!/usr/bin/env php
<?php

final readonly class RssSyncCommand
{
public function __construct(private Console $console) {}
use Tempest\Console\ConsoleApplication;

#[ConsoleCommand('rss:sync')]
public function __invoke(bool $force = false) { /* … */ }
}
```
require_once getcwd() . '/vendor/autoload.php';

ConsoleApplication::boot('My Console')->run();

# Contributing
We welcome contributing to the Tempest framework! We only ask that you take a quick look at our [guidelines](.github/CONTRIBUTING.md) and then head on over to the issues page to see some ways you might help out!
exit;
```
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "tempest/framework",
"name": "tempest/console",
"description": "The PHP framework that gets out of your way.",
"require": {
"php": "^8.3",
Expand Down Expand Up @@ -44,7 +44,6 @@
"csfixer": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"phpstan": "vendor/bin/phpstan analyse src tests app",
"qa": [
"./tempest discovery:clear",
"composer csfixer",
"composer phpstan",
"composer phpunit"
Expand Down
7 changes: 1 addition & 6 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ includes:
- phpstan-baseline.php
- vendor/phpat/phpat/extension.neon
- vendor/spaze/phpstan-disallowed-calls/extension.neon
services:
-
class: Tests\Tempest\Architecture\ArchitectureTest
tags:
- phpat.test
parameters:
level: 6
level: 4
reportUnmatchedIgnoredErrors: false
paths:
- app
Expand Down
4 changes: 0 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
Expand Down
1 change: 1 addition & 0 deletions src/Actions/RenderConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __invoke(ConsoleCommand $consoleCommand): string

private function renderParameter(ReflectionParameter $parameter): string
{
/** @phpstan-ignore-next-line */
$type = $parameter->getType()?->getName();
$optional = $parameter->isOptional();
$defaultValue = strtolower(var_export($optional ? $parameter->getDefaultValue() : null, true));
Expand Down
8 changes: 4 additions & 4 deletions src/Actions/RenderConsoleCommandOverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

namespace Tempest\Console\Actions;

use Tempest\AppConfig;
use Tempest\Console\ConsoleConfig;
use Tempest\Console\ConsoleStyle;
use Tempest\CoreConfig;

final readonly class RenderConsoleCommandOverview
{
public function __construct(
private CoreConfig $coreConfig,
private AppConfig $appConfig,
private ConsoleConfig $consoleConfig,
) {
}

public function __invoke(): string
{
$lines = [
ConsoleStyle::BOLD(ConsoleStyle::BG_DARK_BLUE(" Tempest Console ")),
ConsoleStyle::BOLD(ConsoleStyle::BG_DARK_BLUE(" {$this->consoleConfig->name} ")),
];

if ($this->coreConfig->discoveryCache) {
if ($this->appConfig->discoveryCache) {
$lines[] = ConsoleStyle::BG_RED(' Discovery cache is enabled! ');
}

Expand Down
7 changes: 7 additions & 0 deletions src/Config/console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

use Tempest\Console\ConsoleConfig;

return new ConsoleConfig();
25 changes: 15 additions & 10 deletions src/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,49 @@

use ArgumentCountError;
use ReflectionMethod;
use Tempest\AppConfig;
use Tempest\Application;
use Tempest\Console\Actions\RenderConsoleCommandOverview;
use Tempest\Console\Exceptions\CommandNotFound;
use Tempest\Console\Exceptions\ConsoleExceptionHandler;
use Tempest\Container\Container;
use Tempest\CoreConfig;
use Tempest\Kernel;
use Throwable;

final readonly class ConsoleApplication implements Application
{
public static function boot(string $root): self
{
$coreConfig = new CoreConfig($root);
public static function boot(
string $name = 'Tempest',
?AppConfig $appConfig = null,
): self {
$appConfig ??= new AppConfig(root: getcwd());

$kernel = new Kernel(
coreConfig: $coreConfig,
appConfig: $appConfig,
);

$container = $kernel->init();

$application = new self(
args: $_SERVER['argv'],
container: $container,
coreConfig: $coreConfig,
appConfig: $appConfig,
);

$container->singleton(Application::class, fn () => $application);

$coreConfig->exceptionHandlers[] = $container->get(ConsoleExceptionHandler::class);
$appConfig->exceptionHandlers[] = $container->get(ConsoleExceptionHandler::class);

$consoleConfig = $container->get(ConsoleConfig::class);
$consoleConfig->name = $name;

return $application;
}

public function __construct(
private array $args,
private Container $container,
private CoreConfig $coreConfig,
private AppConfig $appConfig,
) {
}

Expand All @@ -62,11 +67,11 @@ public function run(): void

$this->handleCommand($commandName);
} catch (Throwable $throwable) {
if (! $this->coreConfig->enableExceptionHandling) {
if (! $this->appConfig->enableExceptionHandling) {
throw $throwable;
}

foreach ($this->coreConfig->exceptionHandlers as $exceptionHandler) {
foreach ($this->appConfig->exceptionHandlers as $exceptionHandler) {
$exceptionHandler->handle($throwable);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/ConsoleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
final class ConsoleConfig
{
public function __construct(
public string $name = 'Tempest',

/** @var \Tempest\Console\ConsoleCommand[] $commands */
public array $commands = [],
) {
Expand Down
10 changes: 0 additions & 10 deletions src/Exceptions/ConsoleExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ public function handle(Throwable $throwable): void
}
}

private function outputPath(array $line): void
{
if (! isset($line['file'])) {
return;
}

$this->console->write($line['file'] . ':' . $line['line']);
$this->console->writeln('');
}

private function outputLine(array $line): void
{
$this->console->write(' - ');
Expand Down
8 changes: 4 additions & 4 deletions src/Testing/Console/ConsoleCommandTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Tempest\Console\Testing\Console;

use Tempest\AppConfig;
use Tempest\Console\ConsoleApplication;
use Tempest\Console\ConsoleOutput;
use Tempest\Console\Exceptions\ConsoleExceptionHandler;
use Tempest\Container\Container;
use Tempest\CoreConfig;

final readonly class ConsoleCommandTester
{
Expand All @@ -22,14 +22,14 @@ public function __construct(private Container $container)

public function call(string $command): TestConsoleHelper
{
$coreConfig = $this->container->get(CoreConfig::class);
$appConfig = $this->container->get(AppConfig::class);

$coreConfig->exceptionHandlers[] = $this->container->get(ConsoleExceptionHandler::class);
$appConfig->exceptionHandlers[] = $this->container->get(ConsoleExceptionHandler::class);

$application = new ConsoleApplication(
args: ['tempest', ...explode(' ', $command)],
container: $this->container,
coreConfig: $coreConfig,
appConfig: $appConfig,
);

$application->run();
Expand Down
12 changes: 11 additions & 1 deletion tempest
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
<?php

use Tempest\Console\ConsoleApplication;
use Tempest\AppConfig;
use Tempest\Discovery\DiscoveryLocation;

require_once getcwd() . '/vendor/autoload.php';

ConsoleApplication::boot(getcwd())->run();
ConsoleApplication::boot(
'Tempest Console',
new AppConfig(
getcwd(),
discoveryLocations: [
new DiscoveryLocation('App\\', __DIR__ . '/app/')
],
),
)->run();

exit;
64 changes: 0 additions & 64 deletions tests/Architecture/ArchitectureTest.php

This file was deleted.

Loading

0 comments on commit 7c02abd

Please sign in to comment.