Attribute.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\TemplateEngine\Xhtml\Compiler;
  7. use Magento\Framework\DataObject;
  8. use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\Directive\DirectiveInterface;
  9. /**
  10. * Class Attribute
  11. */
  12. class Attribute implements AttributeInterface
  13. {
  14. /**
  15. * @var DirectiveInterface[]
  16. */
  17. protected $directivePool;
  18. /**
  19. * Constructor
  20. *
  21. * @param DirectiveInterface[] $directivePool
  22. */
  23. public function __construct(array $directivePool)
  24. {
  25. $this->directivePool = $directivePool;
  26. }
  27. /**
  28. * Compiles the Element node
  29. *
  30. * @param \DOMAttr $node
  31. * @param DataObject $processedObject
  32. * @return void
  33. */
  34. public function compile(\DOMAttr $node, DataObject $processedObject)
  35. {
  36. foreach ($this->directivePool as $directive) {
  37. $node->value = preg_replace_callback(
  38. $directive->getPattern(),
  39. function ($match) use ($directive, $processedObject) {
  40. return $directive->execute($match, $processedObject);
  41. },
  42. $node->value
  43. );
  44. }
  45. }
  46. }