Skip to content
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
22 changes: 9 additions & 13 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: PHP package checks

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:
Expand All @@ -17,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.5']
php: ['8.4.1', '8.5']
steps:
- name: Checkout
uses: actions/checkout@v7
Expand All @@ -32,19 +31,16 @@ jobs:
coverage: none

- name: Validate Composer manifest and lock
run: composer validate --no-check-publish --no-interaction
run: composer validate --strict --no-check-publish --no-interaction

- name: Install locked dependencies
run: composer install --prefer-dist --no-interaction --no-progress --no-scripts

- name: Audit locked dependencies
run: composer audit --locked --no-interaction

- name: Check PHP syntax
run: find . -path './vendor' -prune -o -path './.git' -prune -o -name '*.php' -type f -print0 | xargs -0 -n1 php -l

- name: Run declared tests
shell: bash
run: |
if php -r '$composer = json_decode(file_get_contents("composer.json"), true); exit(isset($composer["scripts"]["test"]) ? 0 : 1);'; then
composer test --no-interaction
else
echo 'No test script is declared for this package.'
fi
run: composer lint

- name: Run tests
run: composer test --no-interaction
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

---

## [Unreleased]
## [2.0.0] - Unreleased

### Planned
- Additional built-in commands
- Command scheduling improvements
- Interactive commands
### Breaking
- Require PHP 8.4.1+, Triangle Engine 9, Localzet Console 2.2, and Symfony Console/Process 8.1.
- Migrate command discovery to the Engine 9 plugin APIs and support Localzet Console 2's Illuminate command bridge.

### Added
- Compatibility checks for Engine 9 command discovery and Symfony/Illuminate command execution.
- English and Russian installation, usage, command, and upgrade guides.

18 changes: 11 additions & 7 deletions Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/Console
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2024 Triangle Framework Team
* @copyright Copyright © 2016-2026 Localzet Group. All rights reserved.
* SPDX-License-Identifier: AGPL-3.0-or-later
* @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -68,11 +69,18 @@ public function __construct(protected array $config = [], bool $installInternalC
'phar_stub' => 'master',
'signature_algorithm' => Phar::SHA256,
'private_key_file' => '',
'php_version' => 8.3,
'php_version' => 8.4,
'php_ini' => 'memory_limit = 256M',
'bin_filename' => 'triangle',
]]);
}

$this->config['name'] = 'Triangle Console';
$this->config['version'] = InstalledVersions::getPrettyVersion('triangle/console');

parent::__construct($this->config, $installInternalCommands);

if (Config::isLoaded()) {
$this->loadFromConfig(config('command', []));

// Грузим команды из /app/command/*.php
Expand All @@ -98,10 +106,6 @@ public function __construct(protected array $config = [], bool $installInternalC
$this->loadFromConfig($config['command'] ?? []);
});
}
$this->config['name'] = 'Triangle Console';
$this->config['version'] = InstalledVersions::getPrettyVersion('triangle/console');

parent::__construct($this->config, $installInternalCommands);
}

/**
Expand Down Expand Up @@ -134,7 +138,7 @@ protected function loadFromConfig(array $config): void
$name = $properties['defaultName'] ?? null;
if (!$name) throw new RuntimeException("У команды $class_name нет defaultName");

$this->add(new $class_name(config('console', [])));
$this->addCommand(new $class_name(config('console', [])));
}
}

Expand Down
141 changes: 120 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,120 @@
<p align="center"><a href="https://www.localzet.com" target="_blank">
<img src="https://static.zorin.space/media/logos/LocalzetGroup.png" width="400">
</a></p>

<p align="center">
<a href="https://packagist.org/packages/triangle/console">
<img src="https://img.shields.io/packagist/dt/triangle/console?label=%D0%A1%D0%BA%D0%B0%D1%87%D0%B8%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F" alt="Скачивания">
</a>
<a href="https://github.com/Triangle-org/Console">
<img src="https://img.shields.io/github/commit-activity/t/Triangle-org/Console?label=%D0%9A%D0%BE%D0%BC%D0%BC%D0%B8%D1%82%D1%8B" alt="Коммиты">
</a>
<a href="https://packagist.org/packages/triangle/console">
<img src="https://img.shields.io/packagist/v/triangle/console?label=%D0%92%D0%B5%D1%80%D1%81%D0%B8%D1%8F" alt="Версия">
</a>
<a href="https://packagist.org/packages/triangle/console">
<img src="https://img.shields.io/packagist/dependency-v/triangle/console/php?label=PHP" alt="Версия PHP">
</a>
<a href="https://github.com/Triangle-org/Console">
<img src="https://img.shields.io/github/license/Triangle-org/Console?label=%D0%9B%D0%B8%D1%86%D0%B5%D0%BD%D0%B7%D0%B8%D1%8F" alt="Лицензия">
</a>
</p>
# Triangle Console

Triangle Console adds Triangle Engine integration and project commands to [Localzet Console](https://github.com/localzet/Console). It loads commands from the application and enabled plugins, and includes helpers for creating applications, plugins, commands, controllers, middleware and models. It also provides PHAR and self-contained binary build commands.

> This compatibility line requires PHP 8.4.1 or newer, Triangle Engine 9, and Localzet Console 2.2. It is not compatible with the Engine 8 / Localzet Console 1 dependency line.

## Install

```sh
composer require triangle/console:^2.0
```

The package uses the Triangle Engine runtime. Install it in a Triangle application, then register `Triangle\Console\Console` as the command application:

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Triangle\Console\Console;

(new Console())->run();
```

When Engine configuration has been loaded, the component reads `config/command.php`, discovers application commands under `app/command`, and reads command entries from enabled plugin configuration. A command listed in `config/command.php` must expose a Symfony-compatible `defaultName`:

```php
<?php

return [
App\Command\HealthCommand::class,
];
```

Commands extend `localzet\Console\Commands\Command` and use Symfony Console input/output contracts:

```php
<?php

namespace App\Command;

use localzet\Console\Commands\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class HealthCommand extends Command
{
protected static string $defaultName = 'app:health';
protected static string $defaultDescription = 'Check application health';

protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('OK');

return self::SUCCESS;
}
}
```

## Laravel Console commands

Localzet Console 2.2 supports Illuminate Console commands. Triangle Console exposes that integration through the inherited `useIlluminate()` and `addIlluminateCommand()` methods:

```php
use Illuminate\Container\Container;
use Triangle\Console\Console;

$console = (new Console([], false))->useIlluminate(new Container());
$console->addIlluminateCommand(new App\Console\Commands\ReportCommand());
$console->run();
```

Pass a Laravel application/container configured for your command dependencies when required. `false` disables automatic internal commands for this explicitly composed console instance.

## Built-in commands

The component registers its commands along with Localzet Console's internal commands. Common Triangle commands include:

| Command | Purpose |
| --- | --- |
| `make:command <name>` | Generate an application command |
| `make:controller <name>` | Generate a controller |
| `make:middleware <name>` | Generate middleware |
| `make:model <name>` | Generate a model |
| `app:create <name>` | Create an application scaffold |
| `plugin:create <name>` | Create a plugin scaffold |
| `build:phar` | Package the configured project as a PHAR |
| `build:bin [php-version]` | Package the project with the configured PHP micro runtime |

Run `php your-entrypoint.php list` to see the commands available in the current application. Build commands use settings from `config/console.php`; the binary PHP version is a major/minor value such as `8.4`. Binary packaging does not make PHP source impossible to extract or reverse engineer; protect secrets outside the package and review the license terms for distributed artifacts.

## Compatibility and upgrade

This release line targets PHP `^8.4.1`, Triangle Engine `^9.0`, Localzet Console `^2.2`, Symfony Console `^8.1`, and Symfony Process `^8.1`. Engine 9 plugin discovery and Localzet Console 2 command integration are exercised by the package test suite.

Projects on the previous dependency line must upgrade PHP and Engine together, then resolve the new locked dependencies:

```sh
composer require triangle/engine:^9 localzet/console:^2.2 triangle/console --with-all-dependencies
```

Review application commands and plugins after the Engine 9 migration. Do not combine this package line with Engine 8 or Localzet Console 1 in the same Composer dependency graph.

## Development

```sh
composer install
composer run check
composer audit --locked
```

`composer run check` runs PHP syntax validation and the compatibility smoke tests for Engine 9 command discovery, built-in command registration, Symfony command execution, and Illuminate command execution.

## License

AGPL-3.0-or-later. See [LICENSE](LICENSE).

---

Русская версия: [README.ru.md](README.ru.md).
120 changes: 120 additions & 0 deletions README.ru.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Triangle Console

Triangle Console связывает [Localzet Console](https://github.com/localzet/Console) с Triangle Engine и добавляет команды для работы с проектом. Компонент загружает команды приложения и включённых плагинов, создаёт заготовки приложений, плагинов, команд, контроллеров, middleware и моделей, а также собирает PHAR и автономные бинарные пакеты.

> Эта линия совместимости требует PHP 8.4.1 или новее, Triangle Engine 9 и Localzet Console 2.2. Она несовместима с зависимостями линии Engine 8 / Localzet Console 1.

## Установка

```sh
composer require triangle/console:^2.0
```

Компонент работает в приложении на Triangle Engine. Подключите автозагрузчик Composer и запустите `Triangle\Console\Console`:

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Triangle\Console\Console;

(new Console())->run();
```

Если конфигурация Engine уже загружена, компонент читает `config/command.php`, ищет команды приложения в `app/command` и команды включённых плагинов в их конфигурации. Команда из `config/command.php` должна объявлять имя, совместимое с Symfony Console:

```php
<?php

return [
App\Command\HealthCommand::class,
];
```

Команды наследуются от `localzet\Console\Commands\Command` и используют интерфейсы ввода и вывода Symfony Console:

```php
<?php

namespace App\Command;

use localzet\Console\Commands\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class HealthCommand extends Command
{
protected static string $defaultName = 'app:health';
protected static string $defaultDescription = 'Проверить состояние приложения';

protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('OK');

return self::SUCCESS;
}
}
```

## Команды Laravel Console

Localzet Console 2.2 поддерживает команды Illuminate Console. Triangle Console предоставляет унаследованные методы `useIlluminate()` и `addIlluminateCommand()`:

```php
use Illuminate\Container\Container;
use Triangle\Console\Console;

$console = (new Console([], false))->useIlluminate(new Container());
$console->addIlluminateCommand(new App\Console\Commands\ReportCommand());
$console->run();
```

Если командам нужны зависимости приложения, передайте настроенный Laravel container/application. Параметр `false` отключает автоматическую регистрацию встроенных команд в этой вручную собранной консоли.

## Встроенные команды

Компонент регистрирует свои команды вместе со встроенными командами Localzet Console. Основные команды Triangle:

| Команда | Назначение |
| --- | --- |
| `make:command <name>` | Создать команду приложения |
| `make:controller <name>` | Создать контроллер |
| `make:middleware <name>` | Создать middleware |
| `make:model <name>` | Создать модель |
| `app:create <name>` | Создать структуру приложения |
| `plugin:create <name>` | Создать структуру плагина |
| `build:phar` | Упаковать проект в PHAR |
| `build:bin [php-version]` | Упаковать проект вместе с PHP micro runtime |

Список команд текущего приложения можно посмотреть через `php <точка-входа> list`. Параметры сборки читаются из `config/console.php`; версия PHP для бинарной сборки задаётся значением major/minor, например `8.4`. Бинарная упаковка не исключает извлечение или анализ PHP-кода. Не храните секреты в пакете и заранее проверьте условия лицензии для распространяемых артефактов.

## Совместимость и обновление

Эта линия требует PHP `^8.4.1`, Triangle Engine `^9.0`, Localzet Console `^2.2`, Symfony Console `^8.1` и Symfony Process `^8.1`. Набор проверок компонента проверяет обнаружение команд через Engine 9 и регистрацию команд Localzet Console 2.

Для проекта на предыдущей линии обновите PHP и Engine, затем разрешите новые версии зависимостей:

```sh
composer require triangle/engine:^9 localzet/console:^2.2 triangle/console --with-all-dependencies
```

После перехода на Engine 9 проверьте команды приложения и плагины. Не смешивайте эту линию с Engine 8 или Localzet Console 1 в одном графе зависимостей Composer.

## Разработка

```sh
composer install
composer run check
composer audit --locked
```

`composer run check` проверяет синтаксис PHP и запускает smoke-тесты обнаружения команд Engine 9, регистрации встроенных команд, исполнения Symfony-команды и исполнения Illuminate-команды.

## Лицензия

AGPL-3.0-or-later. См. [LICENSE](LICENSE).

---

English version: [README.md](README.md).
Loading