@param ContainerBuilder $container
@param Reference[]      $refMap
@param string|null      $callerId

@return Reference
330797
public static function register(ContainerBuilder $container, array $refMap, $callerId = null)
    {
        foreach ($refMap as $id => $ref) {
            if (!$ref instanceof Reference) {
                throw new InvalidArgumentException(sprintf('Invalid service locator definition: only services can be referenced, "%s" found for key "%s". Inject parameter values using constructors instead.', is_object($ref) ? get_class($ref) : gettype($ref), $id));
            }
            $refMap[$id] = new ServiceClosureArgument($ref);
        }
        ksort($refMap);

        $locator = (new Definition(ServiceLocator::class))
            ->addArgument($refMap)
            ->setPublic(false)
            ->addTag('container.service_locator');

        if (!$container->has($id = 'service_locator.'.ContainerBuilder::hash($locator))) {
            $container->setDefinition($id, $locator);
        }

        if (null !== $callerId) {
            $locatorId = $id;
            // Locators are shared when they hold the exact same list of factories;
            // to have them specialized per consumer service, we use a cloning factory
            // to derivate customized instances from the prototype one.
            $container->register($id .= '.'.$callerId, ServiceLocator::class)
                ->setPublic(false)
                ->setFactory(array(new Reference($locatorId), 'withContext'))
                ->addArgument($callerId)
                ->addArgument(new Reference('service_container'));
        }

        return new Reference($id);
    }
826685
protected function withRootEntityMapper(IEntityMapper $mapper, callable $callback)
    {
        $oldMapper              = $this->rootEntityMapper;
        $this->rootEntityMapper = $mapper;
        $result                 = $callback();
        $this->rootEntityMapper = $oldMapper;

        return $result;
    }
951050
public function process(ContainerBuilder $container)
    {
        if ($container->hasDefinition($this->workflowRegistry)) {
            $workflowRegistry = new Reference($this->workflowRegistry);

            foreach ($container->findTaggedServiceIds($this->pathReducerTag, true) as $serviceId => $attributes) {
                $pathReducer = $container->getDefinition($serviceId);
                $pathReducer->addMethodCall('setWorkflowRegistry', [$workflowRegistry]);
            }

            $executeTaskCommandDefinition = $container->getDefinition(ExecuteTaskCommand::class);
            $executeTaskCommandDefinition->addMethodCall('setWorkflowRegistry', [$workflowRegistry]);

            $generatePathCommandDefinition = $container->getDefinition(GeneratePathCommand::class);
            $generatePathCommandDefinition->addMethodCall('setWorkflowRegistry', [$workflowRegistry]);

            $captureScreenshotsCommandDefinition = $container->getDefinition(CaptureScreenshotsCommand::class);
            $captureScreenshotsCommandDefinition->addMethodCall('setWorkflowRegistry', [$workflowRegistry]);

            $modelValidatorDefinition = $container->getDefinition(ModelValidator::class);
            $modelValidatorDefinition->addMethodCall('setWorkflowRegistry', [$workflowRegistry]);

            if ($container->hasDefinition(MakeSubject::class)) {
                $makeSubjectDefinition = $container->getDefinition(MakeSubject::class);
                $makeSubjectDefinition->addMethodCall('setWorkflowRegistry', [$workflowRegistry]);
            }
        }
    }
929213
public function build($incoming, Map $context = null)
    {
        $callable = $this->getDelegateBuilder();

        if (null === $context && $this->provide_fallback_context) {
            // Provide a non-null context so null checks aren't later required
            $context = new Map();
        }

        return $callable($incoming, $context);
    }
1374582
public function byId($callerClass, $id, $cache = true, $requiredPerm = 'View')
    {
        $id = (int) $id;
        $item = DataObject::get_by_id($callerClass, $id, $cache);
        if ($item && $item->hasExtension('Restrictable') && $item->checkPerm($requiredPerm)) {
            return $item;
        }
        
        if ($item && !$item->hasExtension('Restrictable') && $item->canView()) {
            return $item;
        }
    }
485501
public function addReference($ruleKey, $columns, $refTableClass, $refColumns,
                                 $onDelete = null, $onUpdate = null)
    {
        $reference = array(self::COLUMNS         => (array) $columns,
                           self::REF_TABLE_CLASS => $refTableClass,
                           self::REF_COLUMNS     => (array) $refColumns);

        if (!empty($onDelete)) {
            $reference[self::ON_DELETE] = $onDelete;
        }

        if (!empty($onUpdate)) {
            $reference[self::ON_UPDATE] = $onUpdate;
        }

        $this->_referenceMap[$ruleKey] = $reference;

        return $this;
    }
291030
public static void showDialog(final CmsUUID referenceId, final AsyncCallback<String> createModeCallback) {

        CmsRpcAction<CmsListInfoBean> action = new CmsRpcAction<CmsListInfoBean>() {

            @Override
            public void execute() {

                start(0, true);
                CmsCoreProvider.getVfsService().getPageInfo(referenceId, this);

            }

            @Override
            protected void onResponse(CmsListInfoBean result) {

                stop(false);
                (new CmsDroppedElementModeSelectionDialog(result, createModeCallback)).center();
            }
        };
        action.execute();

    }
1033075
protected function createDoctrineMappingDriver(ContainerBuilder $container, $driverId, $driverClass)
    {
        $driverDefinition = new Definition($driverClass, array(
            array(realpath(__DIR__.'/../Resources/config/model') => 'Lexik\Bundle\TranslationBundle\Model'),
        ));
        $driverDefinition->setPublic(false);

        $container->setDefinition($driverId, $driverDefinition);
    }
170325
public function flatMap(callable $callback, $depth = INF): CollectionInterface
    {
        return $this->map($callback)->flatten($depth);
    }
474305
public function createDBRef($document, array $referenceMapping = null)
    {
        if ( ! is_object($document)) {
            throw new \InvalidArgumentException('Cannot create a DBRef, the document is not an object');
        }

        $class = $this->getClassMetadata(get_class($document));
        $id = $this->unitOfWork->getDocumentIdentifier($document);

        if (!$id) {
            throw new \RuntimeException(
                sprintf('Cannot create a DBRef without an identifier. UnitOfWork::getDocumentIdentifier() did not return an identifier for class %s', $class->name)
            );
        }

        if ( ! empty($referenceMapping['simple'])) {
            return $class->getDatabaseIdentifierValue($id);
        }

        $dbRef = array(
            '$ref' => $class->getCollection(),
            '$id'  => $class->getDatabaseIdentifierValue($id),
            '$db'  => $this->getDocumentDatabase($class->name)->getName(),
        );

        /* If the class has a discriminator (field and value), use it. A child
         * class that is not defined in the discriminator map may only have a
         * discriminator field and no value, so default to the full class name.
         */
        if (isset($class->discriminatorField)) {
            $dbRef[$class->discriminatorField] = isset($class->discriminatorValue)
                ? $class->discriminatorValue
                : $class->name;
        }

        /* Add a discriminator value if the referenced document is not mapped
         * explicitly to a targetDocument class.
         */
        if ($referenceMapping !== null && ! isset($referenceMapping['targetDocument'])) {
            $discriminatorField = $referenceMapping['discriminatorField'];
            $discriminatorValue = isset($referenceMapping['discriminatorMap'])
                ? array_search($class->name, $referenceMapping['discriminatorMap'])
                : $class->name;

            /* If the discriminator value was not found in the map, use the full
             * class name. In the future, it may be preferable to throw an
             * exception here (perhaps based on some strictness option).
             *
             * @see PersistenceBuilder::prepareEmbeddedDocumentValue()
             */
            if ($discriminatorValue === false) {
                $discriminatorValue = $class->name;
            }

            $dbRef[$discriminatorField] = $discriminatorValue;
        }

        return $dbRef;
    }
417500
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new ViewReferenceBuilderCompilerPass());
        $container->addCompilerPass(new ViewReferenceTransformerCompilerPass());
        $container->addCompilerPass(new ViewReferenceConnectorCompilerPass());
    }
1144923
protected function _getRefItems( array $refIdMap )
	{
		$items = array();
		$context = $this->_getContext();

		foreach( $refIdMap as $domain => $list )
		{
			try
			{
				$manager = MShop_Factory::createManager( $context, $domain );

				$search = $manager->createSearch( true );
				$expr = array(
					$search->compare( '==', str_replace( '/', '.', $domain ) . '.id', array_keys( $list ) ),
					$search->getConditions(),
				);
				$search->setConditions( $search->combine( '&&', $expr ) );
				$search->setSlice( 0, 0x7fffffff );

				foreach( $manager->searchItems( $search ) as $id => $item )
				{
					foreach( $list[ $id ] as $parentId ) {
						$items[ $parentId ][ $domain ][ $id ] = $item;
					}
				}
			}
			catch( MShop_Exception $e )
			{
				$logger = $context->getLogger();
				$logger->log( sprintf( 'Item referenced in domain "%1$s" not found: %2$s', $domain, $e->getMessage() ) );
				$logger->log( $e->getTraceAsString() );
			}
		}

		return $items;
	}
1055870
public function process(ContainerBuilder $container)
    {
        $taggedServices = $container->findTaggedServiceIds($this->tagName);
        foreach ($taggedServices as $id => $tags) {

            $reference = new Reference($id);
            foreach ($tags as $attr) {

                $tag = $this->getAttribute($id, $attr, 'tag');
                $method = $this->getAttribute($id, $attr, 'method');

                $this->injectInto($reference, $container, $tag, $method);
            }
        }
    }
136832
public static function createCallback(string $name, callable $callback): DenormalizationFieldMappingBuilderInterface
    {
        $self = new self($name);
        $self->fieldDenormalizer = new CallbackFieldDenormalizer($callback);

        return $self;
    }
226991
public function process(ContainerBuilder $container): void
    {
        $resolver = $container->findDefinition('fivelab.resource.serializer_resolver');
        $services = $container->findTaggedServiceIds('resource.serializer');

        foreach ($services as $serviceId => $tags) {
            try {
                $attributes = $tags[0];

                if (!array_key_exists('supportable', $attributes)) {
                    throw new \RuntimeException('The resource serializer should define with supportable instance. Please add the "supportable" attribute to "resource.assembler".');
                }

                $serializerDefinition = $container->getDefinition($serviceId);
                $serializerClass = $container->getParameterBag()->resolveValue($serializerDefinition->getClass());

                if (!is_a($serializerClass, ResourceSerializerInterface::class, true)) {
                    throw new \RuntimeException(sprintf(
                        'The resource serializer should implement "%s".',
                        ResourceSerializerInterface::class
                    ));
                }

                $supportableServiceId = $attributes['supportable'];

                $resolver->addMethodCall('add', [
                    new Reference($supportableServiceId),
                    new Reference($serviceId),
                ]);
            } catch (\Exception $e) {
                throw new \RuntimeException(sprintf(
                    'Can\'t compile resource serializer with service id "%s".',
                    $serviceId
                ), 0, $e);
            }
        }
    }
787392
public function process(ContainerBuilder $container)
    {
        if (!$container->has('support_tools.system_info.output_registry')) {
            return;
        }

        $outputFormattersTagged = $container->findTaggedServiceIds('support_tools.system_info.output_format');

        $outputFormatters = [];
        foreach ($outputFormattersTagged as $id => $tags) {
            foreach ($tags as $attributes) {
                $outputFormatters[$attributes['format']] = new Reference($id);
            }
        }

        $outputFormatRegistryDef = $container->findDefinition('support_tools.system_info.output_registry');
        $outputFormatRegistryDef->setArguments([$outputFormatters]);
    }
1371519
public function process(ContainerBuilder $container)
    {
        $service = $container->getDefinition("rms_push_notifications");

        foreach ($container->findTaggedServiceIds("rms_push_notifications.handler") as $id => $attributes) {
            if (!isset($attributes[0]["osType"])) {
                throw new \LogicException("Handler {$id} requires an osType attribute");
            }

            $definition = $container->getDefinition($id);

            // Get reflection class for validate handler
            try {
                $class = $definition->getClass();

                // Class is parameter
                if (strpos($class, '%') === 0) {
                    $class = $container->getParameter(trim($class, '%'));
                }

                $refClass = new \ReflectionClass($class);
            } catch (\ReflectionException $ref) {
                // Class not found or other reflection error
                throw new \RuntimeException(sprintf(
                    'Can\'t compile notification handler by service id "%s".',
                    $id
                ), 0, $ref);
            } catch (ParameterNotFoundException $paramNotFound) {
                // Parameter not found in service container
                throw new \RuntimeException(sprintf(
                    'Can\'t compile notification handler by service id "%s".',
                    $id
                ), 0, $paramNotFound);
            }

            // Required interface
            $requiredInterface = 'RMS\\PushNotificationsBundle\\Service\\OS\\OSNotificationServiceInterface';
            if (!$refClass->implementsInterface($requiredInterface)) {
                throw new \UnexpectedValueException(sprintf(
                   'Notification service "%s" by id "%s" must be implements "%s" interface!' ,
                   $refClass->getName(), $id, $requiredInterface
                ));
            }

            // Add handler to service notifications storage
            $service->addMethodCall("addHandler", array($attributes[0]["osType"], new Reference($id)));
        }
    }