public function getServiceClass(string $serviceName, bool $forced = true): ?string {
        if(!isset($this->serviceClassNames[$serviceName])) {
            if($this->serviceExists($serviceName)) {
                /** @var ContainerInterface $container */
                $container = $this->serviceData[$serviceName];
                if($container->isInstanceLoaded()) {
                    $this->serviceClassNames[$serviceName] = get_class( $container->getInstance() );
                    goto finish;
                }

                if($container instanceof ServiceAwareContainerInterface) {
                    $this->serviceClassNames[$serviceName] = $container->getServiceClass();
                    goto finish;
                } elseif($container instanceof ConfiguredServiceContainer) {
                    $cfg = $container->getConfiguration();
                    // In case of a direct instance fonciguration, get this classname
                    if($cn = $cfg[AbstractFileConfiguration::SERVICE_CLASS] ?? NULL) {
                        $this->serviceClassNames[$serviceName] = $cn;
                        goto finish;

                    } elseif($cn = $cfg[AbstractFileConfiguration::CONFIG_SERVICE_TYPE_KEY] ?? NULL) {
                        // If the developer defined the class by configuration in case of container or file initialisation, use this.
                        $this->serviceClassNames[$serviceName] = $cn;
                        goto finish;
                    }
                }

                // If nothing worked before, finally load the instance
                if($forced)
                    $this->serviceClassNames[$serviceName] = get_class( $container->getInstance() );
            } else {
                // Mark as not existing
                $this->serviceClassNames[$serviceName] = false;
            }
        }

        finish:

        return $this->serviceClassNames[$serviceName] ?: NULL;
    }
public function getServiceClass(string $serviceName, bool $forced = true): ?string {
        if(!isset($this->serviceClassNames[$serviceName])) {
            if($this->serviceExists($serviceName)) {
                /** @var ContainerInterface $container */
                $container = $this->serviceData[$serviceName];
                if($container->isInstanceLoaded()) {
                    $this->serviceClassNames[$serviceName] = get_class( $container->getInstance() );
                    goto finish;
                }

                if($container instanceof ServiceAwareContainerInterface) {
                    $this->serviceClassNames[$serviceName] = $container->getServiceClass();
                    goto finish;
                } elseif($container instanceof ConfiguredServiceContainer) {
                    $cfg = $container->getConfiguration();
                    // In case of a direct instance fonciguration, get this classname
                    if($cn = $cfg[AbstractFileConfiguration::SERVICE_CLASS] ?? NULL) {
                        $this->serviceClassNames[$serviceName] = $cn;
                        goto finish;

                    } elseif($cn = $cfg[AbstractFileConfiguration::CONFIG_SERVICE_TYPE_KEY] ?? NULL) {
                        // If the developer defined the class by configuration in case of container or file initialisation, use this.
                        $this->serviceClassNames[$serviceName] = $cn;
                        goto finish;
                    }
                }

                // If nothing worked before, finally load the instance
                if($forced)
                    $this->serviceClassNames[$serviceName] = get_class( $container->getInstance() );
            } else {
                // Mark as not existing
                $this->serviceClassNames[$serviceName] = false;
            }
        }

        finish:

        return $this->serviceClassNames[$serviceName] ?: NULL;
    }
public function getServiceClass ( string $ serviceName , bool $ forced = true ) : ? string { if ( ! isset ( $ this -> serviceClassNames [ $ serviceName ] ) ) { if ( $ this -> serviceExists ( $ serviceName ) ) { /** @var ContainerInterface $container */ $ container = $ this -> serviceData [ $ serviceName ] ; if ( $ container -> isInstanceLoaded ( ) ) { $ this -> serviceClassNames [ $ serviceName ] = get_class ( $ container -> getInstance ( ) ) ; goto finish ; } if ( $ container instanceof ServiceAwareContainerInterface ) { $ this -> serviceClassNames [ $ serviceName ] = $ container -> getServiceClass ( ) ; goto finish ; } elseif ( $ container instanceof ConfiguredServiceContainer ) { $ cfg = $ container -> getConfiguration ( ) ; // In case of a direct instance fonciguration, get this classname if ( $ cn = $ cfg [ AbstractFileConfiguration :: SERVICE_CLASS ] ?? NULL ) { $ this -> serviceClassNames [ $ serviceName ] = $ cn ; goto finish ; } elseif ( $ cn = $ cfg [ AbstractFileConfiguration :: CONFIG_SERVICE_TYPE_KEY ] ?? NULL ) { // If the developer defined the class by configuration in case of container or file initialisation, use this. $ this -> serviceClassNames [ $ serviceName ] = $ cn ; goto finish ; } } // If nothing worked before, finally load the instance if ( $ forced ) $ this -> serviceClassNames [ $ serviceName ] = get_class ( $ container -> getInstance ( ) ) ; } else { // Mark as not existing $ this -> serviceClassNames [ $ serviceName ] = false ; } } finish : return $ this -> serviceClassNames [ $ serviceName ] ? : NULL ; }
Gets the class of a service instance

@param string $serviceName
@param bool $forced      // If set, it will until load the service to get its class name
@return string|null
Gets the class of a service instance