benjaminhirsch,
@benjaminhirsch@mastodon.social avatar

Is there something similar in php land like kotlin has with kotlinx.html? A DSL to build HTML only with php in a type safe and strict manner? 👀

Crell,
@Crell@phpc.social avatar

@benjaminhirsch A complete, all-of-HTML library is probably unwise, just from a performance perspective. PHP can't do the optimizations that Kotlin or Rust or other compiled languages could do.

For more coarse grained use, this is a bit older but I did it: https://github.com/Crell/HtmlModel

It doesn't do all HTML elements, just the page/fragment level ones. But it tracks metdata (CSS, JS, Links, etc.) and makes merging fragments together into a larger page easy.

benjaminhirsch,
@benjaminhirsch@mastodon.social avatar

@Crell @benjaminhirsch That’s something I thought about as well, but haven’t had time yet to do testing or benchmarking. What specific would you consider problematic performance wise. Creating lots on objects?

Crell,
@Crell@phpc.social avatar

@benjaminhirsch More the hundreds of function calls involved, but the objects, too. Plus the api complexity. HTML doesn't map that cleanly to an object model.

I'm not sure it's possible to do something like that without Rust (Yew framework) or some other compiled language with strong macro support. The DSL would have to be type checked, validated, then compiled away. That's how the fast JS frameworks do it, too.

I just don't see that as viable in PHP. HtmlModel is likely the best we can do.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines