@@ -318,16 +318,16 @@ public static function loadDefinition(ServiceDefinition $definition, $config, st
318318 return ;
319319
320320 } elseif (is_string ($ config ) && interface_exists ($ config )) {
321- $ config = ['class ' => null , ' implement ' => $ config ];
321+ $ config = ['implement ' => $ config ];
322322
323323 } elseif ($ config instanceof Statement && is_string ($ config ->getEntity ()) && interface_exists ($ config ->getEntity ())) {
324- $ config = ['class ' => null , ' implement ' => $ config ->getEntity (), 'factory ' => array_shift ($ config ->arguments )];
324+ $ config = ['implement ' => $ config ->getEntity (), 'factory ' => array_shift ($ config ->arguments )];
325325
326326 } elseif (!is_array ($ config ) || isset ($ config [0 ], $ config [1 ])) {
327- $ config = ['class ' => null , ' factory ' => $ config ];
327+ $ config = ['factory ' => $ config ];
328328 }
329329
330- $ known = ['class ' , 'factory ' , 'arguments ' , 'setup ' , 'autowired ' , 'dynamic ' , 'inject ' , 'parameters ' , 'implement ' , 'run ' , 'tags ' , 'alteration ' ];
330+ $ known = ['type ' , ' class ' , 'factory ' , 'arguments ' , 'setup ' , 'autowired ' , 'dynamic ' , 'inject ' , 'parameters ' , 'implement ' , 'run ' , 'tags ' , 'alteration ' ];
331331 if ($ error = array_diff (array_keys ($ config ), $ known )) {
332332 $ hints = array_filter (array_map (function ($ error ) use ($ known ) {
333333 return Nette \Utils \ObjectMixin::getSuggestion ($ known , $ error );
@@ -343,6 +343,14 @@ public static function loadDefinition(ServiceDefinition $definition, $config, st
343343 $ definition ->setFactory (null );
344344 }
345345
346+ if (array_key_exists ('type ' , $ config )) {
347+ Validators::assertField ($ config , 'type ' , 'string|null ' );
348+ $ definition ->setClass ($ config ['type ' ]);
349+ if (array_key_exists ('class ' , $ config )) {
350+ throw new Nette \InvalidStateException ("Unexpected 'class' when 'type' is used. " );
351+ }
352+ }
353+
346354 if (array_key_exists ('class ' , $ config )) {
347355 Validators::assertField ($ config , 'class ' , 'string|Nette\DI\Statement|null ' );
348356 if ($ config ['class ' ] instanceof Statement) {
0 commit comments