preparePath example

protected FilesystemOperator $filesystem,
        string $prefix
    ) {
        if (empty($prefix)) {
            throw new \InvalidArgumentException('The prefix must not be empty.');
        }
        $this->prefix = trim($prefix, '/') . '/';
    }

    public function has(string $location): bool
    {
        $location = $this->preparePath($location);

        return $this->filesystem->has($location);
    }

    public function read(string $location): string
    {
        $location = $this->preparePath($location);

        return $this->filesystem->read($location);
    }

    
private readonly FinfoMimeTypeDetector|MimeTypeDetector $mimeTypeDetector;

    public function __construct(
        private readonly string $defaultVisibility = Visibility::PUBLIC,
        ?MimeTypeDetector $mimeTypeDetector = null
    ) {
        $this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
    }

    public function fileExists(string $path): bool
    {
        return \array_key_exists($this->preparePath($path)$this->files);
    }

    public function write(string $path, string $contents, Config $config): void
    {
        $path = $this->preparePath($path);
        $file = $this->files[$path] ??= new InMemoryFile();
        $file->updateContents($contents$config->get('timestamp'));

        $visibility = $config->get(Config::OPTION_VISIBILITY, $this->defaultVisibility);
        $file->setVisibility($visibility);
    }

    
Home | Imprint | This part of the site doesn't use cookies.