@param string $serviceId
@param string $modelClass
@param string $adminClass
@param string $controllerName
@param string $managerType

@throws \RuntimeException
341123
public function addResource($serviceId, $modelClass, $adminClass, $controllerName, $managerType)
    {
        $rc = new \ReflectionClass($modelClass);
        $modelClassShortName = $rc->getShortName();

        $code = "services:\n";

        if (is_file($this->file)) {
            $code = rtrim(file_get_contents($this->file));
            $data = (array) Yaml::parse($code);

            if ($code !== '') {
                $code .= "\n";
            }

            if (array_key_exists('services', $data)) {
                if (array_key_exists($serviceId, (array) $data['services'])) {
                    throw new \RuntimeException(sprintf(
                        'The service "%s" is already defined in the file "%s".',
                        $serviceId,
                        realpath($this->file)
                    ));
                }

                if ($data['services'] !== null) {
                    $code .= "\n";
                }
            } else {
                $code .= $code === '' ? '' : "\n" . "services:\n";
            }
        }

        $code .= sprintf(
            $this->template,
            $serviceId,
            $adminClass,
            $modelClass,
            $controllerName,
            $modelClassShortName,
            $managerType,
            current(array_slice(explode('\\', $modelClass), -1))
        );
        @mkdir(dirname($this->file), 0777, true);

        if (@file_put_contents($this->file, $code) === false) {
            throw new \RuntimeException(sprintf(
                'Unable to append service "%s" to the file "%s". You will have to do it manually.',
                $serviceId,
                $this->file
            ));
        }
    }
1128509
public function init(ModuleManagerInterface $manager)
    {
        if (!$manager instanceof ModuleManager) {
            $errMsg =sprintf('Module manager not implement %s', ModuleManager::class);
            throw new Exception\InvalidArgumentException($errMsg);
        }

        
        /** @var ServiceLocatorInterface $sm */
        $sm = $manager->getEvent()->getParam('ServiceManager');

        if (!$sm instanceof ServiceLocatorInterface) {
            $errMsg = sprintf('Service locator not implement %s', ServiceLocatorInterface::class);
            throw new Exception\InvalidArgumentException($errMsg);
        }
        /** @var ServiceListenerInterface $serviceListener */
        $serviceListener = $sm->get('ServiceListener');
        if (!$serviceListener instanceof ServiceListenerInterface) {
            $errMsg = sprintf('ServiceListener not implement %s', ServiceListenerInterface::class);
            throw new Exception\InvalidArgumentException($errMsg);
        }


        $serviceListener->addServiceManager(
            EntryNameResolverManagerInterface::class,
            EntryNameResolverManager::CONFIG_KEY,
            EntryNameResolverProviderInterface::class,
            'getEntryNameResolverConfig'
        );

    }
1023340
public function attach(EventManagerInterface $events)
    {
        $events->attach(
            MvcEvent::EVENT_RENDER,
            function (MvcEvent $event) {
                /** @var ServiceManager $serviceManager */
                $serviceManager = $event->getTarget()->getServiceManager();
                /** @var ControllerManager $controllerManager */
                $controllerManager = $serviceManager->get('ControllerManager');
                $routeMatch = $event->getRouteMatch();
                if ($routeMatch) {
                    $controller = $controllerManager->get($routeMatch->getParam('controller'));
                    $viewHelperManager = $serviceManager->get('ViewHelperManager');
                    /** @var Widget $widgetViewHelper */
                    $widgetViewHelper = $viewHelperManager->get('widget');
                    $widgetViewHelper->setController($controller);
                }
            },
            $this->priority
        );
    }
479206
public function registerHandler(string $queryClass, string $serviceName): void
    {
        if (!Validate::implementsInterface($queryClass, Query::class)) {
            $message = sprintf('Invalid query class: %s', $queryClass);
            throw new DomainException($message);
        }

        $type = Type::create($queryClass)->toString();

        $this->handlers[$type] = $serviceName;
    }
1289487
public function onDispatch(MvcEvent $e)
    {
        $console = $this->getServiceLocator()->get('Console');
        if (!$console instanceof ConsoleAdapterInterface) {
            throw new \DomainException('Could not find console service. Are you sure this was invoked from command line?');
        }

        $manager = $this->getServiceLocator()->get('ModuleManager');
        if (!$manager instanceof ModuleManager) {
            $console->write('Could not find module manager - exit!' . "\n", ColorInterface::RED);
            return;
        }

        foreach ($manager->getLoadedModules() as $name => $module) {
            if (!is_callable(array($module, 'compile'))) {
                continue;
            }

            $console->write(sprintf('Compiling module "%s" ...' . "\n", $name));
            $module->compile();
        }

        $console->write('Done!' . "\n\n", ColorInterface::LIGHT_GREEN);
    }
1056828
public function getProvider( $serviceId )
	{
		$item = $this->manager->getItem( $serviceId, $this->domains, true );
		return $this->manager->getProvider( $item, $item->getType() );
	}
520254
public function loadConfiguration(): void
	{
		if (!class_exists('Symfony\Component\Console\Application')) {
			throw new ServiceCreationException('Missing Symfony\Component\Console\Application service');
		}

		// Skip if it's not CLI mode
		if (!$this->cliMode) return;

		$builder = $this->getContainerBuilder();

		// Helpers
		$builder->addDefinition($this->prefix('connectionHelper'))
			->setFactory(ConnectionHelper::class)
			->setAutowired(false);

		//Commands
		$builder->addDefinition($this->prefix('importCommand'))
			->setFactory(ImportCommand::class)
			->addTag('console.command', 'dbal:import')
			->setAutowired(false);

		$builder->addDefinition($this->prefix('reservedWordsCommand'))
			->setFactory(ReservedWordsCommand::class)
			->addTag('console.command', 'dbal:reserved-words')
			->setAutowired(false);

		$builder->addDefinition($this->prefix('runSqlCommand'))
			->setFactory(RunSqlCommand::class)
			->addTag('console.command', 'dbal:run-sql')
			->setAutowired(false);
	}
252111
public function setModelId($modelId)
    {
        $this->modelId = (string)$modelId;
        $this->model   = null;
        return $this;
    }
1326925
public function generate(BundleInterface $bundle, $adminClassBasename, $modelClass)
    {
        $this->class = sprintf('%s\Admin\%s', $bundle->getNamespace(), $adminClassBasename);
        $this->file = sprintf('%s/Admin/%s.php', $bundle->getPath(), str_replace('\\', '/', $adminClassBasename));
        $parts = explode('\\', $this->class);

        if (file_exists($this->file)) {
            throw new \RuntimeException(sprintf(
                'Unable to generate the admin class "%s". The file "%s" already exists.',
                $this->class,
                realpath($this->file)
            ));
        }

        // Manage route pattern generation
        $routes = $parts;
        array_walk($routes, function (&$item, $k) use (&$routes) {
            $item = preg_replace('/(admin)|(bundle)/', '', strtolower($item));
            if ($item == '') {
                array_splice($routes, $k, 1);
            }
        });

        $this->renderFile('Admin.php.twig', $this->file, array(
            'route_name'    => implode('_', array_map('strtolower', $routes)),
            'classBasename' => array_pop($parts),
            'namespace'     => implode('\\', $parts),
            'fields'        => $this->modelManager->getExportFields($modelClass),
        ));
    }
845852
public function getService($serviceClass, $clientCustomerId = null, $credentials = null)
    {
        $adwordsServices = new AdWordsServices();

        $session = $this->session($clientCustomerId, $credentials);

        return $adwordsServices->get($session, $serviceClass);
    }
400732
public function createService(ServiceLocatorInterface $controllerManager)
    {
        /* @var ControllerManager $controllerManager*/
        $serviceManager = $controllerManager->getServiceLocator();

        return $this->__invoke($serviceManager, null);
    }
1327880
final protected function getFormAdminType(FormMapper $formMapper, AdminInterface $admin, $formField, $field, $fieldOptions = [], $adminOptions = [])
    {
        $adminOptions = array_merge([
            'edit' => 'list',
            'translation_domain' => 'SonataClassificationBundle',
        ], $adminOptions);

        $fieldDescription = $admin->getModelManager()->getNewFieldDescriptionInstance($admin->getClass(), $field, $adminOptions);
        $fieldDescription->setAssociationAdmin($admin);
        $fieldDescription->setAdmin($formMapper->getAdmin());
        $fieldDescription->setAssociationMapping([
            'fieldName' => $field,
            'type' => ClassMetadataInfo::MANY_TO_ONE,
        ]);

        $fieldOptions = array_merge([
            'sonata_field_description' => $fieldDescription,
            'class' => $admin->getClass(),
            'model_manager' => $admin->getModelManager(),
            'required' => false,
        ], $fieldOptions);

        return $formMapper->create($formField, ModelTypeList::class, $fieldOptions);
    }
1341155
private function buildServiceConfig()
    {
        if ($this->serviceConfig->keyExists('Factory') && !$this->serviceConfig->keyExists('Method')) {
            throw new ServiceManagerException(ServiceManagerException::FACTORY_SERVICE_METHOD_KEY_MISSING,
                                              [$this->serviceName]
            );
        }

        $config = new ServiceConfig();
        $config->setClass($this->serviceConfig->key('Class', null, true));
        $config->setArguments($this->serviceConfig->key('Arguments', [], true));
        $config->setCalls($this->serviceConfig->key('Calls', [], true));
        $config->setScope($this->serviceConfig->key('Scope', ServiceScope::CONTAINER, true));
        $config->setFactory($this->serviceConfig->key('Factory', null, true));
        $config->setMethod($this->serviceConfig->key('Method', null, true));
        $config->setMethodArguments($this->serviceConfig->key('MethodArguments'));
        $config->setStatic($this->serviceConfig->key('Static', true, true));

        return $config;
    }
878757
public function find(Driver $driver, $modelClass, $id)
    {
        $this->managerFactory->setModelClass($modelClass);

        return $this->managerFactory->getManager($driver)->find($id);
    }
1068619
public function delete_service($serviceid) {
        global $DB;
        $DB->delete_records('external_services_users', array('externalserviceid' => $serviceid));
        $DB->delete_records('external_services_functions', array('externalserviceid' => $serviceid));
        $DB->delete_records('external_tokens', array('externalserviceid' => $serviceid));
        $DB->delete_records('external_services', array('id' => $serviceid));
    }
47663
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager */
        $moduleOptionsPluginManager = $serviceLocator->get(ModuleOptionsPluginManagerInterface::class);
        /** @var ModuleOptionsInterface $moduleOptions */
        $moduleOptions = $moduleOptionsPluginManager->get(ModuleOptionsInterface::class);

        $managerRegistryOptions = $moduleOptions->getManagerRegistry();


        $buildListConnectionsResult = $this->getEventManager()->trigger(static::EVENT_BUILD_LIST_CONNECTIONS, $this);
        $listConnectionsResult = [];
        foreach ($buildListConnectionsResult as $item) {
            if (is_array($item)) {
                $listConnectionsResult = ArrayUtils::merge($listConnectionsResult, $item);
            }
        }
        $listConnectionsResult = ArrayUtils::merge($listConnectionsResult, $managerRegistryOptions->getConnections());


        $buildListObjectManagersResult = $this->getEventManager()->trigger(static::EVENT_BUILD_LIST_OBJECT_MANAGERS, $this);
        $listObjectManagersResult = [];
        foreach ($buildListObjectManagersResult as $item) {
            if (is_array($item)) {
                $listObjectManagersResult = ArrayUtils::merge($listObjectManagersResult, $item);
            }
        }
        $listObjectManagersResult = ArrayUtils::merge($listObjectManagersResult, $managerRegistryOptions->getObjectManagers());

        return new ManagerRegistry(
            ManagerRegistry::NAME,
            $listConnectionsResult,
            $listObjectManagersResult,
            $managerRegistryOptions->getDefaultConnection(),
            $managerRegistryOptions->getDefaultManager(),
            $managerRegistryOptions->getProxyInterfaceName()
        );
    }
1357487
@Transactional
    public static ServiceManagementRecord updateServiceManagementRecord(EntityManager em, ServiceManagementRecord record) {
        SystemAssert.requireArgument(em != null, "Entity manager can not be null.");
        SystemAssert.requireArgument(record != null, "ServiceManagementRecord cannot be null.");

        TypedQuery<ServiceManagementRecord> query = em.createNamedQuery("ServiceManagementRecord.findByService", ServiceManagementRecord.class);

        query.setParameter("service", record.getService());
        try {
            ServiceManagementRecord oldRecord = query.getSingleResult();

            oldRecord.setEnabled(record.isEnabled());
            return em.merge(oldRecord);
        } catch (NoResultException ex) {
            return em.merge(record);
        }
    }