Opens a file handle.

@param string|resource $file The file to open
@return resource
492874
private function openFile($file)
    {
        if (is_resource($file)) {
            if (get_resource_type($file) !== 'stream') {
                throw new \InvalidArgumentException('The given resource is not a file handle.');
            }
        } else {
            $filename = (string) $file;

            if (!is_file($filename) || !is_readable($filename)) {
                throw new \LogicException(sprintf('File "%s" could not be opened.', $filename));
            }

            $file = fopen($filename, 'r');
        }

        return $file;
    }
570876
public static function file( $file )
	{
		$params = array_merge( static::$params, array(
			'time' => time(),
			'fingerprint' => \CCSession::fingerprint(),
			'random' => CCStr::random(),
		));
		
		foreach( $params as $param => $value )
		{
			$file = str_replace( ':'.$param, $value, $file );
		}
		
		return $file;
	}
720162
public function loadFile($file)
    {
        if (!file_exists($file)) {
            throw new LoaderException("Requested YAML file '{$file}' doesn't exist");
        }

        $contents = file_get_contents($file);

        if ($this->useSymfony) {
            try {
                // Apparently parser keeps references to the things it parses? As such, we want to create a new parser
                // each time (uch)
                $parser = new Parser();
                return $parser->parse($contents);
            } catch (ParseException $e) {
                throw new LoaderException("Could not load the YAML file '{$file}': ".$e->getMessage());
            }
        }

        $data = yaml_parse($contents);
        if (!is_array($data)) {
            throw new LoaderException("Requested YAML file '{$file}' does not parse to an array");
        }

        return $data;
    }
205461
protected function makeReadResource($source)
    {
        if (is_resource($source)) {
            return $source;
        }

        if (is_string($source)) {
            $resource = @fopen($source, 'r');

            if ($resource) {
                return $resource;
            }

            $errorInfo = error_get_last();
            throw new FileException(sprintf(
                'Unable to open the file `%s` for reading%s',
                $source,
                $errorInfo ? ': '.$errorInfo['message'] : ''
            ));
        }

        throw new InvalidArgumentException(sprintf(
            'The given source expected to be a file path of a resource, a %s given',
            is_object($source) ? get_class($source).' instance' : gettype($source)
        ));
    }
756130
private function open(string $folder, string $file): File
    {
        $path = $folder.'/'.$file;

        if (is_dir($path)) {
            $object = new Directory\Directory(
                $file,
                (function($folder) {
                    $handle = opendir($folder);

                    while (($name = readdir($handle)) !== false) {
                        if (\in_array($name, self::INVALID_FILES, true)) {
                            continue;
                        }

                        yield $this->open($folder, $name);
                    }

                    closedir($handle);
                })($path)
            );
        } else {
            try {
                $mediaType = MediaType::fromString(mime_content_type($path));
            } catch (InvalidMediaTypeString $e) {
                $mediaType = new NullMediaType;
            }

            $object = new File\File(
                $file,
                new LazyStream($path),
                $mediaType
            );
        }

        $this->files = $this->files->put($path, $object);

        return $object;
    }
1370420
public function read($file)
    {
        $document = new \DOMDocument();
        $errorToExceptionContext = new ErrorToExceptionContext(E_WARNING, function () use ($file, $document) {
            $document->load($file);
        });
        $errorToExceptionContext->invoke();

        return $this->readDocument($document, pathinfo($file, PATHINFO_FILENAME));
    }
383031
protected function load_file($file)
	{
		$contents = $this->parse_vars(file_get_contents($file));
		return parse_ini_string($contents, true);
	}
1034913
public function updateFileAction(File $file)
    {
        $collection = new ResourceCollection(array($file->getResourceNode()));
        $this->checkAccess('EDIT', $collection);
        $request = $this->get('request');
        $form = $this->get('form.factory')->create(new UpdateFileType(), new File());
        $form->handleRequest($request);

        if ($form->isValid()) {
            $tmpFile = $form->get('file')->getData();
            $this->get('claroline.manager.file_manager')->changeFile($file, $tmpFile);

            if ($this->get('claroline.twig.home_extension')->isDesktop()) {
                $url = $this->generateUrl('claro_desktop_open_tool', array('toolName' => 'resource_manager'));
            } else {
                $url = $this->generateUrl(
                    'claro_workspace_open_tool',
                    array(
                        'toolName' => 'resource_manager',
                        'workspaceId' => $file->getResourceNode()->getWorkspace()->getId()
                    )
                );
            }

            return $this->redirect($url);
        }

        return array(
            'form' => $form->createView(),
            'resourceType' => 'file',
            'file' => $file,
            '_resource' => $file
        );
    }
1135894
public function getFileStream($file, $mode = "w+")
    {

        //Throw some errors
        if (($handle = fopen($file, $mode)) == false) { //this fopen with w will attempt to create the file

            //@Throw error
            return false;
        }

        return $handle;
    }
835538
public function handle($file)
    {
        if (!$mime = $this->getMimeForEmit($file->getExtension())) {
            return $file;
        }
        if (!$file_loc = $file->getLocation()) {
            return $file;
        }
        $file->setMime($mime);
        $file->setFound();
        $fp   = fopen($file_loc, 'r');
        $file->setResource($fp);

        return $file;
    }
459702
protected function loadFile($file)
    {
        if (!stream_is_local($file)) {
            throw new \InvalidArgumentException(sprintf('Procedure file is not a local file: "%s"', $file));
        }

        if (!file_exists($file)) {
            throw new NotExistsException(sprintf('Procedure file does not exist: "%s"', $file));
        }

        return file_get_contents($file);
    }
579893
public function resolve($file)
    {
        $file = implode('_', array_slice(explode('_', $file), 4));

        $class = Str::studly($file);

        return new $class();
    }
1003667
public function handle($file)
    {
        foreach ($this->view_extensions as $ext => $handler) {
            if ($file->exists($ext)) {
                $file = $file->withExtension($ext);
                $file->setMime($handler[1]);
                $file->setFound();
                $handle = $handler[0];
                if (!is_callable($handle)) {
                    $handle = [$this, $handle];
                }
                return call_user_func($handle, $file);
            }
        }

        return $file;
    }
650938
private function loadFile(string $file) : string
    {
        if (!file_exists($file)) {
            throw new \Exception($file . ' not found');
        }
        return (string)file_get_contents($file);
    }
1108930
public function addFile($file, $resource = null)
    {
        if (!file_exists($file) || !is_file($file)) {
            throw new \Exception('The configuration file ' . $file . ' does not exist.');
        } else {
            if ($resource === null) {
                $resource = $file;
            }

            if (!array_key_exists($resource, self::$parameters)) {
                self::$parameters[$resource] = new ParameterBag();
            }

            $content = YamlParser::parse(file_get_contents($file));

            if ($content !== null) {
                $content = self::parseImports($content, $resource);

                $content = self::parseParameters($content, $resource);

                self::addConfig($content, $resource);
            }
        }

        return self::getInstance();
    }
271308
protected function openFile(string $file, string $mode)
    {
        $fp = @fopen($file, $mode);
        if (false === $fp) {
            throw new StreamException(
                    'Can not open file ' . $file . ' with mode ' . $mode . ': '
                    .
                    str_replace('fopen(' . $file . '): ', '', lastErrorMessage())
            );
        }

        return $fp;
    }
977456
public function getFileEditLink($file)
    {
        if (!$file || !$file->isInDB()) {
            return null;
        }

        return Controller::join_links(
            $this->Link('show'),
            $file->ParentID,
            'edit',
            $file->ID
        );
    }