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

Change API of PlaceholderContainer #5

Open
ArjanSchouten opened this issue Sep 18, 2017 · 0 comments
Open

Change API of PlaceholderContainer #5

ArjanSchouten opened this issue Sep 18, 2017 · 0 comments
Assignees

Comments

@ArjanSchouten
Copy link
Owner

The PlaceholderContainer has a bad API.

Current:

$content = '<html>
<body><pre>Content which should be replaced</pre></body>
</html>';
$placeholderContainer = new PlaceholderContainer();
$placeholder = $placeholderContainer->addPlaceholder('Content which should be replaced');
$result = str_replace('Content which should be replaced', $placeholder, $content);

Desired:

$content = '<html>
<body><pre>Content which should be replaced</pre></body>
</html>';
$placeholderContainer = new PlaceholderContainer();
$result = $placeholderContainer->addPlaceholder('Content which should be replaced', $content);

In lots of cases the API is used for doing something like this which makes sense:

return preg_replace_callback($pattern, function ($match) use ($placeholderContainer) {
     return $placeholderContainer->addPlaceholder($match[1]);
}, $contents);

The original addPlaceholder function should be renamed to createPlaceholder() with the same method definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant