Skip to content
This repository has been archived by the owner on Apr 24, 2018. It is now read-only.

Commit

Permalink
✨ Add many visitor
Browse files Browse the repository at this point in the history
Sometimes you need multiple visitors.

$visitor = new VisitorMany(
    array(
        new VisitorX(),
        new VisitorY(),
    )
);

$traverser = new Traverser($visitor);
  • Loading branch information
hansott committed Sep 17, 2017
1 parent 5b3abc8 commit ef28abd
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Query/VisitorMany.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace HansOtt\GraphQL\Query;

final class VisitorMany implements Visitor
{
private $visitors;

/**
* @param Visitor[] $visitors
*/
public function __construct(array $visitors)
{
$this->visitors = $visitors;
}

public function beforeTraverse(Document $document)
{
foreach ($this->visitors as $visitor) {
$visitor->beforeTraverse($document);
}
}

public function enterNode(Node $node)
{
foreach ($this->visitors as $visitor) {
$visitor->enterNode($node);
}
}

public function leaveNode(Node $node)
{
foreach ($this->visitors as $visitor) {
$visitor->leaveNode($node);
}
}

public function afterTraverse(Document $document)
{
foreach ($this->visitors as $visitor) {
$visitor->afterTraverse($document);
}
}
}

0 comments on commit ef28abd

Please sign in to comment.