Skip to content

Symfony UX Turbo: content negotiation and Doctrine integration #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2021
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
189 changes: 189 additions & 0 deletions .github/workflows/test-turbo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
name: Symfony UX Turbo

on:
push:
pull_request:

jobs:
phpstan:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: zip

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
working-directory: src/Turbo
run: composer install --prefer-dist

- name: Install PHPUnit dependencies
working-directory: src/Turbo
run: vendor/bin/simple-phpunit --version

- name: PHPStan
working-directory: src/Turbo
run: vendor/bin/phpstan analyse --no-progress

tests-php-high-deps:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
fail-fast: false
name: PHP ${{ matrix.php-versions }} Test on ubuntu-latest

services:
mercure:
image: dunglas/mercure
env:
SERVER_NAME: :3000
MERCURE_PUBLISHER_JWT_KEY: '!ChangeMe!'
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeMe!'
MERCURE_EXTRA_DIRECTIVES: |
anonymous
cors_origins *
ports:
- 3000:3000

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: zip, pdo_sqlite

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache PHP dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install PHP dependencies
working-directory: src/Turbo
run: composer install --prefer-dist

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install JavaScript dependencies
working-directory: src/Turbo/Tests/app
run: yarn install

- name: Build JavaScript
working-directory: src/Turbo/Tests/app
run: yarn build

- name: Create DB
working-directory: src/Turbo/Tests/app
run: php public/index.php doctrine:schema:create

- name: Run tests
working-directory: src/Turbo
env:
SYMFONY_DEPRECATIONS_HELPER: max[direct]=0
run: vendor/bin/simple-phpunit

tests-php-low-deps:
runs-on: ubuntu-latest
name: PHP 8.0 (lowest) Test on ubuntu-latest

services:
mercure:
image: dunglas/mercure
env:
SERVER_NAME: :3000
MERCURE_PUBLISHER_JWT_KEY: '!ChangeMe!'
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeMe!'
MERCURE_EXTRA_DIRECTIVES: |
anonymous
cors_origins *
ports:
- 3000:3000

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: zip, pdo_sqlite

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache PHP dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install PHP dependencies
working-directory: src/Turbo
run: composer update --prefer-dist --prefer-lowest --prefer-stable

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install JavaScript dependencies
working-directory: src/Turbo/Tests/app
run: yarn install

- name: Build JavaScript
working-directory: src/Turbo/Tests/app
run: yarn build

- name: Create DB
working-directory: src/Turbo/Tests/app
run: php public/index.php doctrine:schema:create

- name: Run tests
working-directory: src/Turbo
env:
SYMFONY_DEPRECATIONS_HELPER: max[total]=9223372036854775807 # PHP_INT_MAX
run: vendor/bin/simple-phpunit
4 changes: 1 addition & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
php-version: '7.4'
- name: php-cs-fixer
run: |
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.16.1/php-cs-fixer.phar -q
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.18.2/php-cs-fixer.phar -q
php php-cs-fixer.phar fix --dry-run --diff

coding-style-js:
Expand All @@ -34,7 +34,6 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
extensions: gd
- name: Chartjs
run: |
cd src/Chartjs
Expand Down Expand Up @@ -63,7 +62,6 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: gd
- name: Chartjs
run: |
cd src/Chartjs
Expand Down
2 changes: 2 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ return PhpCsFixer\Config::create()
->in(__DIR__.'/src')
->append([__FILE__])
->notPath('#/Fixtures/#')
->notPath('#/app/var/#')
->notPath('Turbo/Attribute/Broadcast.php') // Need https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4702
)
;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"workspaces": [
"src/*/Resources/assets"
"src/**/Resources/assets"
],
"scripts": {
"build": "yarn workspaces run build",
Expand Down
2 changes: 1 addition & 1 deletion src/Chartjs/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "1.1-dev"
"dev-main": "1.3-dev"
},
"thanks": {
"name": "symfony/ux",
Expand Down
2 changes: 1 addition & 1 deletion src/Cropperjs/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "1.1-dev"
"dev-main": "1.3-dev"
},
"thanks": {
"name": "symfony/ux",
Expand Down
2 changes: 1 addition & 1 deletion src/Dropzone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ the `@symfony/ux-dropzone/src/style.css` autoimport to `false`:
"@symfony/ux-dropzone": {
"dropzone": {
"enabled": true,
"fetch": "eager",
"webpackMode": "eager",
"autoimport": {
"@symfony/ux-dropzone/src/style.css": false
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dropzone/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "1.1-dev"
"dev-main": "1.3-dev"
},
"thanks": {
"name": "symfony/ux",
Expand Down
2 changes: 1 addition & 1 deletion src/LazyImage/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "1.1-dev"
"dev-main": "1.3-dev"
},
"thanks": {
"name": "symfony/ux",
Expand Down
2 changes: 1 addition & 1 deletion src/Swup/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"extra": {
"branch-alias": {
"dev-main": "1.1-dev"
"dev-main": "1.3-dev"
},
"thanks": {
"name": "symfony/ux",
Expand Down
5 changes: 5 additions & 0 deletions src/Turbo/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/Resources/assets/test export-ignore
/Tests export-ignore
12 changes: 12 additions & 0 deletions src/Turbo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.php_cs.cache
/.php_cs
/.phpunit.result.cache
/composer.phar
/composer.lock
/phpunit.xml
/vendor/
/Tests/app/var
/Tests/app/public/build/
node_modules/
package-lock.json
yarn.lock
44 changes: 44 additions & 0 deletions src/Turbo/Attribute/Broadcast.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\UX\Turbo\Attribute;

use Symfony\UX\Turbo\Bridge\Mercure\Broadcaster;

/**
* Marks the entity as broadcastable.
*
* @author Kévin Dunglas <[email protected]>
*
* @experimental
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
final class Broadcast
{
public const ACTION_CREATE = 'create';
public const ACTION_UPDATE = 'update';
public const ACTION_REMOVE = 'remove';

/**
* @var mixed[]
*/
public array $options;

/**
* Options can be any option supported by the broadcaster.
*
* @see Broadcaster for the default options when using Mercure
*/
public function __construct(mixed ...$options)
{
$this->options = $options;
}
}
Loading