Set a link on a dependency to a constraint.

@param string $type       The link type (require, require-dev, provide, replace).

@param string $name       The package name.

@param string $constraint The version constraint.

@return ComposerJson
355543
private function setLink($type, $name, $constraint)
    {
        $this->set($type . '/' . $this->escape($name), $constraint);

        return $this;
    }
512087
public function set($name, Dependency $dependency)
    {
        $required = isset($this->dependencies[$name]) && $this->dependencies[$name]->isRequired();
        $this->dependencies[$name] = new Requirement($dependency, $required);

        return $this;
    }
155096
private function setLink($name, $link)
    {
        if (! is_string($link) and ! is_object($link)) {
            throw new ValidationException(
                'Link attribute has to be an object or string, "' .
                gettype($link) . '" given.'
            );
        }

        if (is_string($link)) {
            $this->set($name, strval($link));

            return;
        }

        // Now $link can only be an object
        $this->set($name, $this->create('Link', $link));
    }
522940
protected function getForeignConstraint($name)
    {
        $raw = $this->getConstraint($name);

        if (is_null($raw)) {
            return null;
        }

        return new ForeignConstraint(
            $raw->foreign,
            $raw->references,
            $raw->on,
            strtolower($raw->onDelete),
            strtolower($raw->onUpdate),
            null,
            $raw->selfReferences
        );
    }
853075
public function setType(Type $type = null)
    {
        if ($this->type !== $type) {
            // romove link on this item for old type
            if ($this->type instanceof Type) {
                $tmp = $this->type;
                $this->type = null;
                $tmp->removeItem($this);
            }
            $this->type = $type;
            // add link on this item
            if ($this->type instanceof Type) {
                $this->type->addItem($this);
            }
        }

        return $this;
    }
1092527
protected function loadDefaultValues($name, $type = 'metadata')
    {
        $defaultValue = $this->getFileManager()->getContents(array($this->pathToDefaults, $type, $name.'.json') );
        if ($defaultValue !== false) {
            if ($this->useObjects) {
                return Utils\Json::decode($defaultValue);
            } else {
                return Utils\Json::decode($defaultValue, true);
            }
        }
        if ($this->useObjects) {
            return (object) [];
        } else {
            return array();
        }
    }
808929
public function addConstraint($name, IConstraint $constraint) {
        $this->addConstraintGroup(new ConstraintGroup($name, [$constraint]));

        return $this;
    }
959223
protected static function init(string $type = 'string', string $key = null, string $name = null)
    {
        $instance = new static();

        $instance->key($key);
        $instance->field['type'] = $type;

        if ($name) $instance->field['name'] = $name;

        return $instance;
    }
1267179
public function Link($name, $type, $version = 'latest')
    {
        $type = strtolower($type);

        //Gets data
        $data = $this->includeLibraryService->getData($name, $type, $version);

        //Returns the href or src part
        if (null !== $data) {
            return 'css' == $type ? $data['href'] : $data['src'];
        }

        //Throws an error if not found
        throw new Error('The Library "' . $name . ' (' . $type . ') version ' . $version . '" requested via "inc_link()" was not found. Please check name and supported library/versions.');
    }
131020
private function guessSimplePrimaryTypeFromConstraint(Constraint $constraint) : ?TypeDoc
    {
        if (null !== $this->getMatchingClassNameIn($constraint, self::STRING_CONSTRAINT_CLASS_LIST)) {
            return new StringDoc();
        } elseif (null !== $this->getMatchingClassNameIn($constraint, self::BOOLEAN_CONSTRAINT_CLASS_LIST)) {
            return new BooleanDoc();
        } elseif ($constraint instanceof Assert\Regex) {
            return new ScalarDoc();
        } elseif ($this->isArrayConstraint($constraint)) {
            return new ArrayDoc();
        }

        return null;
    }
426844
protected function resolveName(Name $name, $type) {
        $resolvedName = $this->nameContext->getResolvedName($name, $type);
        if (null !== $resolvedName) {
            $name->setAttribute('resolvedName', $resolvedName->toString());
        }
        return $name;
    }
93273
private function createArgumentDescriptorForMagicMethod(string $name, Type $type): ArgumentDescriptor
    {
        $argumentDescriptor = new ArgumentDescriptor();
        $argumentDescriptor->setType(AssemblerAbstract::deduplicateTypes($type));
        $argumentDescriptor->setName($name);

        return $argumentDescriptor;
    }
273524
public function setAsRequired($name)
    {
        $provider = $this->importDependency($name);
        $lastRequired = null;

        try {
            foreach ($provider->getDependencies() as $dependencyName) {
                $lastRequired = $dependencyName;
                if (!$this->isRequired($dependencyName)) {
                    $this->setAsRequired($dependencyName);
                }
            }
        } catch (DependencyException $exception) {
            throw new DependencyException(
                $exception->getCode() === 1
                    ? 'Dependency not found: '.$lastRequired.' < '.$name
                    : $exception->getMessage().' < '.$name,
                2
            );
        }

        return $this;
    }
1337569
public static function durable(string $name, Type $type): self
    {
        $self = new self($name, $type);
        $self->durable = true;

        return $self;
    }
96601
public function createConstant($name, $type = NULL, $default = self::UNDEFINED, $modifiers = GConstant::MODIFIER_PROTECTED) {
    $gConstant = GConstant::create($name, $type, $default, $modifiers);
    
    $this->addConstant($gConstant);
    return $gConstant;
  }
857839
public function setColumnType($name, $type)
    {
        $this->_columns[$name]['type'] = $type;
        $this->_typeMap[$name] = $type;

        return $this;
    }
42447
private function createDocFromConstraint(Constraint $constraint) : ?TypeDoc
    {
        $doc = null;

        if (null !== ($stringType = $this->getStringType($constraint))) {
            $doc = $this->normalizeType($stringType);
        } elseif ($constraint instanceof Assert\Callback) {
            $doc = $this->getTypeFromCallbackConstraint($constraint);
        } elseif ($constraint instanceof Assert\Existence && count($constraint->constraints) > 0) {
            $doc = $this->guess($constraint->constraints);
        }

        return $doc;
    }