Apply the default values required by the AdminInterface to the Admin service definition.

@param string $serviceId

@return Definition
336603
public function applyDefaults(ContainerBuilder $container, $serviceId, array $attributes = [])
    {
        $definition = $container->getDefinition($serviceId);
        $settings = $container->getParameter('sonata.admin.configuration.admin_services');

        $definition->setShared(false);

        $manager_type = $attributes['manager_type'];

        $overwriteAdminConfiguration = $settings[$serviceId] ?? [];

        $defaultAddServices = [
            'model_manager' => sprintf('sonata.admin.manager.%s', $manager_type),
            'form_contractor' => sprintf('sonata.admin.builder.%s_form', $manager_type),
            'show_builder' => sprintf('sonata.admin.builder.%s_show', $manager_type),
            'list_builder' => sprintf('sonata.admin.builder.%s_list', $manager_type),
            'datagrid_builder' => sprintf('sonata.admin.builder.%s_datagrid', $manager_type),
            'translator' => 'translator',
            'configuration_pool' => 'sonata.admin.pool',
            'route_generator' => 'sonata.admin.route.default_generator',
            'validator' => 'validator',
            'security_handler' => 'sonata.admin.security.handler',
            'menu_factory' => 'knp_menu.factory',
            'route_builder' => 'sonata.admin.route.path_info'.
                (('doctrine_phpcr' === $manager_type) ? '_slashes' : ''),
            'label_translator_strategy' => 'sonata.admin.label.strategy.native',
        ];

        $definition->addMethodCall('setManagerType', [$manager_type]);

        foreach ($defaultAddServices as $attr => $addServiceId) {
            $method = 'set'.Inflector::classify($attr);

            if (isset($overwriteAdminConfiguration[$attr]) || !$definition->hasMethodCall($method)) {
                $args = [new Reference($overwriteAdminConfiguration[$attr] ?? $addServiceId)];
                if ('translator' === $attr) {
                    $args[] = false;
                }

                $definition->addMethodCall($method, $args);
            }
        }

        if (isset($overwriteAdminConfiguration['pager_type'])) {
            $pagerType = $overwriteAdminConfiguration['pager_type'];
        } elseif (isset($attributes['pager_type'])) {
            $pagerType = $attributes['pager_type'];
        } else {
            $pagerType = Pager::TYPE_DEFAULT;
        }

        $definition->addMethodCall('setPagerType', [$pagerType]);

        if (isset($overwriteAdminConfiguration['label'])) {
            $label = $overwriteAdminConfiguration['label'];
        } elseif (isset($attributes['label'])) {
            $label = $attributes['label'];
        } else {
            $label = '-';
        }

        $definition->addMethodCall('setLabel', [$label]);

        $persistFilters = $container->getParameter('sonata.admin.configuration.filters.persist');
        // override default configuration with admin config if set
        if (isset($attributes['persist_filters'])) {
            $persistFilters = $attributes['persist_filters'];
        }
        $filtersPersister = $container->getParameter('sonata.admin.configuration.filters.persister');
        // override default configuration with admin config if set
        if (isset($attributes['filter_persister'])) {
            $filtersPersister = $attributes['filter_persister'];
        }
        // configure filters persistence, if configured to
        if ($persistFilters) {
            $definition->addMethodCall('setFilterPersister', [new Reference($filtersPersister)]);
        }

        if (isset($overwriteAdminConfiguration['show_mosaic_button'])) {
            $showMosaicButton = $overwriteAdminConfiguration['show_mosaic_button'];
        } elseif (isset($attributes['show_mosaic_button'])) {
            $showMosaicButton = $attributes['show_mosaic_button'];
        } else {
            $showMosaicButton = $container->getParameter('sonata.admin.configuration.show.mosaic.button');
        }

        $definition->addMethodCall('showMosaicButton', [$showMosaicButton]);

        $this->fixTemplates(
            $serviceId,
            $container,
            $definition,
            $overwriteAdminConfiguration['templates'] ?? ['view' => []]
        );

        if ($container->hasParameter('sonata.admin.configuration.security.information') && !$definition->hasMethodCall('setSecurityInformation')) {
            $definition->addMethodCall('setSecurityInformation', ['%sonata.admin.configuration.security.information%']);
        }

        $definition->addMethodCall('initialize');

        return $definition;
    }
44486
private function manageInheritance()
    {
        $config = $this->serviceConfig;
        if ($config->keyExists('Parent')) {
            $parentServiceName = $this->str($config->key('Parent'))->trimLeft('@')->val();
            $parentConfig = ServiceManager::getInstance()->getServiceConfig($parentServiceName)->toArray(true);
            if (!$parentConfig->keyExists('Abstract')) {
                throw new ServiceManagerException(ServiceManagerException::SERVICE_IS_NOT_ABSTRACT,
                                                  [$config->key('Parent')]
                );
            }
            $config = $this->extendConfig($config, $parentConfig);
        }

        // Check if it's a potentially valid service definition
        if (!$config->keyExists('Class') && !$config->keyExists('Factory')) {
            throw new ServiceManagerException(ServiceManagerException::SERVICE_CLASS_KEY_NOT_FOUND,
                                              [$this->serviceName]
            );
        }

        $this->serviceConfig = $config;
    }
433060
private function initializeService($serviceId, array $constructorArguments) {
		
		if(!isset($this->config->services[$serviceId])) {
			throw new ApplicationException(sprintf("Service '%s' not configured.", $serviceId));
		}

		$configData = $this->config->services[$serviceId];

		// get class name

		$class	= $configData['class'];

		// create instance and pass additional parameters to constructor

		try {
			$service = new $class(...$constructorArguments);
		}
		catch(\Exception $e) {
			throw new ApplicationException(sprintf("Instancing of service '%s' failed. Error: %s", $serviceId, $e->getMessage()));
		}

		// check whether instance implements ServiceInterface  

		if(!$service instanceof ServiceInterface) {
			throw new ApplicationException(sprintf("Service '%s' (class %s) does not implement the ServiceInterface.", $serviceId, $class));
		}

		// set parameters
		
		$service->setParameters($configData['parameters']);
		
		return $service;

	}
127540
public function setAlias($existsId, $newId) {
		if (isset($this->_definitions[$newId])) {
			throw new Exceptions\ServiceOverride('Service "' . $newId . '" already exists');
		}
		
		$this->_definitions[$newId] = $this->getDefinition($existsId);
	}
768812
public function deleteRoleDraft($roleId)
    {
        $this->roleService->deleteRoleDraft(
            $this->roleService->loadRoleDraft($roleId)
        );

        return new Values\NoContent();
    }
1216448
public function build($id)
    {
        if ($this->internalContainer->offsetExists($id)) {
            return $this->internalContainer->offsetGet($id);
        }

        if ($this->externalContainer && $this->externalContainer->has($id)) {
            return $this->externalContainer->get($id);
        }

        throw new ServiceNotFoundException("Service '$id' not found in any of the containers.");
    }
1022512
public function setServiceName($serviceName)
    {
        $allowedValues = $this->getServiceNameAllowableValues();
        if (!in_array($serviceName, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'serviceName', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['serviceName'] = $serviceName;

        return $this;
    }
1322177
public function wrapService($serviceId, $instance)
    {
        $serviceId = $this->canonicalizeName($serviceId);
        $proxy = null;
        
        if (($fqcn = $this->getCache()->getItem(self::CACHE_ID_PREFIX . $serviceId)) 
             && class_exists($fqcn) 
             && $this->getProxyAutoCreateStrategy() !== self::PROXY_AUTO_CREATE_ALWAYS) {
            
            $proxy = new $fqcn($instance);
        } else {
            $className      = get_class($instance);
            $proxyGenerator = $this->getProxyGenerator();
            $fqcn           = $proxyGenerator->getProxyClassName($className);
            $file           = $proxyGenerator->getProxyFilename($className);
            
            // Re-generate proxy class if original service class file has changed
            if ($this->getProxyAutoCreateStrategy() === self::PROXY_AUTO_CREATE_MTIME && file_exists($file)) {
                $reflection = new ReflectionClass($className);
                $instanceFile = $reflection->getFileName();
                
                if (filemtime($instanceFile) > filemtime($file)) {
                    unlink($file);
                }
            }

            if (!file_exists($file) || $this->getProxyAutoCreateStrategy() === self::PROXY_AUTO_CREATE_ALWAYS) {
                try {
                    $config = $this->getAnnotationBuilder()->getServiceSpecification($instance);
                } catch(\Exception $e) {
                    throw new AnnotationException(
                        sprintf('Unable to parse annotations for service %s (%s). Reason: %s', $serviceId, $file, $e->getMessage()));
                }
                
                $config['service_id'] = $serviceId; // Overwrite any previously configured service ID
                
                $proxyGenerator->generateProxyClass($instance, $config);
            }
            
            require_once $file;
            $proxy = new $fqcn($instance);
            
            $this->getCache()->setItem(self::CACHE_ID_PREFIX . $serviceId, $fqcn);
        }
        
        // Run initializers for the proxy class
        foreach ($this->initializers as $initializer) {
            if ($initializer instanceof InitializerInterface) {
                $initializer->initialize($proxy, $this);
            } elseif (is_object($initializer) && is_callable($initializer)) {
                $initializer($proxy, $this);
            } else {
                call_user_func($initializer, $proxy, $this);
            }
        }
        
        return $proxy;
    }
957579
protected function _getOrderServiceItem( $baseid )
	{
		$orderServiceManager = MShop_Factory::createManager( $this->_getContext(), 'order/base/service' );

		$search = $orderServiceManager->createSearch();
		$expr = array(
			$search->compare( '==', 'order.base.service.baseid', $baseid ),
			$search->compare( '==', 'order.base.service.type', 'payment' )
		);
		$search->setConditions( $search->combine( '&&', $expr ) );

		$results = $orderServiceManager->searchItems( $search );

		if ( ( $serviceItem = reset( $results ) ) === false )
		{
			$msg = sprintf( 'Service payment provider for order base ID "%1$s" not found', $baseid );
			throw new MShop_Service_Exception( $msg );
		}

		return $serviceItem;
	}
1045289
final public function get(string $id): ServiceConfigurator
    {
        $this->__destruct();

        return $this->parent->get($id);
    }
952547
private function getDefinitionForServiceId($serviceId, ServiceConfig $serviceConfig)
    {

        if ($serviceConfig->has(ServiceConfig::LAZY) && !$serviceConfig->get(ServiceConfig::LAZY)) {
            return new Reference($serviceId);
        } else {
            return new Definition($this->invokeClass, array(new Reference('service_container'), $serviceId));
        }
    }
880546
private function getServiceOrParameter($id)
    {
        if (array_key_exists($id, $this->aliases)) {
            return $this->offsetGet($this->aliases[$id]);
        }

        if (array_key_exists($id, $this->values)) {
            return $this->values[$id];
        }

        if (array_key_exists($id, $this->definitions)) {
            return $this->values[$id] = $this->build($this->definitions[$id]);
        }

        throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
    }
246962
public function get_ws_authorised_users($serviceid) {
        global $DB, $CFG;
        $params = array($CFG->siteguest, $serviceid);
        $sql = " SELECT u.id as id, esu.id as serviceuserid, u.email as email, u.firstname as firstname,
                        u.lastname as lastname,
                        esu.iprestriction as iprestriction, esu.validuntil as validuntil,
                        esu.timecreated as timecreated
                   FROM {user} u, {external_services_users} esu
                  WHERE u.id <> ? AND u.deleted = 0 AND u.confirmed = 1
                        AND esu.userid = u.id
                        AND esu.externalserviceid = ?";

        $users = $DB->get_records_sql($sql, $params);
        return $users;
    }
1318293
public function setDefault($websiteId)
    {
        /** @var ConfigInterface $config */
        $config = $this->configFactory->create();

        $foundDifference = false;

        foreach ($this->defaultConfig as $key => $value) {
            if ($config->setConfigValue($key, $value, $websiteId)) {
                $foundDifference = true;
            }
        }

        if ($foundDifference) {
            $config->cleanScope();
        }

        return $this->statusResponseFactory->create()
            ->setStatus('ok');
    }
313905
protected function serviceFromDefinition($id, $args)
    {
        // create the service object
        $service = $this->createServiceObject($id, $args);

        // run predefined methods if any
        $this->runDefinedMethods($id, $service);

        // decorate the service if DecorateExtension loaded
        $this->decorateService($service);

        return $service;
    }
1056828
public function getProvider( $serviceId )
	{
		$item = $this->manager->getItem( $serviceId, $this->domains, true );
		return $this->manager->getProvider( $item, $item->getType() );
	}
1018476
public static function oneById($serviceName, $id)
	{
		if(!self::has($serviceName)) {
			return null;
		}
		/** @var ReadOneInterface $serviceInstance */
		$serviceInstance = self::get($serviceName);
		try {
			$result = $serviceInstance->oneById($id);
		} catch (NotFoundHttpException $e) {
			$result = null;
		}
		return $result;
	}