Sons of PHP
Source Code
  • 🏠Home
  • Contributor Covenant Code of Conduct
  • Getting Help
  • Reporting Issues
  • Security Policy
  • 🪈Bard
    • Overview
    • Commands
  • Symfony Bundles
    • Feature Toggle
  • Contracts
    • Contracts Overview
    • Common
    • Cookie
    • CQRS
    • Filesystem
    • Mailer
    • Pager
    • Registry
    • State Machine
  • 📦Components
    • Assert
    • Cache
      • Adapters
      • Marshallers
    • Clock
    • Container
    • Cookie
    • CQRS
    • Event Dispatcher
    • Event Sourcing
      • Aggregates
        • Aggregate Repository
      • Event Messages
        • Using the Serializable Event Message
        • Message Enrichers
        • Message Serializers
        • Message Repository
        • Message Upcasters
    • Feature Toggle
    • Filesystem
      • Adapters
    • Http Factory
    • Http Handler
    • Http Message
    • JSON
    • Link
    • Logger
      • Handlers
      • Enrichers
      • Filters
      • Formatters
    • Mailer
      • Transports
    • Money
      • Currency Providers
      • Operators
      • Queries
    • Pager
      • Adapters
    • Registry
    • State Machine
    • Version
  • 💁Contributing
    • Contributing Overview
    • Contributing Code
    • Discussions
    • Documentation
Powered by GitBook
On this page
  • Installation
  • Usage
  • Support for LiipImagineBundle
  • Need Help?

Was this helpful?

Edit on GitHub
  1. Components

Filesystem

This filesystem is more of a virtual filesystem that allows you to keep one interface but is able to manage files on multiple backends. For example, you could use the NativeAdapter to write files to disk and during testing, you can use the NullAdapter so no files are actually written to disk.

Installation

composer require sonsofphp/filesystem

Usage

<?php

use SonsOfPHP\Component\Filesystem\Adapter\NativeAdapter;
use SonsOfPHP\Component\Filesystem\Filesystem;

$filesystem = new Filesystem(new NativeAdapter('/tmp'));

// Write File
$filesystem->write('example.txt', 'Contents to write');

// Read File contents
$content = $filesystem->read('example.txt');

// Delete File
$filesystem->delete('example.txt');

// Check if file exists
$doesExist = $filesystem->exists('example.txt');

// Get MIME Type of file
$mimeType = $filesystem->mimeType('example.txt');

// Copy file
$filesystem->copy('source.txt', 'destination.txt');

// Move file
$filesystem->move('source.txt', 'destination.txt');

Support for LiipImagineBundle

composer require sonsofphp/filesystem-liip-imagine
# config/services.yaml
services:
    SonsOfPHP\Contract\Filesystem\Adapter\AdapterInterface:
        class: SonsOfPHP\Component\Filesystem\Adapter\NativeAdapter
        arguments: ['%kernel.project_dir%/var/data/%kernel.id%']
    SonsOfPHP\Contract\Filesystem\FilesystemInterface:
        class: SonsOfPHP\Component\Filesystem\Filesystem
        arguments: ['@SonsOfPHP\Contract\Filesystem\Adapter\AdapterInterface']
    imagine.cache.resolver.sonsofphp:
      class: SonsOfPHP\Bridge\LiipImagine\Filesystem\Imagine\Cache\Resolver\SonsOfPHPFilesystemResolver
      arguments:
        - '@SonsOfPHP\Contract\Filesystem\FilesystemInterface'
        - 'https://images.example.com'
      tags:
        - { name: "liip_imagine.cache.resolver", resolver: sonsofphp }
# config/packages/liip_imagine.yaml
liip_imagine:
    data_loader: SonsOfPHP\Bridge\LiipImagine\Filesystem\Binary\Loader\SonsOfPHPFilesystemLoader
    cache: sonsofphp

Need Help?

PreviousFeature ToggleNextAdapters

Last updated 8 months ago

Was this helpful?

Check out .

📦
Sons of PHP's Organization Discussions