Remix.run Logo
stefanfisk 7 days ago

How would that work if a library supplies a function that takes a string and returns an array? I can’t make it use my array class.

cess11 7 days ago | parent [-]

Could you give a realistic example?

The PHP pipes as described in the articles about it will require a bunch of wrapping anyway so you could just do that. There are several alternatives, from a function or method that just converts from raw array to class, to abstractions involving stuff like __invoke, __call, dispatchers and such.

Also the expectation to not have to put facades on libraries is a bit suspicious, in my experience it is very common. I find it unlikely you actually want to use raw arrays instead of leveraging type guards in your code.

stefanfisk 7 days ago | parent [-]

If I use Laravel’s Str in an app where both myself and a third party library want to add a chainable method, how do I make the API make sense? We can’t both subclass Str. The only option I see is Macroable and that’s a rabbit hole I’d rather avoid.

cess11 7 days ago | parent [-]

The Laravel developers expect you to use Stringable::macro if you want to extend their 'fluent' API, and if you're working in an organisation that builds with the Laravel toolchain that's probably what's least surprising to the other members.

I'm still not clear over what you want to do or why the third party library expects there to be a hacked in 'fluent' method on the Stringable.

Personally I'm not a fan of the Str/Stringable API:s, I find it weird and confusing to mix methods for file paths, strings, encryption and so on. Actually, I'm more of a Symfony person for reasons like this.