@param string $file
@param null   $assign

@return string
774967
public function process($file, $assign = null)
    {
        if ($file === '') {
            return '';
        }

        if ($policy = $this->core->getSecurityPolicy()) {
            while (true) {
                if (preg_match('{^([a-z]+?)://}i', $file)) {
                    $this->core->triggerError('The security policy prevents you to read files from external sources.',
                        E_USER_WARNING);
                }

                $file = realpath($file);
                $dirs = $policy->getAllowedDirectories();
                foreach ($dirs as $dir => $dummy) {
                    if (strpos($file, $dir) === 0) {
                        break 2;
                    }
                }
                $this->core->triggerError('The security policy prevents you to read <em>' . $file . '</em>',
                    E_USER_WARNING);
            }
        }
        $file = str_replace(array(
            "\t",
            "\n",
            "\r"
        ),
            array(
                '\\t',
                '\\n',
                '\\r'
            ),
            $file);

        $out = file_get_contents($file);

        if ($assign === null) {
            return $out;
        }
        $this->core->assignInScope($out, $assign);
    }
278290
public static function create_from_assign(\assign $assign) {
        $data = array(
            'context' => $assign->get_context(),
            'other' => array(
                'assignid' => $assign->get_instance()->id,
            ),
        );
        self::$preventcreatecall = false;
        /** @var grading_table_viewed $event */
        $event = self::create($data);
        self::$preventcreatecall = true;
        $event->set_assign($assign);
        return $event;
    }
938879
public final function getRelativePath($file = null) {
        return $file ? MODULE_DIR . DS . $this->dirname . DS . ($file ? $file : '') : $this->path . DS;
    }
229445
protected function getFileContents($file)
    {
        if ($file instanceof ModuleResource) {
            $path = $file->getPath();
        } else {
            $path = Director::baseFolder() . '/' . $file;
        }
        if (!file_exists($path)) {
            return null;
        }
        $content = file_get_contents($path);

        // Remove UTF-8 BOM
        if (substr($content, 0, 3) === pack("CCC", 0xef, 0xbb, 0xbf)) {
            $content = substr($content, 3);
        }

        return $content;
    }
759109
private function getFirstClassNameInFile(File $file): ?string
    {
        $position = $file->findNext(T_CLASS, 0);

        if ($position === false) {
            return null;
        }

        $fileClassName = ClassHelper::getFullyQualifiedName($file, $position);

        return ltrim($fileClassName, '\\');
    }
818536
public function dump(string $file = null):string{
		$this->image      = \imagecreatetruecolor($this->length, $this->length);
		$this->background = \imagecolorallocate($this->image, ...$this->options->imageTransparencyBG);

		if((bool)$this->options->imageTransparent && \in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){
			\imagecolortransparent($this->image, $this->background);
		}

		\imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $this->background);

		foreach($this->matrix->matrix() as $y => $row){
			foreach($row as $x => $M_TYPE){
				$this->setPixel($x, $y, $this->moduleValues[$M_TYPE]);
			}
		}

		$imageData = $this->dumpImage($file);

		if((bool)$this->options->imageBase64){
			$imageData = 'data:image/'.$this->options->outputType.';base64,'.\base64_encode($imageData);
		}

		return $imageData;
	}
88180
public static function for_file($file)
    {
        if (!$file || (is_string($file) && !file_exists($file))) {
            return null;
        }

        // Ensure we have a File instance to work with
        if (is_string($file)) {
            /** @var File $fileObject */
            $fileObject = File::create();
            $fileObject->setFromLocalFile($file);
            $file = $fileObject;
        }

        $extension = $file->getExtension();
        $mime = $file->getMimeType();

        foreach (self::get_extractor_classes() as $className) {
            $extractor = self::get_extractor($className);

            // Skip unavailable extractors
            if (!$extractor->isAvailable()) {
                continue;
            }

            // Check extension
            if ($extension && $extractor->supportsExtension($extension)) {
                return $extractor;
            }

            // Check mime
            if ($mime && $extractor->supportsMime($mime)) {
                return $extractor;
            }
        }
    }
701678
public function getBindingForFile( $file ) {
		$engine_key = $this->default;

		foreach ( $this->bindings as $suffix => $engine ) {
			if ( substr( $file, -strlen( $suffix ) ) === $suffix ) {
				$engine_key = $engine;
				break;
			}
		}

		return $engine_key;
	}
1198983
public function generateTempFile($file = null): string
    {
        $path = tempnam(sys_get_temp_dir(), self::TEMP_FILE_OR_DIRECTORY_PREFIX);
        if ($file) {
            file_put_contents($path, $file instanceof \SplFileInfo ? (new Parser())->getBinary($file) : $file);
        }
        register_shutdown_function(function () use ($path) {
            if (file_exists($path)) {
                unlink($path);
            }
        });
        return $path;
    }
656760
public function process($file, $cache_time = null, $cache_id = null, $compile_id = null, $data = '_root', $assign = null, array $rest = array())
    {
        $include = null;
        if ($file === '') {
            return '';
        }

        if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
            // resource:identifier given, extract them
            $resource   = $m[1];
            $identifier = $m[2];
        } else {
            // get the current template's resource
            $resource   = $this->core->getTemplate()->getResourceName();
            $identifier = $file;
        }

        try {
            $include = $this->core->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id);
        }
        catch (SecurityException $e) {
            $this->core->triggerError('Include : Security restriction : ' . $e->getMessage(), E_USER_WARNING);
        }
        catch (Exception $e) {
            $this->core->triggerError('Include : ' . $e->getMessage(), E_USER_WARNING);
        }

        if ($include === null) {
            $this->core->triggerError('Include : Resource "' . $resource . ':' . $identifier . '" not found.',
                E_USER_WARNING);
        } elseif ($include === false) {
            $this->core->triggerError('Include : Resource "' . $resource . '" does not support includes.',
                E_USER_WARNING);
        }

        if (is_string($data)) {
            $vars = $this->core->readVar($data);
        } else {
            $vars = $data;
        }

        if (count($rest)) {
            $vars = $rest + $vars;
        }

        $clone = clone $this->core;
        $out   = $clone->get($include, $vars);

        if ($assign !== null) {
            $this->core->assignInScope($out, $assign);
        }

        foreach ($clone->getReturnValues() as $name => $value) {
            $this->core->assignInScope($value, $name);
        }

        if ($assign === null) {
            return $out;
        }
    }
929961
public static function getUniqueCode($file)
    {
        if (!$file) {
            return null;
        }

        $hash = md5($file->file_name . '!' . $file->disk_name);
        return base64_encode($file->id . '!' . $hash);
    }
578305
public function json($file = null)
    {
        $file = $file ? $file : $this->cacheFileName;

        $details = array();

        clearstatcache();

        $details['src']       = $this->imageSrc;
        $lastModified         = filemtime($this->pathToImage);
        $details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);

        $details['cache']       = basename($this->cacheFileName);
        $lastModified           = filemtime($this->cacheFileName);
        $details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);

        $this->load($file);

        $details['filename']    = basename($file);
        $details['mimeType']    = $this->getMimeType($this->fileType);
        $details['width']       = $this->width;
        $details['height']      = $this->height;
        $details['aspectRatio'] = round($this->width / $this->height, 3);
        $details['size']        = filesize($file);
        $details['colors'] = $this->colorsTotal($this->image);
        $details['includedFiles'] = count(get_included_files());
        $details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
        $details['memoryCurrent'] = round(memory_get_usage()/1024/1024, 3) . " MB";
        $details['memoryLimit'] = ini_get('memory_limit');

        if (isset($_SERVER['REQUEST_TIME_FLOAT'])) {
            $details['loadTime'] = (string) round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 3) . "s";
        }

        if ($details['mimeType'] == 'image/png') {
            $details['pngType'] = $this->getPngTypeAsString(null, $file);
        }

        $options = null;
        if (defined("JSON_PRETTY_PRINT") && defined("JSON_UNESCAPED_SLASHES")) {
            $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES;
        }

        return json_encode($details, $options);
    }
82394
public function write(File $file): string
    {
        $this->createDirectoryIfRequired($file);
        $file->create();
        $file->putContents();

        return $file->getPath();
    }
112867
public function getPath($id, $file = null)
    {
        if (is_null($file)) {
            return sprintf('%s/%s/', $this->baseDir, $id);
        } else {
            return sprintf('%s/%s/%s', $this->baseDir, $id, $file);
        }
    }
368753
static function read($file)
	{
		if(file_exists($file) && is_readable($file))
			return file_get_contents($file);

		foreach(bors_dirs() as $dir)
			if(file_exists($fn = $dir.'/data/'.$file) && is_readable($fn))
				return file_get_contents($fn);

		return NULL;
	}
67556
public function getFileFromZip($file)
    {
        if (false !== $content = $this->zip->getFromName($file)) {
            $tmpDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
            $fileName = $tmpDir . md5($file) . time() . '.' . pathinfo($file, PATHINFO_EXTENSION);
            file_put_contents($fileName, $content);

            $this->destructible[] = $fileName;

            return $fileName;
        }

        return null;
    }
215334
protected function _check_data($file = null) {
        if (empty($this->file_data)) {
            if (is_null($file)) {
                $file = $this->file;
            }

            return $this->load_data($file);
        }

        return true;
    }