prismicio-community / php-kit

Community maintained development kit for Prismic and the PHP language
https://prismic.io
Other
108 stars 82 forks source link

Add Slice Interface #138

Closed gsteel closed 7 years ago

gsteel commented 7 years ago

Add SliceInterface to represent common traits of normal slices and composite slices.

Also added some missing properties to the Slice class declaration and type hinted FragmentInterface in the constructor.

srenault commented 7 years ago

Thanks again @gsteel for your contribution!

What would be the use case of this?

gsteel commented 7 years ago

In my case, I type hint against a slice fragment in view helpers so that helpers and views can be sure of what they are dealing with. As it's probable that the 'old' slice type will get deprecated, it's handy to maintain type safety where your repo may be sending you either type of slice…

srenault commented 7 years ago

So you want to support both in your code in case if the writer converts the old slice type to the new one?

gsteel commented 7 years ago

Yes, in certain places, I want to be sure that I've got a slice - Say I have a helper that proxies different slices to different renderers/serializers based on the name of that slice - I want to be sure that whatever I'm proxying is 'Slice-Like' and leave it up the serializers to figure out whether the slice is composite or not.