Skip to content

Pass string as method argument #154

Description

@dereuromark

Is there a reason the string has to be put into the constructor, and the actual config happens at runtime?
It makes it difficult for DI and libraries/config to adjust the object ones in constructing and then using it.

If you look into e.g.
https://commonmark.thephpleague.com/1.5/extensions/github-flavored-markdown/
or https://github.com/kzykhys/Ciconia/blob/master/src/Ciconia/Ciconia.php#L42

Then you usually make the builder itself stateless and instead wrap statefulness internally.

$env = .. // Can contain all the filters and stuff
$options =  [
    'xhtmlOutput' => true,
    'strictMode' => false,
    'escapeHtml' => true
];

// We can pass defaults here if we want
$instance = new Decoda($env, $options);

// We can also set options here per convertion
$html = $instance->convert($bbcodeText, $options);
$html2 = $instance->convert($bbcodeText2, $otherOptions);

What do you think?

There will also be no need for reset() then as it keeps the wrapper stateless and reuses the objects here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    majormajor (BC break)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions