Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve main parser entry point API and config #232

Open
barnabywalters opened this issue Feb 23, 2022 · 0 comments
Open

Improve main parser entry point API and config #232

barnabywalters opened this issue Feb 23, 2022 · 0 comments
Milestone

Comments

@barnabywalters
Copy link
Collaborator

barnabywalters commented Feb 23, 2022

Currently, the parser has a variety of different entry points:

Mf2\fetch('url');
Mf2\parse('html', 'url');
$p = new Parser('html', 'url');
$p->parse();
$p->parseFromId();

Additionally, there is a variety of different ways of setting various configuration options and feature flags, often just by passing a boolean to a positional argument. Depending on the entry point, a boolean in a particular position might do something completely different.

For v1.0 we could make the most of the possibility for breaking changes to improve the API for better consistency, readability and extensibility.

Inspired by the XRay API, one potential improvement could be replacing the fetch and parse functions with a single parse function which does both depending on its arguments:

Mf2\parse($url); // Fetches and parses the contents of $url
Mf2\parse($url, $html); // Parses $html using $url as a base URL

One potential solution to the config issue would be to allow passing a $config array or object to any of the main entry points, e.g.

$config = [
  'lang' => true,
  'curl_info' => &$curlInfo,
  'json_mode' => true,
  'debug' => true,
  'parse_classic' => true
];

// Used with the existing entry point functions:
Mf2\fetch('url', $config);
Mf2\parse('html', 'url', $config);
$p = new Parser('html', 'url', $config);

// Or, with the fetch/parse change suggested above:
Mf2\parse('url', $config);
Mf2\parse('url', 'html', $config);

The config keys themselves are only suggestions and could likely be improved.

With some type checking, it may even be possible to implement this while maintaining back compatibility with the old APIs.

@barnabywalters barnabywalters added this to the v1.0.0 milestone Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant