Set Entity links
@param Bond\Entity\Base $entity
@param string $link String descriptor of link. Eg, ItemLinkFile
@param Bond\Entity\Container $new

@return int The number of objects affected by this change.
509572
public static function set_links( Base $entity, $link, Container $new = null )
    {

        $repository = $entity->r();
        if( !$repository->hasLink( $link, $detail ) ) {
            throw new EntityLinkException("Bad link `{$link}`");
        }

        if( is_null( $new ) ) {
            $new = new Container();
        }

        // check container is of the correct type
        $class = $new->classGet();
        $classUnqualified = get_unqualified_class( $class );
        if( $class and !in_array( $classUnqualified, $detail->foreignEntities ) ) {
            $foreignEntities = implode( ', ', $detail->foreignEntities );
            throw new EntityLinkException(
                "Passed container is of type `{$classUnqualified}` and we need one of type(s) {$foreignEntities}"
            );
        }

        // Build array key'd, $existing, like so
        // array(
        //     spl_obj_hash( 'link' ) => spl_obj_hash( 'entity' )
        // )

        $existingLinks = $repository->linksGet( $entity, $link, $classUnqualified, null, false );

        $existing = array();
        foreach( $existingLinks as $splHashLink => $link ) {
            $existing[$splHashLink] = spl_object_hash( $link[$detail->refForeign[0]] );
        }

        $newKeys = array_keys( $new->collection );

        $newKeys = array();
        $ordering = array(); $n = 0;
        foreach( $new as $splHashEntity => $_ ) {
            $newKeys[] = $splHashEntity;
            $ordering[$splHashEntity] = $n++;
        }

        // operations
        $toRemove = array_diff( $existing, $newKeys );
        $toAdd = array_diff( $newKeys, $existing );
        $unchanged = array_intersect( $existing, $newKeys );

        //
        $numModified = 0;

        // remove
        while( list($splHashLink,) = each( $toRemove ) ) {
            $existingLinks[$splHashLink][$detail->refSource[1]] = null;
            $existingLinks[$splHashLink][$detail->refForeign[0]] = null;
            $numModified++;
        }

        // add
        $linkRepo = Repository::init( $link );
        foreach( $toAdd as $key ) {

            $link = $linkRepo->make();
            $link[$detail->refSource[1]] = $entity;
            $link[$detail->refForeign[0]] = $new[$key];

            if( isset( $detail->sortColumn ) ) {
                $link[$detail->sortColumn] = $ordering[$key];
            }

            $numModified++;

        }

        if( isset( $detail->sortColumn ) ) {
            foreach( $unchanged as $linkKey => $entityKey ) {
                $numModified += $existingLinks[$linkKey]->set( $detail->sortColumn, $ordering[$entityKey] ) ? 1 : 0;
            }
        }

        return $numModified;

    }
478894
protected function deleteEntity($entity)
    {
        $this->checkEntityType($entity);

        $delete = new Delete($this->aggregate($entity), $this->newQueryBuilder());

        $delete->execute();
    }
42851
protected function wrapAtomEntry($entity, array $links = null)
    {
        Validate::notNull($entity, 'entity');

        $content = new Content();
        $content->setType(Resources::XML_CONTENT_TYPE);
        $content->setText(ContentPropertiesSerializer::serialize($entity));

        $atomEntry = new Entry();
        $atomEntry->setContent($content);

        if ($links) {
            $atomEntry->setLink($links);
        }

        $xmlWriter = new \XMLWriter();
        $xmlWriter->openMemory();
        $atomEntry->writeXml($xmlWriter);

        return $xmlWriter->outputMemory();
    }
1210714
protected function addLink(Request $request, Link $link)
    {
        if (!class_exists(AddLinkHeaderListener::class)) {
            throw new \LogicException('You can not use the "addLink" method if the WebLink component is not available. Try running "composer require symfony/web-link".');
        }

        if (null === $linkProvider = $request->attributes->get('_links')) {
            $request->attributes->set('_links', new GenericLinkProvider([$link]));

            return;
        }

        $request->attributes->set('_links', $linkProvider->withLink($link));
    }
603474
public function buildChanges($oldEntity, $newEntity)
    {
        $changes = [];
        $entityDefinition = $this->definitions->getDefinition($oldEntity);
        foreach ($entityDefinition->getObservedProperties() as $property) {
            if ($this->isDifferent($property, $oldEntity, $newEntity)) {
                $oldValue = $this->propertyAccessor->getValue($oldEntity, $property->getName());
                $newValue = $this->propertyAccessor->getValue($newEntity, $property->getName());

                $changes[] = $this->buildChange($property, $oldValue, $newValue);
            }
        }

        return new ChangeSet($changes);
    }
1209864
public function setEntityType(string $entityType): void {
		if (!class_exists($entityType)) {
			throw new EntityFactoryException("Unknown entity: $entityType.", EntityFactoryException::UNKNOWN_ENTITY);
		}
		
		// now that we know a class with the name of entityType exists, we need
		// to see if it is an implementation of our EntityInterface object.  the
		// use of the Aura DI container to inject dependencies seems to prevent
		// the use of the PHP is_a() and is_subclass_of() functions.  instead,
		// we'll try to instantiate it like it's an EntityInterface and then we
		// can use the instanceof operator to be sure.
		
		$this->entityType = $entityType;
		$temp = $this->newEntity([]);
		
		if (!($temp instanceof EntityInterface)) {
			
			// if that didn't work, then not only do we want to throw an
			// exception, but we also want to be sure that we set the
			// entityType property back to null so that it doesn't accidentally
			// get used elsewhere after the exception is caught.
			
			$this->entityType = null;
			throw new EntityFactoryException("Not an entity: $entityType.", EntityFactoryException::NOT_AN_ENTITY);
		}
	}
39840
public function setEntity($entity)
    {
        $this->debugLog(sprintf('ENTITY: %s', $entity));

        $expectedEntity = $this->makeSQLSafe($this->getParams()['DBPREFIX'] . $entity);

        $this->debugLog(sprintf('SET ENTITY: %s', $expectedEntity));

        // Concatinate the entity with the sqldbprefix value only if not already done.
        if ($expectedEntity !== $this->entity) {
            $this->entity = $expectedEntity;
        }

        return $this;
    }
143036
public function setMainUrl($entity)
    {
        // set main to first entry or to null
        if ($entity->getUrls()->isEmpty()) {
            $entity->setMainUrl(null);
        } else {
            $entity->setMainUrl($entity->getUrls()->first()->getUrl());
        }
    }
636287
private Link annotationToLink(Siren4JLink linkAnno, EntityContext context) {
        LinkBuilder builder = LinkBuilder.newInstance().setRelationship(linkAnno.rel()).setHref(linkAnno.href());
        if (StringUtils.isNotBlank(linkAnno.title())) {
            builder.setTitle(linkAnno.title());
        }
        if (ArrayUtils.isNotEmpty(linkAnno.linkClass())) {
            builder.setComponentClass(linkAnno.linkClass());
        }
        return builder.build();
    }
1025965
public function generate($entity,$type = self::TYPE_LINK_DEFAULT,$parameters = array())
    {
        if($type === null){
            $type = self::TYPE_LINK_DEFAULT;
        }
        $entityConfig = $this->getEntityConf($entity);
        $link = '';
        if($entityConfig){
            $link = $this->generateFromConfig($entity,$entityConfig,$type,$parameters);
        }
        return $link;
    }
56024
public function updateSeoByEntity(BasePage $page, $entity)
    {
        //if no entity is provided
        if ($entity === null) {
            //we look for the entity of the page
            if ($page->getBusinessEntity() !== null) {
                $entity = $page->getBusinessEntity();
            }
        }

        //only if we have an entity instance
        if ($entity !== null) {
            //the page seo
            $pageSeo = $page->getSeo();

            //the page seo might not exist yet
            if ($pageSeo !== null) {
                $businessEntity = $this->businessEntityHelper->findByEntityInstance($entity);

                if ($businessEntity !== null) {
                    $businessProperties = $businessEntity->getBusinessPropertiesByType('seoable');

                    //parse the business properties
                    foreach ($businessProperties as $businessProperty) {
                        //parse of seo attributes
                        foreach ($this->pageSeoAttributes as $seoAttribute) {
                            $value = $this->getEntityAttributeValue($pageSeo, $seoAttribute);
                            // we only update value if its a string and (if its a VBP or its a BP where value is not defined)
                            if (is_string($value) && ($page instanceof VirtualBusinessPage || ($page instanceof BusinessPage && $value == null))) {
                                $value = $this->parameterConverter->setBusinessPropertyInstance(
                                    $value,
                                    $businessProperty,
                                    $entity
                                );
                            }
                            $this->setEntityAttributeValue($pageSeo, $seoAttribute, $value);
                        }
                    }
                }
            }
        }
    }
728846
public function create(Entity $entity)
    {
        $result = $this->events->shouldExecute($entity, 'before', 'create');
        if (!$result) {
            return false;
        }
        $result = $this->doCreate($entity);
        $this->events->shouldExecute($entity, 'after', 'create');
        return $result;
    }
861448
private function setCount(Link $link, $count): void
	{
		if (is_array($count)) {
			$link->setCount($count[0], $count[1]);
		} elseif (is_int($count)) {
			$link->setCount($count);
		} else {
			throw new InvalidArgumentException("Wrong argument 'count'");
		}
	}
1110614
def replace_entity_resource(model, oldres, newres):
    '''
    
    '''
    oldrids = set()
    for rid, link in model:
        if link[ORIGIN] == oldres or link[TARGET] == oldres or oldres in link[ATTRIBUTES].values():
            oldrids.add(rid)
            new_link = (newres if o == oldres else o, r, newres if t == oldres else t, dict((k, newres if v == oldres else v) for k, v in a.items()))
            model.add(*new_link)
    model.delete(oldrids)
    return
1367552
public function setBaseUrl(string $name, string $link): void
	{
		$this->baseUrl = new \stdClass;
		$this->baseUrl->name = $name;
		$this->baseUrl->link = $link;
	}
301206
public function entity(Entity $entity, Array $linkRelations = array()) {
    if (!isset($this->meta['links']))
      $this->meta['links'] = array();
      
    foreach ($linkRelations as $linkRelation) {
      $this->meta['links'][] = (object) array(
        'rel'=>$linkRelation->getName(),
        'href'=>$linkRelation->getHref()
      );
    }
    
    return $this;
  }
109459
protected function createLink($source, DocumentHydrator $hydrator): LinkObject
    {
        if (is_string($source)) {
            return new LinkObject($source);
        }

        if (! isset($source->href)) {
            throw new InvalidDocumentException('Link must be a string or an object contains "href" attribute.');
        }

        $link = new LinkObject($source->href);

        $hydrator->hydrateObject($link, $source);

        return $link;
    }