Skip to content
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

twigでのphp関数の呼び出し機構を廃止 #1320

Closed
hainey opened this issue Dec 12, 2015 · 8 comments
Closed

twigでのphp関数の呼び出し機構を廃止 #1320

hainey opened this issue Dec 12, 2015 · 8 comments
Labels
enhancement 機能追加 security security
Milestone

Comments

@hainey
Copy link

hainey commented Dec 12, 2015

twigテンプレートにはPHP関数を使うことができないので、
Smartyなどになれている開発者には不便です、こちらのPHP関数をtwigに実行できるExtensionを公式的に導入するのはいかがでしょうか?
http://pastebin.com/VZzgSGLq

@ttsuru
Copy link
Contributor

ttsuru commented Dec 12, 2015

TwigはViewですし、Viewでロジックで実装すべき内容を書くこと自体、推奨されないのではないでしょうか。
不便なのではなく、できないようにしていると言った方が正しいと思います。

必要があれば、TwigExtentionを作成するなり、プラグインをつくって、Controllerなどで処理するなどで対応可能なのではないでしょうか。

@hainey
Copy link
Author

hainey commented Dec 12, 2015

TwigPHPExtensionはphpをロジックとしてtwigに書くことではなくて、
{{ php_ini_get('memory_limit') }} など phpの関数の前にphp_をつけることだけで、phpの標準関数をtwigで直接使えるExtensionとなります。

もちろんControllerに事前に関数を読んで変数をセットすることもできるんですが、もともとロジックではなくて、変数にする必要ない場合でもわざわざViewから分離してControllerに書くのも、かえてプログラムが読みにくくなってしまいます。

またTwigPHPExtensionを導入する以外の方法で、下記のtwigの公式ドキュメントにも方法があるようです。
http://twig.sensiolabs.org/doc/recipes.html
Defining undefined Functions and Filters on the Flyのところをご参照ください。

@nanasess nanasess added the enhancement 機能追加 label Dec 14, 2015
@ttsuru
Copy link
Contributor

ttsuru commented Dec 15, 2015

@hainey
僕がいったExtentionは TwigPHPExtension のことではなく、必要になった場合に適時Extentionを書けばいいのではないかという点です。
PHP関数を利用したい場合に適時Extentionを書いていけばよいのではないでしょうか。

Viewでロジックを書かないという内容は現在のベストプラクティスに近くなっており、現状のEC-CUBEでもPHPをわざわざTwig内に書く必要性がわかりません。
おそらく、ユースケースを幾つか挙げていただいた方が他の方にもわかりやすいのではないかと思います。

@seasoftjapan
Copy link
Contributor

ビューでも PHP をカジュアルに使えるようになるのは歓迎です。PHP の関数群は便利ですから。

@ryo-endo ryo-endo added the question Further information is requested label Jul 28, 2016
@ryo-endo ryo-endo added this to the 3.x milestone Aug 1, 2016
@nanasess
Copy link
Contributor

nanasess commented Apr 6, 2017

React のように View にロジックを記述するフレームワークも出てきていますし、PHP関数も適材適所で使えたら良いのではないかなと思います。

@okazy
Copy link
Contributor

okazy commented Jun 17, 2021

2021/6/17 セキュリティ対策検討会メモ

Twig 内で PHP 関数が実行できるのは、セキュリティの観点から望ましくないので、非推奨としてゆくゆくは廃止していくことも検討しなければいけない。

@chihiro-adachi chihiro-adachi modified the milestones: x.x, 4.2.0 May 27, 2022
@chihiro-adachi
Copy link
Contributor

4.1で非推奨化されましたので、4.2で機能を削除します

@chihiro-adachi chihiro-adachi changed the title twigにphp関数の呼び出し twigでのphp関数の呼び出し機構を廃止 May 30, 2022
@chihiro-adachi chihiro-adachi removed the question Further information is requested label May 30, 2022
@chihiro-adachi
Copy link
Contributor

以下で修正されました。4.2ブランチへ反映されています。
7cd9c2e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 機能追加 security security
Projects
None yet
Development

No branches or pull requests

7 participants