@param \Bitbucket\HttpClient\Message\FileResource $file

@throws \Http\Client\Exception

@return array
505637
public function create(FileResource $file)
    {
        $path = $this->buildUsersPath();
        $builder = (new MultipartStreamBuilder())->addResource($file->getName(), $file->getResource(), $file->getOptions());
        $headers = ['Content-Type' => sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())];

        return $this->postRaw($path, $builder->build(), $headers);
    }
1211066
protected static function getSourceCode($file, $line)
    {
        $first = ($line - 9 > 0) ? $line - 9 : 1;

        try {
            $contents = file($file);
            $source = [
                'first' => $first,
                'source' => array_slice($contents, $first - 1, 19),
            ];
        } catch (Exception $e) {
            $source = [];
        }

        return $source;
    }
187719
public function parseFile($file)
    {
        $bundleConfig = Yaml::parse(file_get_contents(realpath($file)));

        if (!is_array($bundleConfig)) {
            return array();
        }

        return $bundleConfig;
    }
674980
private static function getLinks(string $file): array
    {
        $links    = [];
        $contents = (string)file_get_contents($file);
        if (false !== preg_match_all(
            '/\[(.+?)\].*?\((.+?)\)/',
            $contents,
            $matches,
            PREG_SET_ORDER
        )) {
            $links = array_merge($links, $matches);
        }

        return $links;
    }
734158
protected function getFile($file)
    {
        $mapping = [
            '%environment%' => $this->runtime->getEnvironment(),
        ];

        if ($this->runtime->getHostName() !== null) {
            $mapping['%host%'] = $this->runtime->getHostName();
        }

        if ($this->runtime->getReleaseId() !== null) {
            $mapping['%release%'] = $this->runtime->getReleaseId();
        }

        $options = $this->getOptions();
        return str_replace(
            array_keys($mapping),
            array_values($mapping),
            $options[$file]
        );
    }
209695
public function loadFile($file)
    {
        if (!file_exists($file)) {
            throw new LoaderException("Requested file '{$file}' doesn't exist");
        }

        $data = include($file);

        if (!is_array($data)) {
            throw new LoaderException("Requested file '{$file}' is expected to return an array");
        }

        return $data;
    }
49976
protected function getTranslations(string $file) : array
    {
        return $this->files->exists($file) ? (array) json_decode($this->files->get($file)) : [];
    }
680010
public static function removeFile($file)
    {
        if (!is_readable($file) || !is_file($file)) {
            throw new Exception('No such file: ' . $file);
        }
        $res = unlink($file);
        if (false === $res) {
            throw new Exception('File deleting failure: ' . $file);
        }
        return $res;
    }
44893
public function read($file)
    {
        $file = '/data/' . $file;

        /**
         * @todo validate that $file is a string
         */

        $result = [];

        $ext = pathinfo($file, PATHINFO_EXTENSION);

        if (isset($this->converters[$ext])) {

            $meta = [];

            $content = '';

            $file_contents = $this->source_filesystem->read($file);

            if ($file_contents) {

                $parts = preg_split('/\-{3}/', $file_contents, 3);

                if (count($parts) === 3) {

                    $meta = $parts[1] ?: [];

                    $content = $parts[2];
                } else {

                    $content = $file_contents;
                }

                $result = $this->yaml->parse($meta);

                $content = $this->converters[$ext]->convert($content);

                $result['content'] = trim($content);
            }
        }

        return $result;
    }
44835
public function loadFile($file)
    {
        if (is_array($file)) {
            return collect($file)->mapWithKeys(function ($subFile, $key) {
                return [$key => $this->loadFile($subFile)];
            })->toArray();
        }

        return $this->parser->parseFile($file);
    }
905275
public function loadFile(string $file) : array
    {
        if (!file_exists($file)) {
            throw new LoaderException("Requested YAML file '{$file}' doesn't exist");
        }

        if (!$this->forceSymfony && $this->hasExtension) {
            $data = yaml_parse_file($file);
        } else {
            $data = Yaml::parse(file_get_contents($file));
        }

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

        return $data;
    }
629088
private function _getDomainObjectsFromFile($file)
    {
        $result = array();

        if (fnmatch("*.php", $file)) {
            foreach ($this->_getClassFiles($file) as $namespace=>$classes) {
                foreach ($classes as $class) {
                    $fullClass = empty($namespace) ? "\\$class" : "\\$namespace\\$class";

                    $reflection = new \ReflectionClass($fullClass);
                    if (is_a($fullClass, "\Pheasant\DomainObject", true) && $reflection->isInstantiable()) {
                        $result []= $fullClass;
                    }
                }
            }
        }

        return $result;
    }
1369899
public function validateFile($file)
    {
        if (file_exists($file) !== true) {
            throw new Exception('File not found');
        }
        if (is_readable($file) !== true) {
            throw new Exception('File not readable');
        }

        $data = file_get_contents($file);
        if ($data === false) {
            throw new Exception('Failed get file');
        }

        return $this->validateFragment($data);
    }
1306200
protected static function loadFromFile(?string $file)
    {
        if ($file === null) {
            return [];
        }

        $ext = \strrchr($file, '.');
        if ($ext === '.yml' || $ext === '.yaml') {
            return static::loadYaml($file, $ext);
        }

        return require $file;
    }
1105308
private function parseIniFile(string $file): array
    {
        $ini = parse_ini_file($file, true);

        if (!\is_array($ini)) {
            throw new \RuntimeException("File $file cannot be decoded");
        }

        if (!isset($ini['requires']) || !\is_array($ini['requires'])) {
            return [];
        }

        return $ini['requires'];
    }
831558
protected function process(SplFileInfo $file): array
    {
        /** @var FileLoaderAdapterInterface $adapter */
        foreach ($this->adapters as $adapter) {
            if ($adapter->doesHandle($file)) return $adapter->process($file->getRealPath());
        }

        return [];

    }
152814
public function serialize(File $file)
    {
        $options = [
            'id' => $file->getId(),
            'size' => $file->getSize(),
            'autoDownload' => $file->getAutoDownload(),
            'commentsActivated' => $file->getResourceNode()->isCommentsActivated(),
            'hashName' => $file->getHashName(),

            // We generate URL here because the stream API endpoint uses ResourceNode ID,
            // but the new api only contains the ResourceNode UUID.

            // NB : This will no longer be required when the stream API will use UUIDs
            'url' => $this->router->generate('claro_file_get_media', [
                'node' => $file->getResourceNode()->getId(),
            ]),
        ];

        return $options;
    }