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

Add wrapper for custom Transforms #1

Open
WebMechanic opened this issue Mar 21, 2020 · 0 comments
Open

Add wrapper for custom Transforms #1

WebMechanic opened this issue Mar 21, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@WebMechanic
Copy link
Owner

Currently the signature to create a new custom element Transform is unintuitive, rather complex and ugly:

$this->transforms['channel'] = new Transform(
  function (DOMElement $node, Item $site) {
    // do stuff
    return $this;
  }
);

Add a wrapper to Converter to streamline these calls, i.e.

/* probable signature */
public function addTransform(string $nodeName, Closure|string $callback) { /*...*/ }

within the custom Converter

/* 1) pass an anonymous function */
$this->addTransform('language', function($node,$item) {});
/* 2) pass an object byref with a "language" method, calls $myhelper->language() */
$this->addTransform('language', $myhelper);
/* 3) pass the name of a method within the custom Converter, calls $this->langCoder() */
$this->addTransform('language', "langCoder");

Option 2 would allow to include (share) external code (plugins) to perform the same Transform job over and over again.

@WebMechanic WebMechanic added the enhancement New feature or request label Mar 21, 2020
@WebMechanic WebMechanic self-assigned this Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant