PHP code example of brianhenryie / bh-php-flysystem-readonly

1. Go to this page and download the library: Download brianhenryie/bh-php-flysystem-readonly library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brianhenryie / bh-php-flysystem-readonly example snippets


use BrianHenryIE\FlysystemReadOnly\ReadOnlyFileSystemAdapter;
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;

$adapter = new LocalFilesystemAdapter('/path/to/project');

if ($isDryRun) {
    $adapter = new ReadOnlyFileSystemAdapter($adapter);
}

$filesystem = new Filesystem($adapter);

$filesystem->write('src/Example.php', ' // rewritten');

// The new content is visible...
echo $filesystem->read('src/Example.php');       
//  // rewritten

// ...but the file on disk is untouched.
echo file_get_contents('/path/to/project/src/Example.php');
// Warning: file_get_contents(/path/to/project/src/Example.php): failed to open stream: No such file or directory in Command line code on line 1

$adapter = new ReadOnlyFileSystemAdapter($localAdapter, $myPathNormalizer);

class MyAdapter extends SomeAdapter implements FlysystemAdapterBackCompatTraitInterface
{
    use FlysystemAdapterBackCompatTrait;

    public function normalizePath(string $path): string
    {
        return (new WhitespacePathNormalizer())->normalizePath($path);
    }
}