Repository method to serve the referenced file.

@inheritDocs
548232
public function send_file($storedfile, $lifetime=null , $filter=0, $forcedownload=false, array $options = null) {
        $reference = $this->unpack_reference($storedfile->get_reference());

        $maxcachesize = $this->max_cache_bytes();
        if (empty($maxcachesize)) {
            // Always cache the file, regardless of size.
            $cachefile = true;
        } else {
            // Size available. Only cache if it is under maxcachesize.
            $cachefile = $storedfile->get_filesize() < $maxcachesize;
        }

        if (!$cachefile) {
            \core\session\manager::write_close();
            header('Location: ' . $this->get_file_download_link($reference->url));
            die;
        }

        try {
            $this->import_external_file_contents($storedfile, $this->max_cache_bytes());
            if (!is_array($options)) {
                $options = array();
            }
            $options['sendcachedexternalfile'] = true;
            \core\session\manager::write_close();
            send_stored_file($storedfile, $lifetime, $filter, $forcedownload, $options);
        } catch (moodle_exception $e) {
            // Redirect to Dropbox, it will show the error.
            // Note: We redirect to Dropbox shared link, not to the download link here!
            \core\session\manager::write_close();
            header('Location: ' . $reference->url);
            die;
        }
    }
753166
public function resolve()
    {
        if ($this->sourceFile instanceof UploadedFile) {
            $extension = $this->sourceFile->guessExtension();
            $name = preg_filter('/^php(.+)/', '$1', $this->sourceFile->getBasename());
            $this->originalName = $this->sourceFile->getClientOriginalName();
        } else {
            $extension = $this->sourceFile->getExtension();
            $this->originalName = $name = $this->sourceFile->getBasename('.'.$extension);
        }

        $this->setPhysicalFile(
            $this->sourceFile->move(
                $this->storePath,
                sprintf('%s%s.%s',
                    strtolower($name),
                    base_convert(microtime(), 10, 36),
                    $extension
                )
            )
        );

        return parent::resolve();
    }
951778
public function showFile($file, $ref = 'HEAD')
    {
        /** @var $result CallResult */
        $result = $this->getGit()->{'show'}($this->getRepositoryPath(), array(
            sprintf('%s:%s', $ref, $file)
        ));
        $result->assertSuccess(sprintf('Cannot show "%s" at "%s" from "%s"',
            $file, $ref, $this->getRepositoryPath()
        ));


        return $result->getStdOut();
    }
657761
protected function filterFile($file)
    {
        if (is_string($file)) {
            $this->file = $file;
        } elseif (is_resource($file)) {
            $this->stream = new Stream($file);
        } elseif ($file instanceof StreamInterface) {
            $this->stream = $file;
        } else {
            throw new \InvalidArgumentException('The file resource is not readable.');
        }
    }
515605
function servePublicFile(file, type, maxAge) {
    const publicFileMiddleware = createPublicFileMiddleware(file, type, maxAge);

    return function servePublicFile(req, res, next) {
        if (req.path === '/' + file) {
            return publicFileMiddleware(req, res, next);
        } else {
            return next();
        }
    };
}
744482
public function serve($as = null)
	{
		// Initiate a new content server
		$server = new \Hubzero\Content\Server();
		$server->disposition('attachment');
		$server->acceptranges(false);

		if (!$this->isLocal())
		{
			// Create a temp file and write to it
			$temp = tmpfile();
			fwrite($temp, $this->read());
			$server->filename(stream_get_meta_data($temp)['uri']);
		}
		else
		{
			$server->filename($this->getAbsolutePath());
		}

		$server->saveas($as ?: $this->getFileName());

		// Serve up the file
		$result = $server->serve();

		// Clean up after serving
		if (isset($temp) && is_resource($temp))
		{
			fclose($temp);
		}

		return $result;
	}
502966
public function generateRepository($group, $module, $model, $mode, $output, $file = "", $customTemplate = "")
    {
        $generator = new RepositoryGenerator($group, $module, $model, $mode, $output, $file, $customTemplate);
        $generator->run();
    }
1327950
public function setRepositoryReference(RepositoryReference $repositoryReference)
    {
        parent::setRepositoryReference($repositoryReference);
        $this
            ->repository
            ->setRepositoryReference($repositoryReference);
    }
1363631
public function serve()
	{
		return self::serve_file($this->_filename, $this->_saveas, $this->_disposition, $this->_acceptranges);
	}
789436
protected function makeRepository()
    {
        $full_path = $this->getFullRepositoryPath();
        if (file_exists($full_path)) {
            throw new RepositoryExistsException(sprintf('%s file already exists', $full_path));
        }
        $contract_contents = str_replace(
            [
                '%%MODEL_BASENAME%%',
                '%%MODEL_NAME%%',
                '%%CLASS_NAME%%',
                '%%NAMESPACE%%',
                '%%CONTRACT%%',
            ],
            [
                $this->getModelBasename(),
                $this->getModelName(),
                $this->getRepositoryBaseName(),
                trim($this->getRepositoriesNamespace(), '\\'),
                $this->getContractsNamespace() . '\\' . $this->getContractBaseName(),

            ],
            $this->contentsFromStub('Repository')
        );
        if (!file_exists(dirname($full_path))) {
            mkdir(dirname($full_path), 0755, true);
        }
        file_put_contents($full_path, $contract_contents);
    }
491724
public function get_file_reference($source) {
        global $USER;
        $reference = new stdClass;
        $reference->userid = $USER->id;
        $reference->username = fullname($USER);
        $reference->path = $source;

        // Determine whether we are downloading the file, or should use a file reference.
        $usefilereference = optional_param('usefilereference', false, PARAM_BOOL);
        if ($usefilereference) {
            if ($data = $this->dropbox->get_file_share_info($source)) {
                $reference = (object) array_merge((array) $data, (array) $reference);
            }
        }

        return serialize($reference);
    }
397012
public function store($resource)
    {
        if (!$resource instanceof LocalResource) {
            throw new \InvalidArgumentException('Resource is not local.');
        }

        $file = $this->directory.'/'.$resource->getPath();
        @mkdir(dirname($file), 0777, true);
        file_put_contents($file, $resource->getContent());
        return new MaterializedResource($resource, $this->directory);
    }
16207
public function loadCollection(PersistentCollectionInterface $collection) : void
    {
        $mapping = $collection->getMapping();
        switch ($mapping['association']) {
            case ClassMetadata::EMBED_MANY:
                $this->loadEmbedManyCollection($collection);
                break;

            case ClassMetadata::REFERENCE_MANY:
                if (isset($mapping['repositoryMethod']) && $mapping['repositoryMethod']) {
                    $this->loadReferenceManyWithRepositoryMethod($collection);
                } else {
                    if ($mapping['isOwningSide']) {
                        $this->loadReferenceManyCollectionOwningSide($collection);
                    } else {
                        $this->loadReferenceManyCollectionInverseSide($collection);
                    }
                }
                break;
        }
    }
1347327
private function loadReferenceManyCollectionInverseSide(PersistentCollectionInterface $collection)
    {
        $query     = $this->createReferenceInverseSideQuery($collection->getMapping(), $collection->getOwner());
        $documents = $query->execute()->toArray();

        foreach ($documents as $key => $document) {
            $collection->add($document);
        }
    }
960213
public function push($repository = null, $refspec = null)
    {
        $command = 'push';

        if ($repository) {
            $command .= " $repository";
        }

        if ($refspec) {
            $command .= " $refspec";
        }

        $this->getClient()->run($this, $command);

        return $this;
    }
1338955
public function resolveRepository($resource, array $parameters = [], $version = null)
    {
        return $this->resolve('repository', $resource, $parameters, $version);
    }
441565
public function handleUpdate(Args $args)
    {
        $flags = $args->isOptionSet('force')
            ? RepositoryManager::OVERRIDE | RepositoryManager::IGNORE_FILE_NOT_FOUND
            : RepositoryManager::OVERRIDE;
        $repositoryPath = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
        $mappingToUpdate = $this->repoManager->getRootPathMapping($repositoryPath);
        $pathReferences = array_flip($mappingToUpdate->getPathReferences());

        foreach ($args->getOption('add') as $pathReference) {
            $pathReferences[$pathReference] = true;
        }

        foreach ($args->getOption('remove') as $pathReference) {
            unset($pathReferences[$pathReference]);
        }

        if (0 === count($pathReferences)) {
            $this->repoManager->removeRootPathMapping($repositoryPath);

            return 0;
        }

        $updatedMapping = new PathMapping($repositoryPath, array_keys($pathReferences));

        if ($this->mappingsEqual($mappingToUpdate, $updatedMapping)) {
            throw new RuntimeException('Nothing to update.');
        }

        $this->repoManager->addRootPathMapping($updatedMapping, $flags);

        return 0;
    }