{@inheritDoc}
@throws ReferenceException
424637
public function resolveService($arg, Container $container, $alias = "")
    {
        if (!is_string($alias)) {
            $alias = "";
        }
        if ($arg[0] == ContainerBuilder::SERVICE_CHAR) {
            $originalName = substr($arg, 1);
            $name = $this->aliasThisKey($originalName, $alias);
            // check if the service exists
            if (!$container->offsetExists($name)) {
                // check the un-aliased name
                $name = $originalName;

                if (!$container->offsetExists($name)) {
                    // check for private services if we have an alias to work with

                    $privateName = $originalName;
                    // alias the name if it wasn't already
                    if (!empty($alias) && strpos($originalName, $alias) === false) {
                        $privateName = $this->aliasThisKey($privateName, $alias);
                    }

                    // accessing private services from an unaliased context should always fail
                    if (
                        empty($alias) ||
                        empty($this->privateServices[$privateName]) || 
                        !$container->offsetExists($this->privateServices[$privateName])
                    ) {
                        // no private service either, or the private service key doesn't exist in the container (WTF?!)
                        throw new ReferenceException(sprintf("Tried to inject the service '%s', but it doesn't exist", $name));
                    }
                    
                    $name = $this->privateServices[$privateName];
                }

            }
            $arg = $container[$name];
        }
        return $arg;
    }
299266
public function visitReferenceValue(Value\ReferenceValue $reference)
    {
        $referenceUri = $this->uriResolver()->resolve(
            $reference->uri(),
            $this->currentBaseUri()
        );

        $resolution = $this->resolution($referenceUri);
        if (null !== $resolution) {
            return $resolution;
        }
        $resolution = $this->startResolution($referenceUri);

        if (!$value = $this->resolveInline($referenceUri, $reference)) {
            $value = $this->resolveExternal($referenceUri, $reference);
        }

        $this->completeResolution($referenceUri, $value);

        return $resolution;
    }
674448
public function setReference(ViewReference $reference = null, $locale = null)
    {
        $locale = $locale ?: $this->getCurrentLocale();
        $this->references[$locale] = $reference;

        return $this;
    }
583848
public function setReferenceId($referenceId)
    {
        $this->referenceId = $referenceId;
        $this->email = null;
        $this->executed = false;
        return $this;
    }
668139
public function prepareSource(&$source = null, $reference = false)
    {
        if (is_null($source)) {
            $raw = static::loadRawFromRequest();

            $this->data = json_decode($raw, true);

            if (!is_array($this->data)) {
                $this->data = [];
            }
        } else {
            if ($reference) {
                $this->data = &$source;
            } else {
                $this->data = $source;
            }
        }
    }
1348628
public function find(ReferenceableInterface $referenceable) {
        foreach( $this->generators->all() as $generator ) {
            if( $generator->canHandle($referenceable) ) {
                return $generator;
            }
        }
        
        return null;
    }
100981
public static function set_references( Base $entity, $name, $value = null )
    {

        $repository = $entity->r();
        if( !$repository->hasReference( $name, $detail ) ) {
            throw new EntityReferenceException("Bad reference `{$name}`");
        }

        // get existing references
        $existing = $repository->referencesGet( $entity, $name );

        $numObjectsChanged = 0;

        // container operations?
        if( $detail[2] ) {

            if( $value === null ) {

                $value = new Container();

            } elseif ( !( $value instanceof Container ) ) {
                throw new ContainerException(
                    sprintf(
                        "Reference is 1-many. You should be using containers. Passed %s",
                        print_r( $value, true )
                    )
                );
            }

            $unassociate = $existing
                ->diff( $value )
                ->each( Container::generateSetPropertyClosure( $detail[1], null ) );

            $numObjectsChanged += $unassociate->count();

            $new = $value
                ->diff( $existing )
                ->each( Container::generateSetPropertyClosure( $detail[1], $entity ) );

            $numObjectsChanged += $new->count();

        } else {

            // entity operation
            if( $entity !== $value ) {

                if( $existing ) {
                     $existing->set( $detail[1], null );
                     $numObjectsChanged++;
                }

                // add new association
                if( $value ) {
                    $value->set( $detail[1], $entity );
                     $numObjectsChanged++;
                }

            }

        }

        return $numObjectsChanged;

    }
1317237
public function addReferenceId($referenceId)
    {
        $this->referenceIds[] = $referenceId;
        $this->referenceIds = array_unique($this->referenceIds);

        return $this;
    }
1323672
public function setReference($reference)
    {
      if(!is_string($reference) || strlen(trim($reference)) == 0)
        throw new InvalidArgumentException(__METHOD__ . '; Invalid reference, must be a non empty string');

      $this->reference = $reference;
    }
412760
public function setClasspathRef(Reference $r): void
    {
        $this->classpathId = $r->getRefId();
        $this->createClasspath()->setRefid($r);
    }
772688
function it_should_replace_input_message_references_by_reference_html_link($reference1, $reference2) {
        $reference1->getStartIndice()->willReturn(5);
        $reference1->getEndIndice()->willReturn(10);
        $reference1->getType()->willReturn(ReferenceType::USER);
        $reference1->getData()->willReturn(array(
            "id"          => 6844292,
            "name"        => "John Doe",
            "type"        => "user",
            "offset"      => 5,
            "length"      => 5
        ));

        $reference2->getStartIndice()->willReturn(12);
        $reference2->getEndIndice()->willReturn(17);
        $reference2->getType()->willReturn(ReferenceType::PAGE);
        $reference2->getData()->willReturn(array(
            "id"          => 32425,
            "name"        => "test",
            "type"        => "page",
            "offset"      => 5,
            "length"      => 5
        ));

        $this->format('test @jdoe, @test bar', [$reference2, $reference1])
            ->shouldReturn('test <a href="https://www.facebook.com/6844292" target="_blank">@jdoe</a>, <a href="https://www.facebook.com/32425" target="_blank">@test</a> bar');

        $this->format('foo #média bar', [])
            ->shouldReturn('foo <a href="https://www.facebook.com/hashtag/média" target="_blank">#média</a> bar');

        $this->format('foo http://test.com bar', [])
            ->shouldReturn('foo <a href="http://test.com" target="_blank">http://test.com</a> bar');
    }
1004659
protected function resolveReferences()
    {
        $references = $this->config['references'] ?? [];

        if (! is_array($references) || empty($references)) {
            return;
        }

        foreach ($references as $config) {
            $this->resolveReference($config);
        }
    }
1043289
public function describeMachineReference($reference, $field = null)
	{
		if ($field === null) {
			return @ $this->references[$reference];
		} else {
			return @ $this->references[$reference][$field];
		}
	}
931570
public function createReference(object $document, array $referenceMapping)
    {
        $class = $this->getClassMetadata(get_class($document));
        $id    = $this->unitOfWork->getDocumentIdentifier($document);

        if ($id === null) {
            throw new RuntimeException(
                sprintf('Cannot create a DBRef for class %s without an identifier. Have you forgotten to persist/merge the document first?', $class->name)
            );
        }

        $storeAs = $referenceMapping['storeAs'] ?? null;
        switch ($storeAs) {
            case ClassMetadata::REFERENCE_STORE_AS_ID:
                if ($class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION) {
                    throw MappingException::simpleReferenceMustNotTargetDiscriminatedDocument($referenceMapping['targetDocument']);
                }

                return $class->getDatabaseIdentifierValue($id);
                break;

            case ClassMetadata::REFERENCE_STORE_AS_REF:
                $reference = ['id' => $class->getDatabaseIdentifierValue($id)];
                break;

            case ClassMetadata::REFERENCE_STORE_AS_DB_REF:
                $reference = [
                    '$ref' => $class->getCollection(),
                    '$id'  => $class->getDatabaseIdentifierValue($id),
                ];
                break;

            case ClassMetadata::REFERENCE_STORE_AS_DB_REF_WITH_DB:
                $reference = [
                    '$ref' => $class->getCollection(),
                    '$id'  => $class->getDatabaseIdentifierValue($id),
                    '$db'  => $this->getDocumentDatabase($class->name)->getDatabaseName(),
                ];
                break;

            default:
                throw new InvalidArgumentException(sprintf('Reference type %s is invalid.', $storeAs));
        }

        return $reference + $this->getDiscriminatorData($referenceMapping, $class);
    }
813253
public function setReferenceContext(ReferenceContext $context)
    {
        if ($this->_pathItem !== null) {
            $this->_pathItem->setReferenceContext($context);
        }
    }
734762
public void setReferenceResolver(final Object referenceResolver) {
        if (referenceResolver instanceof ReferenceResolver) {
            this.referenceResolver = (ReferenceResolver) referenceResolver;
        } else if (referenceResolver instanceof String) {
            this.referenceResolver = new ReferenceResolver() {
                public String getReferenceFor(String nodeName) {
                    return (String) referenceResolver;
                }
            };
        } else if (referenceResolver instanceof Closure) {
            final ObjectGraphBuilder self = this;
            this.referenceResolver = new ReferenceResolver() {
                public String getReferenceFor(String nodeName) {
                    Closure cls = (Closure) referenceResolver;
                    cls.setDelegate(self);
                    return (String) cls.call(new Object[]{nodeName});
                }
            };
        } else {
            this.referenceResolver = new DefaultReferenceResolver();
        }
    }
106847
public function initialize()
    {
        if (!$this->isInitialized()) {
            $referencedDocs = [];
            if (self::REFERENCE_TYPE_UUID === $this->referenceType) {
                $referencedNodes = $this->dm->getPhpcrSession()->getNodesByIdentifier($this->referencedNodes);
            } else {
                $referencedNodes = $this->dm->getPhpcrSession()->getNodes($this->referencedNodes);
            }

            $uow = $this->dm->getUnitOfWork();
            $uow->getPrefetchHelper()->prefetch($this->dm, $referencedNodes, $this->locale);

            $this->originalReferencePaths = [];
            foreach ($referencedNodes as $referencedNode) {
                $proxy = $uow->getOrCreateProxyFromNode($referencedNode, $this->locale);
                if (isset($targetDocument) && !$proxy instanceof $this->targetDocument) {
                    throw new PHPCRException("Unexpected class for referenced document at '{$referencedNode->getPath()}'. Expected '{$this->targetDocument}' but got '".ClassUtils::getClass($proxy)."'.");
                }
                $referencedDocs[] = $proxy;
                $this->originalReferencePaths[] = $referencedNode->getPath();
            }

            $this->collection = new ArrayCollection($referencedDocs);
            $this->initialized = self::INITIALIZED_FROM_PHPCR;
        }
    }