@@ -136,24 +136,31 @@ protected function fetchByTypeAndId(string $type, string $providerBehaviour, int
136136
137137 $ element = $ builder ->buildById ($ id );
138138
139- $ this ->dispatchData ([$ element ], $ providerBehaviour , $ resourceMeta );
139+ if ($ element instanceof ElementInterface) {
140+ $ this ->dispatchElement ($ element , $ providerBehaviour , $ resourceMeta );
141+ }
140142 }
141143
142144 protected function log (string $ level , string $ message ): void
143145 {
144146 $ this ->logger ->log ($ level , $ message , DsTrinityDataBundle::PROVIDER_NAME , $ this ->contextName );
145147 }
146148
147- protected function dispatchData (array $ elements , string $ providerBehaviour , ?ResourceMetaInterface $ resourceMeta = null ): void
149+ protected function dispatchData (\ Generator $ elements , string $ providerBehaviour , ?ResourceMetaInterface $ resourceMeta = null ): void
148150 {
149151 foreach ($ elements as $ element ) {
150- $ newDataEvent = new NewDataEvent ($ this ->contextDispatchType , $ this ->contextName , $ element , $ providerBehaviour , $ resourceMeta );
151- $ this ->eventDispatcher ->dispatch ($ newDataEvent , DynamicSearchEvents::NEW_DATA_AVAILABLE );
152-
153- $ this ->dispatchProcessControlSignal ();
152+ $ this ->dispatchElement ($ element , $ providerBehaviour , $ resourceMeta );
154153 }
155154 }
156155
156+ protected function dispatchElement (ElementInterface $ element , string $ providerBehaviour , ?ResourceMetaInterface $ resourceMeta = null ): void
157+ {
158+ $ newDataEvent = new NewDataEvent ($ this ->contextDispatchType , $ this ->contextName , $ element , $ providerBehaviour , $ resourceMeta );
159+ $ this ->eventDispatcher ->dispatch ($ newDataEvent , DynamicSearchEvents::NEW_DATA_AVAILABLE );
160+
161+ $ this ->dispatchProcessControlSignal ();
162+ }
163+
157164 protected function addSignalListener (): void
158165 {
159166 if (php_sapi_name () !== 'cli ' ) {
0 commit comments