contentful / rich-text.php

Utilities for the Contentful Rich Text
https://www.contentful.com
MIT License
12 stars 9 forks source link

Too few arguments to Parser #32

Closed kination closed 5 years ago

kination commented 5 years ago

Hello, I caught an error when calling parser and renderer for RichText

2019/03/19 06:21:17 [error] 6#6: *5 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function Contentful\RichText\Parser::__construct(), 0 passed in /var/www/html/include/contentful_function.php on line 82 and at least 1 expected in /var/www/html/assets/vendor/contentful/rich-text/src/Parser.php:45

My code is:

...
    $parser = new Contentful\RichText\Parser();
    $renderer = new Contentful\RichText\Renderer();

    $node = $parser->parse($data);
...

What parameter do I have to put on Parser constructor?

Thanks.

dborsatto commented 5 years ago

This package is designed to be used automatically by the Delivery SDK, and shouldn't really be created manually. If for whatever reason you still want to use this library standalone, you need to provide an instance of Contentful\Core\Api\LinkResolverInterface, which is responsible for converting a Contentful\Core\Api\Link object (a Contentful link) into an actual resource. You can check the Delivery SDK implementation for reference: https://github.com/contentful/contentful.php/blob/master/src/LinkResolver.php

Cheers,

Davide

getrealtec commented 2 years ago

@dborsatto Then when is it instanciated without parameters in the README file?

Cause for confusion here.

I'm currently looking for a formatter from your rawRich array to HTML but using the whole "Core" is impossible as we're not using that library to fetch data from Contentful because of architectural reasons.

Do you have a Snapshot that would allow us to use the RichText as a standalone library since it is separated from the "Core" by design?

Sebb767 commented 2 years ago

Hey @getrealtec ,

@dborsatto no longer maintains this library. The readme should've been updated, since we had previous confusion - I'm sorry, that's on me.

On using this library stand-alone, we don't really support this use-case. That being said, simply implementing the link resolver interface to resolve to your types would be an option (see here for an example on how it's used). You'd still need to import Contentful/Core by dependency, but you wouldn't need to use it in any way.