Prepare file reference information

@param string $source source of the file, returned by repository as 'source' and received back from user (not cleaned)
@return string file reference, ready to be stored
420541
public function get_file_reference($source) {
        if ($source && $this->has_moodle_files()) {
            $params = @json_decode(base64_decode($source), true);
            if (!is_array($params) || empty($params['contextid'])) {
                throw new repository_exception('invalidparams', 'repository');
            }
            $params = array(
                'component' => empty($params['component']) ? ''   : clean_param($params['component'], PARAM_COMPONENT),
                'filearea'  => empty($params['filearea'])  ? ''   : clean_param($params['filearea'], PARAM_AREA),
                'itemid'    => empty($params['itemid'])    ? 0    : clean_param($params['itemid'], PARAM_INT),
                'filename'  => empty($params['filename'])  ? null : clean_param($params['filename'], PARAM_FILE),
                'filepath'  => empty($params['filepath'])  ? null : clean_param($params['filepath'], PARAM_PATH),
                'contextid' => clean_param($params['contextid'], PARAM_INT)
            );
            // Check if context exists.
            if (!context::instance_by_id($params['contextid'], IGNORE_MISSING)) {
                throw new repository_exception('invalidparams', 'repository');
            }
            return file_storage::pack_reference($params);
        }
        return $source;
    }
135479
public function load($source)
    {
        if ($this->isFile($source)) {
            return $this->loadFile($source);
        } else {
            return $this->loadString($source);
        }
    }
483762
public function copyFrom($file, $source)
    {
        if ($this->enabled) {
            $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
            $this->filesystem->ensureDirectoryExists(dirname($this->root . $file));

            if ($this->io->isDebug()) {
                $this->io->writeError('Writing '.$this->root . $file.' into cache');
            }

            return copy($source, $this->root . $file);
        }

        return false;
    }
410653
public function getCompiledFile($source)
    {
        if (strpos($source, $root = $this->alias->get('@root')) === 0) {
            $compiled = '@data/sword' . substr($source, strlen($root));
        } elseif (!empty($_SERVER['DOCUMENT_ROOT']) && strpos($source, $_SERVER['DOCUMENT_ROOT']) === 0) {
            $compiled = '@data/sword/' . substr($source, strlen($_SERVER['DOCUMENT_ROOT']));
        } else {
            $compiled = "@data/sword/$source";
            if (DIRECTORY_SEPARATOR === '\\') {
                $compiled = str_replace(':', '_', $compiled);
            }
        }

        $compiled = $this->alias->resolve($compiled);

        if ($this->configure->debug || !file_exists($compiled) || filemtime($source) > filemtime($compiled)) {
            $this->swordCompiler->compileFile($source, $compiled);
        }

        return $compiled;
    }
1269636
public function resolvePath (string $source, string $target) : string
    {
        $sourceDirs = $this->toDirectoryFragments(\dirname($source));
        $targetFileName = \basename($target);

        // if relative path is absolute, just return the absolute path
        if ("/" === \substr($target, 0, 1))
        {
            return $target;
        }

        // strip leading "./"
        if ("./" === \substr($target, 0, 2))
        {
            $target = \substr($target, 2);
        }

        $targetDirs = $this->toDirectoryFragments(\dirname($target));

        // if the relative dirs are empty (it is just a file name), use the same directory
        if (empty($targetDirs))
        {
            return $this->buildFilePath($sourceDirs, $targetFileName);
        }

        // strip leading "../../" from the beginning of the relative dir and simultaneously from the end of the source dir
        while (!empty($targetDirs) && ".." === $targetDirs[0])
        {
            \array_pop($sourceDirs);
            \array_shift($targetDirs);
        }

        return $this->buildFilePath(
            \array_merge($sourceDirs, $targetDirs),
            $targetFileName
        );
    }
501765
public function set_source($source) {
        $filerecord = new stdClass;
        $filerecord->source = $source;
        $this->update($filerecord);
    }
56044
private function localize($source) {
		if (!stream_is_local($source) || ($this->args->git && isset($this->args->branch))) {
			$source = $this->download($source);
			$this->cleanup[] = new Task\Cleanup($source);
		}
		$source = realpath($source);
		if (!is_dir($source)) {
			$source = $this->extract($source);
			$this->cleanup[] = new Task\Cleanup($source);
			
			if (!$this->args->git) {
				$source = (new Task\PeclFixup($source))->run($this->verbosity());
			}
		}
		return $source;
	}
597524
public function fromFile( $source = null )
	{
		$typesFilename = is_null( $source )
			? dirname( __FILE__ ) . "/" . XBRL_Types::$filename
			: $source;

		if ( ! file_exists( $typesFilename ) ) return;

		$json = file_get_contents( $typesFilename );
		if ( $json === false ) return false;

		return $this->fromJSON( $json );
	}
318785
private function determineSource($source)
    {
        // Use the contents of a file as the data source.
        if (is_string($source)) {
            $source = Psr7\try_fopen($source, 'r');
        }

        // Create a source stream.
        $stream = Psr7\stream_for($source);
        if (!$stream->isReadable()) {
            throw new IAE('Source stream must be readable.');
        }

        return $stream;
    }
833842
public function setSource($source): Method
    {
        if (!empty($source)) {
            if (is_array($source)) {
                $this->source->setLines($source);
            } elseif (is_string($source)) {
                $this->source->setString($source);
            }
        }

        return $this;
    }
143285
public function provide(string $source): string
    {
        if (!$this->filesystem->fileExists($source)) {
            throw WsdlException::notFound($source);
        }

        return $source;
    }
546862
protected static function makeSource($source): SourceInterface
    {
        if (is_array($source) || $source instanceof \ArrayAccess) {
            return new ArraySource($source);
        }

        if (is_object($source)) {
            return new ObjectSource($source);
        }

        throw new InvalidSourceException(
            sprintf('Source type "%s" cannot be recognized as suitable storage', gettype($source))
        );
    }
446434
public static function code($source)
		{
			if (class_exists($source))
			{
				@list ($class, $method, $comment) = func_get_args();
				return is_string($method)
					? Code::method($class, $method, $comment)
					: Code::classfile($class, $method);
			}
			else if (file_exists($source))
			{
				@list ($path, $start, $end, $undent) = func_get_args();
				return is_int($start)
					? Code::section($path, $start, $end, $undent)
					: Code::file($path, $start);
			}
			return Code::output($source);
		}
1356645
public function RemoveFiles($source){
        if (is_dir($source)){
            $folder = opendir($source);
            while($file = readdir($folder)){
                if ($file == '.' || $file == '..')continue;
                if(is_dir($source.'/'.$file)) $this->RemoveFiles($source.'/'.$file);
                else unlink($source.'/'.$file);
            }
            closedir($folder);
            rmdir($source);
        }
        return 1;
    }
350240
public function cdn($source)
	{
		$url = str_ireplace($this->public_path, '', $this->assets_path . '/' . ltrim($source, '/'));
		$url = $this->cdn ? $this->cdn . $url : $url;
		return $url;
	}
126590
protected function getSourcesFromFinder($source)
    {
        $array = explode(DIRECTORY_SEPARATOR, $source);
        $filename = array_pop($array);
        $directory = $source;
        $pattern = '*';
        
        // if a dot is present, the last part is the filename pattern
        if (strstr($filename, '.') !== false) {
            $pattern = $filename;
            $directory = implode('/', $array);
        }
        $finder = new Finder();
        $finder
            ->name($pattern)
            ->in($directory);
        
        $sources = [];
        
        foreach ($finder as $source) {
            $sources[] = $source;
        }
        
        return $sources;
    }
147537
public function formatSource($source)
    {
        if (! is_object($source)) {
            return '';
        }

        $parts = [];

        if ($source->namespace) {
            $parts['namespace'] = $source->namespace . '::';
        }

        $parts['name'] = $source->name;
        $parts['line'] = ':' . $source->line;

        return implode($parts);
    }