Serve public file

@param string $key

@return Response
355710
public function servePublicFile($key)
  {
    $SecurityFile = $this->SecurityFile->byKey($key)->first();

    if(!is_null($SecurityFile))
    {
      $File = $this->File->byKeyAndPublicWithConnectionName($key, true, $SecurityFile->organization->database_connection_name)->first();
    }
    else
    {
      $File = $this->File->byKeyAndPublic($key, true)->first();
    }

    if(!is_null($File))
    {
      return $this->serveFile($File->system_type, $File->system_route, $File->name);
    }

    return $this->Redirector->to($this->AppManager->getErrorPageUrl())->withError($this->Lang->get('decima-file::file-management.fileNotFound'));
  }
560964
public function post(string $key)
    {
        if (array_key_exists($key, $this->post)) {
            return $this->post[$key];
        }

        return '';
    }
1041761
public function load($key)
    {
        if (file_exists($path = $this->path . $key)) {
            return unserialize(file_get_contents($path));
        }

        return null;
    }
1163684
private function read($key)
    {
        $_jsonFile = $this->_root.$key.'.json';
        if(empty($this->_nr[$key])) {
            if (file_exists($_jsonFile)) {
                $_ar = @file_get_contents($_jsonFile);
                $ar = json_decode($_ar,true);
            } else {
                $ar = array();
            }
            $this->_nr[$key] = $ar;
        }
        return $this;
    }
349924
public function read($key)
    {
        if (!isset($this->cacheDirectory)) {
            return;
        }

        $this->loadCacheMetaData();

        return unserialize(file_get_contents($this->cacheDirectory . '/' . $key));
    }
963739
public function post($key = NULL, $default = NULL)
    {
        if ( !$key ) {
            return $this->request->all();
        }

        $path = '';
        $key  = explode('.', $key);
        foreach ($key as $item) {
            if ( !$path ) {
                $path .= $item;
                continue;
            }
            $path .= '[' . $item . ']';
        }

        return $this->request->get($path, $default, TRUE);
    }
542798
public function fetch($key)
    {
        $file_name = $this->getFilePath($key);
        if (!\file_exists($file_name) || !\is_readable($file_name)) {
            return false;
        } else {
            $h = \fopen($file_name, 'r');
            //lock file
            \flock($h, LOCK_SH);
        }

        $data = \file_get_contents($file_name);

        //release lock
        \fclose($h);

        $data = @\unserialize($data);

        //check to see if it expired
        if ($data && ($data[0] == 0 || time() <= $data[0])) {
            return $data[1];
        } else {
            $this->delete($key);
            return false;
        }

        return $data[1];
    }
136170
public static function get(string $key)
    {
        $encodedValue = @file_get_contents(self::determineDabaseFilePathFor($key));
        if ($encodedValue === false) {
            return null;
        }

        return Json::decode($encodedValue);
    }
915345
public function request(string $key, $default = null)
  {
    return $this->get($key) ?: $this->post($key) ?: $this->files($key) ?: $default;
  }
728807
protected function loadConfigFile(string $key)
    {
        $key = strtolower($key);
        $filename = $this->path . DIRECTORY_SEPARATOR . ucfirst($key) . Config::CONFIG_FILE_EXTENSION;

        if (file_exists($filename)) {
            $this->configuration[$key] = require $filename;
            return;
        }

        throw new ConfigException('Unable to load resource: ' . $filename);
    }
1038922
public function serve($path, SymfonyRequest $request, $disposition = 'inline', $fileName = null, $prepared = true)
    {
        if (! file_exists($path)) {
            return new Response('File Not Found', 404);
        } else if (! is_readable($path)) {
            return new Response('Unauthorized Access', 403);
        }

        // Create a Binary File Response instance.
        $headers = array(
            'Access-Control-Allow-Origin' => '*',
        );

        $mimeType = $this->guessMimeType($path);

        if ($request->getMethod() == 'OPTIONS') {
            $headers = array_merge($headers, array(
                'Access-Control-Allow-Methods' => 'GET, HEAD, OPTIONS',
                'Access-Control-Allow-Headers' => 'Content-Type, X-Auth-Token, Origin',
            ));

            return new Response('OK', 200, $headers);
        }

        // Not an OPTIONS request.
        else {
            $headers['Content-Type'] = $mimeType;
        }

        if ($mimeType !== 'application/json') {
            $response = new BinaryFileResponse($path, 200, $headers, true, $disposition, true, false);

            // Set the Content Disposition.
            $response->setContentDisposition($disposition, $fileName ?: basename($path));

            // Setup the (browser) Cache Control.
            $this->setupCacheControl($response);

            // Setup the Not Modified since...
            $response->isNotModified($request);
        } else {
            // We will do a special processing for the JSON files.
            $response = new JsonResponse(
                json_decode(file_get_contents($path), true), 200, $headers
            );
        }

        // Prepare the Response against the Request instance, if is requested.
        if ($prepared) {
            return $response->prepare($request);
        }

        return $response;
    }
600831
public function retrieve(string $key)
  {
    $file = $this->file;

    if (file_exists($file)) {
      $data = unserialize($this->decrypt(file_get_contents($file)));

      if (isset($data[$key])) {
        return $data[$key];
      }
    }

    return null;
  }
1216428
protected function getFileKey($key)
    {
        $key = (string) $key;
        if (!array_key_exists($key, $this->fileKeys))
        {
            $this->fileKeys[$key] = new FileKey($key);
        }
        
        return $this->fileKeys[$key];
    }
697281
public function file($key = null, $default = null)
    {
        if ($this->needParser()) {
            $this->treatPutRequest();
            $fileObjects = [];
            if ($this->hasFile($key)) {
                $files = $this->fileParser->getFiles($key);
                foreach ($files as $key => $file) {
                    $originalName  = Arr::get($file, 'name');
                    $mimeType      = Arr::get($file, 'type');
                    $path          = Arr::get($file, 'tmp_name');
                    $size          = Arr::get($file, 'size');
                    $fileObjects[] = new \Illuminate\Http\UploadedFile($path, $originalName, $mimeType, $size);
                }
            }
            if (count($fileObjects) == 0) {
                return $default;
            } elseif (count($fileObjects) == 1) {
                return $fileObjects[0];
            }

            return $fileObjects;
        }

        return parent::file($key, $default);
    }
1038602
public static function files(string $key = null)
    {
        if (!isset($_FILES[$key])) {
            return null;
        }
        if (is_array($_FILES[$key]['name'])) {
            return self::getFileObjects($key);
        } else {
            return new filesystem\UploadedFile($_FILES);
        }
    }
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();
        }
    };
}
1012222
private function loadFileContentPhaseOne($key)
    {
        // Settings from config
        $basepath = $this->config["basePath"];
        $filter   = $this->config["textfilter-frontmatter"];

        // Whole path to file
        $path = $basepath . "/" . $this->index[$key]["file"];

        // Load content from file
        if (!is_file($path)) {
            $msg = t("The content '!ROUTE' does not exists as a file '!FILE'.", ["!ROUTE" => $key, "!FILE" => $path]);
            throw new \Anax\Exception\NotFoundException($msg);
        }

        // Get filtered content
        $src = file_get_contents($path);
        $filtered = $this->di->get("textfilter")->parse($src, $filter);

        return $filtered;
    }