Create a Reference

@link https://developer.github.com/v3/git/refs/#create-a-reference

@param string $ref
@param string $sha

@return array
@throws \Exception
338899
public function create(string $ref, string $sha): array
    {
        return $this->getApi()->request($this->getApi()
                                             ->sprintf('/repos/:owner/:repo/git/refs', $this->getGitData()->getOwner(),
                                                 $this->getGitData()->getRepo()), Request::METHOD_POST, [
                'ref' => $ref,
                'sha' => $sha
            ]);
    }
1332791
public function setSha1($sha1)
    {
        $this->throwExceptionIfProtected();
        if (!is_string($sha1) || preg_match('/[A-Fa-f0-9]{40}/', $sha1) !== 1) {
            throw new \InvalidArgumentException('Specified invalid hash to setSha1()', 1362564220);
        }
        $this->sha1 = strtolower($sha1);
    }
626503
public function delete(string $ref): bool
    {
        $this->getApi()->request($this->getApi()
                                      ->sprintf('/repos/:owner/:repo/git/refs/:ref', $this->getGitData()->getOwner(),
                                          $this->getGitData()->getRepo(), $ref), Request::METHOD_DELETE);

        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
            return true;
        }

        return false;
    }
503522
protected function flatReference(array $reference)/*# : array */
    {
        reset($reference);
        foreach ($reference as $key => $value) {
            if (is_object($value)) {
                $reference[$key] = get_class($value);
            } elseif (is_array($value)) {
                $reference[$key] = $this->flatReference($value);
            }
        }
        ksort($reference);
        return $reference;
    }
50453
public function ref($id): Reference
	{
		$ref = new $this->reference_class($this->smalldb, $this, $id);
		if ($this->debug_logger) {
			$this->debug_logger->afterReferenceCreated(null, $ref);
		}
		return $ref;
	}
877330
public function evalsha($sha, $keys = null, $args = null) {
        $params = [$sha];
        if (is_array($keys)) {
            $keys = (array)$keys;
            $params[] = count($keys);
            $params[] = $keys;
        } else {
            $params[] = 0;
        }
        if (is_array($args)) {
            $params[] = (array) $args;
        }
        return $this->returnCommand(['EVALSHA'], $keys, $params);
    }
805952
private function resolveSchema($reference)
    {
        $schema = $reference;
        if (property_exists($reference, '$ref')) {
            $schemaResolver = $this->document->getSchemaResolver();
            $ref = new Reference($reference);
            $schema = $schemaResolver->resolveReference($ref)->getDocument();
        } elseif ($reference->type === 'array' && !empty($reference->items)) {
            $schema->items = $this->resolveSchema($reference->items);
        }

        // resolve properties
        if (!empty($schema->properties)) {
            $properties = (array) $schema->properties;
            foreach ($properties as $name => $property) {
                if (isset($property->type)
                    && $property->type === 'array'
                    && isset($property->items)
                    && property_exists($property->items, '$ref')
                    && !isset($schema->properties->$name->items)) {
                    $schema->properties->$name->items = $this->resolveSchema($property->items);
                } elseif (property_exists($property, '$ref') && !isset($schema->properties->$name)) {
                    $schema->properties->$name = $this->resolveSchema($property);
                }
            }
        }

        return $schema;
    }
489751
public function listDeployments(string $sha = null, string $ref = null, string $task = null,
                                    string $environment = null): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/deployments',
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(),
            http_build_query(['sha' => $sha, 'ref' => $ref, 'task' => $task, 'environment' => $environment])));
    }
623296
public static function create($languageReference, $level = 'info', $objectName = '', $execTime = null)
    {
        if (JsonReader::read(BASE_DIR.'/phiber_config.json')->phiber->log == 1 ? true : false) {
            $date = date('Y-m-d H:i:s');
            switch ($level) {
                case 'info':
                    $levelStr = strtoupper(new Internationalization("log_info"));
                    $msg = "\033[0;35m PHIBER LOG -> [$date] [$levelStr]: (" .
                    new Internationalization("reference") .
                    "=> \"$objectName\") " . new Internationalization($languageReference) .
                    " - ";
                    if($execTime != null){
                        $msg .=  "em " . $execTime . ".";
                    }
                    echo $msg . "\e[0m \n";
                    break;

                case 'warning':
                    $levelStr = strtoupper(new Internationalization("log_warning"));
                    $msg = "\033[1;33m PHIBER LOG -> [$date] [$levelStr]: (" .
                        new Internationalization("reference") .
                        "=> \"$objectName\") " . new Internationalization($languageReference) .
                        " - ";
                    if($execTime != null){
                        $msg .=  "em " . $execTime . ".";
                    }
                    echo $msg . "\e[0m \n";
                    break;

                case 'error':
                    $levelStr = strtoupper(new Internationalization("log_error"));
                    $msg = "\033[0;31m PHIBER LOG -> [$date] [$levelStr]: (" .
                        new Internationalization("reference") .
                        "=> \"$objectName\") " . new Internationalization($languageReference) .
                        " - ";
                    if($execTime != null){
                        $msg .=  "em " . $execTime . ".";
                    }
                    echo $msg . "\e[0m \n";
                    break;
            }
        }
    }
1186518
public function generate($reference)
    {
        $adapter = $this->getAdapter();
        if ($adapter instanceof AwsS3) {
            return $adapter->getUrl($reference);
        } elseif ($adapter instanceof Local) {
            $request = $this->getRequest();

            return $request->getSchemeAndHttpHost().'/'.$this->getLocalUploadDirectory().'/'.$reference;
        }

        return $reference;
    }
609306
protected function validateCommit($sha, $field) {
		// Check selected commit
		if(empty($sha)) {
			$this->validationError(
				$field,
				"No valid release selected",
				"required"
			);
			return false;
		}

		// Check validity of commit
		if (!preg_match('/^[a-f0-9]{40}$/', $sha)) {
			$this->validationError(
				$field,
				"Invalid release SHA: " . Convert::raw2xml($sha),
				"error"
			);
			return false;
		}

		return true;
	}
671174
def commit(ref)
      if sha?(ref)
        get_cache(:commit, ref) { commit!(ref) }
      else
        if (sha = get_cache(:ref, ref))
          commit(sha)
        else
          if (cm = commit!(ref))
            set_cache(:ref, ref, cm.id)
            set_cache(:commit, cm.id, cm)
          end
        end
      end
    end
240130
public function setReferences($references)
    {
        $this->_references = [];
        foreach ($references as $name => $ref) {
            if (!array_key_exists('key', $ref)) {
                $ref['key'] = 'id';
            }
            $this->_references[$name] = $ref;
        }
        return $this;
    }
122922
public static function reset($reference = null)
    {
        if ($reference === null) {
            static::$_registered = [];
            Suite::reset();
            return;
        }
        unset(static::$_registered[Suite::hash($reference)]);
    }
424432
public function shareInstance($instance, $reference = null)
    {

        if (!is_object($instance)) {
            //@TODO maybe throw an error?
            return false;
        }

        $concrete = get_class($instance);

        //if reference is difference from $concrete add Alias
        if (!empty($reference) && ($reference !== $concrete)) {
            $alias = $reference;
            $this->createAlias($concrete, $alias);
        }

        //just save the instance in container, no need for lambdas;
        return $this->container[$concrete] = $instance;
    }
143882
public function hotRef($properties): Reference
	{
		$ref = $this->reference_class::createPreheatedReference($this->smalldb, $this, $properties);
		if ($this->debug_logger) {
			$this->debug_logger->afterReferenceCreated(null, $ref, $properties);
		}
		return $ref;
	}
430028
public function urlForReference(string $user, string $repo, string $ref): string
    {
        $key = sprintf(self::CACHE_KEY_TEMPLATE, md5($user . $repo), 'ref_url_' . md5($ref));

        if (($latest = $this->getFromCache($key)) !== null) {
            return $latest;
        }

        [$type, $resolved] = $this->resolveRefType($ref);
        $repoURL = $this->urlForRepository($user, $repo);

        switch ($type) {
            case 'commit':
                $url = "${repoURL}/commit/${resolved}";
                break;

            case 'tag':
                $url = "${repoURL}/releases/tag/${resolved}";
                break;

            case 'pull':
                $url = "${repoURL}/pull/${resolved}";
                break;

            case 'branch':
            default:
                $url = "${repoURL}/tree/${resolved}";
        }

        $this->setToCache($key, $url, 30);
        return $url;
    }