1 | <?php |
||
23 | final class Reader implements EnvironmentReader { |
||
24 | |||
25 | /** |
||
26 | * @var ContextReader[] |
||
27 | */ |
||
28 | private $contextReaders = array(); |
||
29 | |||
30 | /** |
||
31 | * Drupal driver manager. |
||
32 | * |
||
33 | * @var \Drupal\DrupalDriverManager |
||
34 | */ |
||
35 | private $drupal; |
||
36 | |||
37 | /** |
||
38 | * Configuration parameters for this suite. |
||
39 | */ |
||
40 | private $parameters; |
||
41 | |||
42 | /** |
||
43 | * Statically cached lists of subcontexts by path. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | static protected $subContexts; |
||
48 | |||
49 | /** |
||
50 | * Register the Drupal driver manager. |
||
51 | */ |
||
52 | public function __construct(DrupalDriverManager $drupal, array $parameters) { |
||
53 | $this->drupal = $drupal; |
||
54 | $this->parameters = $parameters; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Registers context loader. |
||
59 | * |
||
60 | * @param ContextReader $contextReader |
||
61 | */ |
||
62 | public function registerContextReader(ContextReader $contextReader) { |
||
63 | $this->contextReaders[] = $contextReader; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function supportsEnvironment(Environment $environment) { |
||
70 | return $environment instanceof ContextEnvironment; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function readEnvironmentCallees(Environment $environment) { |
||
77 | |||
78 | if (!$environment instanceof ContextEnvironment) { |
||
79 | throw new EnvironmentReadException(sprintf( |
||
80 | 'ContextEnvironmentReader does not support `%s` environment.', |
||
81 | get_class($environment) |
||
82 | ), $environment); |
||
83 | } |
||
84 | |||
85 | $callees = array(); |
||
86 | if (!$environment instanceof UninitializedContextEnvironment) { |
||
87 | return $callees; |
||
88 | } |
||
89 | |||
90 | $contextClasses = $this->findSubContextClasses(); |
||
91 | |||
92 | foreach ($contextClasses as $contextClass) { |
||
93 | $callees = array_merge( |
||
94 | $callees, |
||
95 | $this->readContextCallees($environment, $contextClass) |
||
96 | ); |
||
97 | |||
98 | // Register context. |
||
99 | $environment->registerContextClass($contextClass, array($this->drupal)); |
||
100 | } |
||
101 | |||
102 | return $callees; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Reads callees from a specific suite's context. |
||
107 | * |
||
108 | * @param ContextEnvironment $environment |
||
109 | * @param string $contextClass |
||
110 | * |
||
111 | * @return Callee[] |
||
112 | */ |
||
113 | private function readContextCallees(ContextEnvironment $environment, $contextClass) |
||
114 | { |
||
115 | $callees = array(); |
||
116 | foreach ($this->contextReaders as $loader) { |
||
117 | $callees = array_merge( |
||
118 | $callees, |
||
119 | $loader->readContextCallees($environment, $contextClass) |
||
120 | ); |
||
121 | } |
||
122 | |||
123 | return $callees; |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Finds and loads available subcontext classes. |
||
128 | */ |
||
129 | private function findSubContextClasses() { |
||
169 | |||
170 | /** |
||
171 | * Find Sub-contexts matching a given pattern located at the passed path. |
||
172 | * |
||
173 | * @param string $path |
||
174 | * Absolute path to the directory to search for sub-contexts. |
||
175 | * @param string $pattern |
||
176 | * File pattern to match. Defaults to `/^.+\.behat\.inc/i`. |
||
177 | * |
||
178 | * @return array |
||
179 | * An array of paths. |
||
180 | */ |
||
181 | private function findAvailableSubContexts($path, $pattern = '/^.+\.behat\.inc/i') { |
||
201 | |||
202 | /** |
||
203 | * Load each subcontext file. |
||
204 | * |
||
205 | * @param array $subcontexts |
||
206 | * An array of files to include. |
||
207 | */ |
||
208 | private function loadSubContexts($subcontexts) { |
||
218 | |||
219 | } |
||
220 |