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
10 changes: 7 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
fail-fast: false
matrix:
php: ['8.1', '8.5']
engine: ['8.1.11', '9.0.0']
steps:
- name: Checkout
uses: actions/checkout@v7
Expand All @@ -31,11 +32,14 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
coverage: none

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

- name: Install locked dependencies
run: composer install --prefer-dist --no-interaction --no-progress --no-scripts
- name: Resolve dependencies for Engine version
run: composer update --prefer-dist --no-interaction --no-progress --with=triangle/engine:${{ matrix.engine }}

- 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
Expand Down
27 changes: 6 additions & 21 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2025-01-XX - LTS Release
## [2.1.0] - Unreleased

### Added
- Initial LTS release
- Full documentation
- Template rendering system
- Multiple template engine support
- View caching
- View composers
- Layout system
- Blade template support
- Support Triangle Engine 9 while retaining compatibility with Engine 8.
- Add an Engine-backed integration check for view configuration and template rendering.

### Changed
- Improved template rendering performance
- Enhanced view caching

---

## [Unreleased]

### Planned
- Additional template engines
- View component system
- Improved caching strategy
### Fixed
- Include request-assigned variables in the default PHP renderer.
- Return and deduplicate post-render templates separately from pre-render templates.

32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,35 @@
<img src="https://img.shields.io/github/license/Triangle-org/View?label=%D0%9B%D0%B8%D1%86%D0%B5%D0%BD%D0%B7%D0%B8%D1%8F" alt="Лицензия">
</a>
</p>

# Triangle View

Triangle View provides a small adapter layer for rendering PHP templates and, when installed, Blade, Twig, or ThinkPHP templates.

## Compatibility

- PHP 8.1 or newer.
- Triangle Engine `^8.1` or `^9.0`.
- Engine 9 runs on Localzet Server 7; Engine 8 remains supported for existing applications.

Install the package with Composer:

```sh
composer require triangle/view:^2.1
```

The package's `Install` helper copies the default `view.php` configuration into the application's config directory when it does not already exist. The default handler is `raw`; set `VIEW_HANDLER` to `blade`, `twig`, or `think` to select an optional adapter. Install the corresponding template engine package separately.

By default, a template named `page` for the `dashboard` application is loaded from `app/dashboard/view/page.phtml`. The `view()` helper returns an Engine response and merges variables assigned to the current request with the variables passed to the helper; explicit helper variables take precedence.

The `raw` handler executes PHP templates and does not escape output automatically. Escape untrusted values in the template, for example with `htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')`.

Run the Engine compatibility and rendering integration check with:

```sh
composer test
```

For Russian documentation, see [README.ru.md](README.ru.md).

Copyright © 2016-2026 [Localzet Group](https://www.localzet.com/). All rights reserved.
31 changes: 31 additions & 0 deletions README.ru.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Triangle View

Triangle View предоставляет небольшой слой адаптеров для PHP-шаблонов и, при установленной зависимости, для Blade, Twig или ThinkPHP.

## Совместимость

- PHP 8.1 или новее.
- Triangle Engine `^8.1` или `^9.0`.
- Engine 9 работает на Localzet Server 7; поддержка Engine 8 сохранена для существующих приложений.

Установите пакет через Composer:

```sh
composer require triangle/view:^2.1
```

Класс `Install` копирует конфигурацию `view.php` в каталог конфигурации приложения, если файла там ещё нет. По умолчанию используется обработчик `raw`; переменная `VIEW_HANDLER` со значением `blade`, `twig` или `think` выбирает соответствующий необязательный адаптер. Установите пакет выбранного шаблонизатора отдельно.

По умолчанию шаблон `page` приложения `dashboard` загружается из `app/dashboard/view/page.phtml`. Помощник `view()` возвращает ответ Engine и объединяет переменные текущего запроса с параметрами вызова; явные параметры имеют приоритет.

Обработчик `raw` исполняет PHP-шаблоны и не экранирует вывод автоматически. Экранируйте недоверенные значения в шаблоне, например через `htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')`.

Запуск интеграционной проверки Engine и рендеринга:

```sh
composer test
```

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

Copyright © 2016-2026 [Localzet Group](https://www.localzet.com/). All rights reserved.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
"require-dev": {
"rector/rector": "*"
},
"scripts": {
"test": "php tests/engine_compatibility.php"
},
"require": {
"php": "^8.1",
"triangle/engine": "^8.1"
"triangle/engine": "^8.1 || ^9.0"
},
"suggest": {
"twig/twig": "For Twig render",
Expand Down
3 changes: 2 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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
6 changes: 4 additions & 2 deletions src/Config/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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 All @@ -31,7 +32,8 @@
* @link https://github.com/Triangle-org/View
*
* @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
3 changes: 2 additions & 1 deletion src/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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
9 changes: 5 additions & 4 deletions src/Render/AbstractRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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 @@ -115,7 +116,7 @@ public static function addPreRender(string $template, string $app = null, string
*/
public static function getPreRenders(): array
{
return array_unique(self::$preRender);
return array_values(array_unique(self::$preRender, SORT_REGULAR));
}

/**
Expand All @@ -138,6 +139,6 @@ public static function addPostRender(string $template, string $app = null, strin
*/
public static function getPostRenders(): array
{
return array_unique(self::$preRender);
return array_values(array_unique(self::$postRender, SORT_REGULAR));
}
}
}
3 changes: 2 additions & 1 deletion src/Render/Blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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
4 changes: 3 additions & 1 deletion src/Render/Raw.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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 @@ -51,6 +52,7 @@ class Raw extends AbstractRender implements RenderInterface
*/
public static function render(string $template, array $vars, string $app = null, string $plugin = null): string
{
$request = request();
$configPrefix = $plugin ? config('app.plugin_alias', 'plugin') . ".$plugin." : '';

foreach (config("{$configPrefix}view.options.pre_renders", []) as $render) {
Expand Down
3 changes: 2 additions & 1 deletion src/Render/RenderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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
3 changes: 2 additions & 1 deletion src/Render/ThinkPHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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
3 changes: 2 additions & 1 deletion src/Render/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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
3 changes: 2 additions & 1 deletion src/Support/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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
6 changes: 4 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link https://github.com/Triangle-org/View
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 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 All @@ -31,7 +32,8 @@
* @link https://github.com/Triangle-org/View
*
* @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
Loading