By drunken monkey on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x-1.x
Introduced in version:
8.x-1.40
Issue links:
Description:
New variants of the plugin (and server instance) getter methods on our entity classes were added to improve DX for this common pattern:
if ($index->hasValidTracker()) {
return $index->getTrackerInstance()->…();
}
return [];
The following methods were added:
interface IndexInterface {
public function getDatasourceIfAvailable(string $datasource_id): ?DatasourceInterface;
public function getTrackerInstanceIfAvailable(): ?TrackerInterface;
public function getServerInstanceIfAvailable(): ?ServerInterface;
public function getProcessorIfAvailable(string $processor_id): ?ProcessorInterface;
}
interface ServerInterface {
public function getBackendIfAvailable(): ?BackendInterface;
}
While the above example needs four lines and is (incorrectly) marked by IDEs as unsafe (because of an uncaught exception), this can now be written cleanly in the following way:
return $index->getTrackerInstanceIfAvailable()?->…() ?? [];
Impacts:
Module developers