diff --git a/src/Elchristo/Calendar/Converter/Converter.php b/src/Elchristo/Calendar/Converter/Converter.php index b952540..85dbad3 100644 --- a/src/Elchristo/Calendar/Converter/Converter.php +++ b/src/Elchristo/Calendar/Converter/Converter.php @@ -49,10 +49,18 @@ protected static function exists($name, array $convertibleEvents = [], $buildIfE if (isset(self::$converters[$canonicalizeName])) { return $canonicalizeName; } else if (\is_subclass_of($name, ConverterInterface::class)) { + // passed classname if ($buildIfExists === \true) { self::build($name, $convertibleEvents); } return $canonicalizeName; + } else if (\array_key_exists($name, $convertibleEvents) && \is_array($convertibleEvents[$name])) { + // converter name declared in configuration + $classname = \current($convertibleEvents[$name]); + if ($buildIfExists === \true) { + self::build($classname, $convertibleEvents); + } + return self::canonicalizeName($classname); } else { // lookup in default namespace $className = __NAMESPACE__ . '\\' . \ucfirst($name) . '\\' . \ucfirst($name); diff --git a/tests/unit/ConvertibleEventFactoryTest.php b/tests/unit/ConvertibleEventFactoryTest.php index 9d20541..e29abe7 100644 --- a/tests/unit/ConvertibleEventFactoryTest.php +++ b/tests/unit/ConvertibleEventFactoryTest.php @@ -50,6 +50,7 @@ public function testCanConvertCalendarByGivenConverterName() $config = $this->getConfigProvider(); $sourceBuilder = SourceBuilderFactory::create($config); $calendar = new unit\Stub\TestCalendar($sourceBuilder, new Collection()); + $calendar->setConfig($config); $json = Converter::convert($calendar, 'json'); $this->assertJson($json); }