prismicio-community / php-kit

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

Updated API to use late static binding #153

Closed jrbasso closed 4 years ago

jrbasso commented 6 years ago

Using late static binding allows the developers to extend the original Api class and make some customizations.

With this change, developers can rename the cookie by simply doing like this:

class CustomAPI extends Prismic\Api {
    const PREVIEW_COOKIE = "my_custom_cookie";
}

CustomAPI::get('https://project.prismic....');

It can also add some logs or manipulation on top of the original class:

class CustomAPI2 extends Prismic\Api {
    public function query($q, $options = array()) {
        $options['lang'] => $_COOKIE['my_custom_locale_cookie'];
        return parent::query($q, $options);
    }
}

CustomAPI::get('https://project.prismic....');

These 2 things are not possible currently because the Api::get() has the returning forcing to use the Prismic\Api class. The only alternative would be doing what the Api::get does on the developer side, which is not great and Prismic's updates could break developer's apps.

kenvunz commented 6 years ago

Please merge as we also need to override the defaultCache method to inject Laravel caching system instead of using the default one

eytienne commented 4 years ago

why isn't it merged yet ?

Raph22 commented 4 years ago

Hi all, Thank you for the PR. I understand that this feature is really asked and it lacks to you. But I can't accepted it as it because we don't want our customers be able to change cookies names. For other things ok. So if you remove the late static binding on cookies and fix conflicts I will be able to merge it. Otherwise someone in the team will do the PR as soon as we get a chance to work on it. Thank you

jrbasso commented 4 years ago

@Raph22 Out of curiosity, why not allowing changing the cookie names?

Raph22 commented 4 years ago

We rely in it for several things. Especially for the Prismic toolbar and the preview feature.

Raph22 commented 4 years ago

Thanks a lot @jrbasso !

Raph22 commented 4 years ago

Released as 5.1.1