4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Snippet;
13 use Behat\Behat\Context\Snippet\ContextSnippet;
14 use Behat\Gherkin\Node\StepNode;
17 * Aggregates multiple similar snippets with different targets and steps.
19 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 final class AggregateSnippet
29 * Initializes snippet.
31 * @param Snippet[] $snippets
33 public function __construct(array $snippets)
35 $this->snippets = $snippets;
39 * Returns snippet type.
43 public function getType()
45 return current($this->snippets)->getType();
49 * Returns snippet unique ID (step type independent).
53 public function getHash()
55 return current($this->snippets)->getHash();
59 * Returns definition snippet text.
63 public function getSnippet()
65 return current($this->snippets)->getSnippet();
69 * Returns all steps interested in this snippet.
73 public function getSteps()
77 function (Snippet $snippet) {
78 return $snippet->getStep();
87 * Returns all snippet targets.
91 public function getTargets()
95 function (Snippet $snippet) {
96 return $snippet->getTarget();
104 * Returns the classes used in the snippet which should be imported.
108 public function getUsedClasses()
110 if (empty($this->snippets)) {
115 call_user_func_array(
118 function (Snippet $snippet) {
119 if (!$snippet instanceof ContextSnippet) {
123 return $snippet->getUsedClasses();