Commit Graph

6780 Commits

Author SHA1 Message Date
Fabien Potencier 34dce7cd9f Merge branch '3.x' into 4.x
* 3.x:
  Deprecate OptimizerNodeVisitor::OPTIMIZE_TEXT_NODES
2024-08-23 09:25:03 +02:00
Fabien Potencier 1fe2c00fa2 bug #4221 Deprecate OptimizerNodeVisitor::OPTIMIZE_TEXT_NODES (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Deprecate OptimizerNodeVisitor::OPTIMIZE_TEXT_NODES

Refs #4146

While trying to debug #4146, I realized that this optimization is not possible as we don't know how nodes are going to be used.

See the script provided in #4146 to reproduce the problem.

`@brandonkelly` Can you confirm that this fixes your problem? Maybe there is also an issue with yield vs echo, but the script provided in the issue runs fine for me after this PR.

Commits
-------

7121673c Deprecate OptimizerNodeVisitor::OPTIMIZE_TEXT_NODES
2024-08-23 09:23:28 +02:00
Fabien Potencier 7121673c9c Deprecate OptimizerNodeVisitor::OPTIMIZE_TEXT_NODES 2024-08-23 09:22:06 +02:00
Fabien Potencier 96e5d65d42 minor #4218 Add private types on 4.x (smnandre)
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Add private types on 4.x

(WIP but i open to gather early feedback / comments)

Objective: add missing types

- [x] Private properties
- [x] Return type on private methods
- [ ] Argument types on private methods (?not sure)

Maybe "`@internal`" then

Commits
-------

72bbe489 Add private types on 4.x
2024-08-21 20:05:43 +02:00
Simon André 72bbe489e1 Add private types on 4.x 2024-08-21 20:05:41 +02:00
Fabien Potencier 8da936a2e0 feature #4199 Do not hide unnecessary escape characters (ruudk)
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Do not hide unnecessary escape characters

Follow up of #4176, #4123 and #2712.

Now that we have deprecated unnecessary escape in v3, we can change the behavior in v4.

With this change, unnecessary will no longer be ignored, but handled like any other character.

This allows for writing fully qualified class names like this:
```twig
{{ constant('App\Entity\User::SOME_CONSTANT') }}
```

Instead of having to escape the `\` in v3:
```twig
{{ constant('App\\Entity\\User::SOME_CONSTANT') }}
```

/cc `@fabpot` `@stof`

Commits
-------

53c24bfc Do not hide unnecessary escape characters
2024-08-21 19:42:34 +02:00
Ruud Kamphuis 53c24bfc33 Do not hide unnecessary escape characters 2024-08-21 19:42:26 +02:00
Fabien Potencier 878d2a200a Merge branch '3.x' into 4.x
* 3.x:
  Improve deprecation message
2024-08-21 19:39:57 +02:00
Fabien Potencier e0077a4a6c minor #4219 Improve deprecation message (ruudk)
This PR was merged into the 3.x branch.

Discussion
----------

Improve deprecation message

See https://github.com/twigphp/Twig/pull/4199#discussion_r1723456834

/cc `@stof` `@fabpot`

Commits
-------

90107929 Improve deprecation message
2024-08-21 19:39:46 +02:00
Ruud Kamphuis 90107929da Improve deprecation message
See https://github.com/twigphp/Twig/pull/4199#discussion_r1723456834
2024-08-21 19:36:27 +02:00
Fabien Potencier 2acd9e8d9f Remove obsolete code 2024-08-21 08:21:08 +02:00
Fabien Potencier b5372f5764 Merge branch '3.x' into 4.x
* 3.x:
  Fix CS
  Remove obsolete comment
  Resolves #4200
2024-08-20 18:12:56 +02:00
Fabien Potencier 302971f34e Fix CS 2024-08-20 18:10:26 +02:00
Fabien Potencier f4bca4fa44 Remove obsolete comment 2024-08-20 18:06:11 +02:00
Fabien Potencier 5918aa939f feature #4212 ChainLoader constructor should accept iterable instead of array (TheCelavi)
This PR was merged into the 3.x branch.

Discussion
----------

ChainLoader constructor should accept iterable instead of array

Closes #4200

Commits
-------

6ef13d1e Resolves #4200
2024-08-20 18:00:03 +02:00
Nikola Svitlica a.k.a TheCelavi 6ef13d1e0b Resolves #4200 2024-08-20 17:30:37 +02:00
Fabien Potencier 9808763717 Simplify code 2024-08-20 17:22:36 +02:00
Fabien Potencier 5678ee080d Merge branch '3.x' into 4.x
* 3.x:
  Refactor code
  Add a test
2024-08-20 17:21:22 +02:00
Fabien Potencier b9b8d52572 minor #4217 Refactor code (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Refactor code

Commits
-------

31037d0e Refactor code
2024-08-20 17:20:15 +02:00
Fabien Potencier 31037d0e51 Refactor code 2024-08-20 15:39:54 +02:00
Fabien Potencier 63e35b9620 Add a test 2024-08-20 09:34:22 +02:00
Fabien Potencier 06c378ef27 Remove compat layer (use_yield) 2024-08-19 20:21:08 +02:00
Fabien Potencier 5820fba263 Merge branch '3.x' into 4.x
* 3.x:
  Update CHANGELOG and docs
  Swap BC layer for yield-ready and reclaim perf loss
  Add test about version
2024-08-19 20:19:25 +02:00
Fabien Potencier 3a307cd41d Update CHANGELOG and docs 2024-08-19 20:06:41 +02:00
Fabien Potencier 80c15749f9 feature #4216 Swap BC layer for yield-ready and reclaim perf loss (nicolas-grekas)
This PR was merged into the 3.x branch.

Discussion
----------

Swap BC layer for yield-ready and reclaim perf loss

Follows #3999

Fix #4146
Fix #4103

When `use_yield` is set to false (the default), this PR reverts the implementation of the `render()` method to use a wrapping output buffer instead of hooking between each steps of generators. In this mode, the behavior of the yield method is not "pure": it triggers a mix of yield and echo. But this is fine for render and display methods.

When `use_yield` is set to `true`, we skip that wrapping output buffer. This makes twig compatible with fibers (and this also makes compilation fail if a non-YieldReady extension is found.)

That makes the name of the option not ideal, but BC rulez FTW.

Commits
-------

5d1a19a8 Swap BC layer for yield-ready and reclaim perf loss
2024-08-19 20:02:33 +02:00
Nicolas Grekas 5d1a19a80c Swap BC layer for yield-ready and reclaim perf loss 2024-08-19 17:31:12 +02:00
Fabien Potencier 17997cf7fc minor #4214 Add test about Environment version constants. (VincentLanglet)
This PR was merged into the 3.x branch.

Discussion
----------

Add test about Environment version constants.

Hi `@fabpot`

The Environment Version constants seems to be manually updated.
https://github.com/twigphp/Twig/blob/fe36e084b4e208c44e30886053c8594bb99bd78f/src/Environment.php#L46-L51

A mistake was made on the 3.11 version, the MAJOR_VERSION was set to 4 instead of 3
https://github.com/twigphp/Twig/blob/e80fb8ebba85c7341a97a9ebf825d7fd4b77708d/src/Environment.php#L48

It was fixed in another version, but I think it could be useful to have some test about the consistency of all those constants.
Such test would have fail for the 3.11 version and avoid the mistake.

Commits
-------

254abc8c Add test about version
2024-08-19 08:48:36 +02:00
Fabien Potencier 65048fa3bb Fix CS 2024-08-18 19:27:14 +02:00
Fabien Potencier 15c0adb3ed Merge branch '3.x' into 4.x
* 3.x:
  Fix CS
2024-08-18 19:26:04 +02:00
Fabien Potencier 675cb2d141 Fix CS 2024-08-18 19:25:19 +02:00
Vincent Langlet 254abc8c4c Add test about version 2024-08-18 18:25:33 +02:00
Fabien Potencier 787aaed923 Remove versionadded in docs 2024-08-18 17:54:42 +02:00
Fabien Potencier d9f52db503 Merge branch '3.x' into 4.x
* 3.x:
  Fix typos in CHANGELOG
2024-08-18 17:54:12 +02:00
Fabien Potencier fe36e084b4 feature #4209 Accept colons instead of equals for named arguments (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Accept colons instead of equals for named arguments

Refs #3475
Refs #3635

Commits
-------

84116e5f Fix typos in CHANGELOG
2024-08-18 17:53:41 +02:00
Fabien Potencier 84116e5ff7 Fix typos in CHANGELOG 2024-08-18 17:52:16 +02:00
Fabien Potencier 3f99f250d7 Remove versionadded in docs 2024-08-18 09:41:01 +02:00
Fabien Potencier 9e48502555 Merge branch '3.x' into 4.x
* 3.x:
  Fix html_cva docs
  Fix html_cva docs
  Introduce CVA to html-extra
  Move some methods to static calls
2024-08-18 09:40:33 +02:00
Fabien Potencier 1d5a8dc98b Fix html_cva docs 2024-08-18 09:38:48 +02:00
Fabien Potencier e85519fcd9 Fix html_cva docs 2024-08-18 09:38:02 +02:00
Fabien Potencier 0bfef5b300 feature #4006 Introduce CVA to html-extra (WebMamba)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Introduce CVA to html-extra

Hey! This PR introduces CVA to Twig. All of this has already been merged into SymfonyUX (https://github.com/symfony/ux/pull/1416), but `@kbond` suggested that this repo can be a better place for this feature.

Here is a description from the PR merged in to SymfonyUX:

------------------------------

This PR introduces a new concept CVA (Class Variance Authority), by adding a1 twig function, to help you manage your class in your component.

Let's take an example an Alert component. In your app, an alert can have a lot of different styles one for success, one for alert, one for warning, and different sizes, with icons or not... You need something that lets you completely change the style of your component without creating a new component, and without creating too much complexity in your template.

Here is the reason came CVA.

Your Alert component can now look like this:

```twig
{% props color = 'blue', size = 'md' %}

{% set alert =  html_cva(
      'alert rounded-lg',
     {
        color: {
            blue: 'text-blue-800 bg-blue-50 dark:bg-gray-800 dark:text-blue-400',
            red: 'text-red-800 bg-red-50 dark:bg-gray-800 dark:text-red-400',
            green: 'text-green-800 bg-green-50 dark:bg-gray-800 dark:text-green-400',
            yellow: 'text-yellow-800 bg-yellow-50 dark:bg-gray-800 dark:text-yellow-400',
        },
        size: {
            sm: 'px-4 py-3 text-sm',
            md: 'px-6 py-4 text-base',
            lg: 'px-8 py-5 text-lg',
        }
    },
    [{
           color: ['red'],
           size: ['lg'],
          class: 'font-semibold'
    }],
   {
           rounded: 'md'
    }
}) %}

<div class="{{ cva.apply({color, size}, attribute.render('class'), 'flex p-4') }}">
    ...
</div>
```

So here you have a `cva` function that lets you define different variants of your component.

You can now use your component like this:
```twig
<twig:Alert color="red" size="md"/>

<twig:Alert color="green" size="sm"/>

<twig:Alert color="yellow" size="lg"/>

<twig:Alert color="red" size="md" class="dark:bg-gray-800"/>
```

And then you get the following result:

<img width="1269" alt="Capture d’écran 2024-01-24 à 00 52 33" src="https://github.com/symfony/ux/assets/32077734/6a5e25be-5b81-4ae7-8385-0fa5422d0396">

If you want to know more about the concept I implement here you can look at:
- CVA (js version): https://cva.style/docs
- tailwind merge: https://github.com/gehrisandro/tailwind-merge-php, https://github.com/dcastil/tailwind-merge
- this implementation by using tailwind-merge and cva is inspired a lot by: https://ui.shadcn.com/ (shadcn is the most starred library on github in 2023)
- a really good article that explains the philosophy behind https://manupa.dev/blog/anatomy-of-shadcn-ui
- this PR works great in a LASTstack: https://symfonycasts.com/screencast/last-stack/last-stack

Tell me what you think about it! Thanks for your time! Cheers 🧡

------------

Commits
-------

e3ac14e1 Introduce CVA to html-extra
2024-08-18 09:36:20 +02:00
Matheo Daninos e3ac14e1c8 Introduce CVA to html-extra 2024-08-18 09:36:16 +02:00
Fabien Potencier 8c090c3427 feature #4213 Add return types missed in #4211 (smnandre)
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Add return types missed in #4211

Complete #4211 (sorry)

I forgot to update the docs, and found some others in RuntimeLoader(s)

Commits
-------

21f08dcf Add return types missed in #4211
2024-08-17 23:34:48 +02:00
Simon André 21f08dcfe2 Add return types missed in #4211 2024-08-17 23:34:44 +02:00
Fabien Potencier 15a58aaffb Modernize code 2024-08-17 23:16:46 +02:00
Fabien Potencier 8370e8a9a7 Move some methods to static calls 2024-08-17 23:15:53 +02:00
Fabien Potencier 88cabcc433 feature #4211 Add missing return types in 4.0 (smnandre)
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Add missing return types in 4.0

Revert the removal of return types done in #3156

Should i propagate to `extra` packages in the same PR ?

Commits
-------

470965fc Add missing return types in 4.0
2024-08-17 23:10:10 +02:00
Simon André 470965fcc2 Add missing return types in 4.0 2024-08-17 23:10:07 +02:00
Fabien Potencier 96bc312f5d Modernize code 2024-08-17 23:09:21 +02:00
Fabien Potencier aab6d74ce1 Move loop function implementation to CoreExtension 2024-08-17 23:08:38 +02:00
Fabien Potencier 93206a7d4a Merge branch '3.x' into 4.x
* 3.x:
  Add an extension point for parsing special functions
2024-08-17 23:06:33 +02:00