TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FileStreamWrapper Class Reference

Public Member Functions

 dir_closedir ()
 
 dir_opendir ($path, $options=0)
 
 dir_readdir ()
 
 dir_rewinddir ()
 
 mkdir ($path, $mode, $options=0)
 
 rename ($pathFrom, $pathTo)
 
 rmdir ($path)
 
 stream_cast ($castAs)
 
 stream_close ()
 
 stream_eof ()
 
 stream_flush ()
 
 stream_lock ($operation)
 
 stream_metadata ($path, $options, $value)
 
 stream_open ($path, $mode, $options, &$opened_path)
 
 stream_read ($length)
 
 stream_seek ($offset, $whence=SEEK_SET)
 
 stream_set_option ($option, $arg1, $arg2)
 
 stream_stat ()
 
 stream_tell ()
 
 stream_truncate ($size)
 
 stream_write ($data)
 
 unlink ($path)
 
 url_stat ($path, $flags)
 

Static Public Member Functions

static init ($rootPath)
 
static destroy ()
 
static registerOverlayPath ($overlay, $replace, $createFolder=true)
 

Static Protected Member Functions

static overlayPath ($path)
 
static register ()
 
static restore ()
 

Protected Attributes

 $dirHandle = null
 
 $fileHandle = null
 

Static Protected Attributes

static $registered = false
 
static $overlayPaths = []
 
static $rootPath = ''
 

Detailed Description

Stream wrapper for the file:// protocol

Implementation details: Due to the nature of PHP, it is not possible to switch to the default handler other then restoring the default handler for file:// and registering it again around each call. It is important that the default handler is restored to allow autoloading (including) of files during the test run. For each method allowed to pass paths, the passed path is checked against the the list of paths to overlay and rewritten if needed.

= Usage = use org; use org;

$root = ::setup('root'); $subfolder = ::newDirectory('fileadmin'); $root->addChild($subfolder); // Load fixture files and folders from disk ::copyFromFileSystem(DIR . '/Fixture/Files', $subfolder, 1024*1024); FileStreamWrapper::init(PATH_site); FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin');

// Use file functions as usual mkdir(PATH_site . 'fileadmin/test/'); $file = PATH_site . 'fileadmin/test/Foo.bar'; file_put_contents($file, 'Baz'); $content = file_get_contents($file); $this->assertSame('Baz', $content);

$this->assertEqual(array(file system structure as array), vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure());

FileStreamWrapper::destroy();

See also
http://www.php.net/manual/en/class.streamwrapper.php

Definition at line 58 of file FileStreamWrapper.php.

Member Function Documentation

dir_closedir ( )

Close the directory

Returns
bool

Definition at line 212 of file FileStreamWrapper.php.

dir_opendir (   $path,
  $options = 0 
)

Opens a directory for reading

Parameters
string$path
int$options
Returns
bool

Definition at line 232 of file FileStreamWrapper.php.

dir_readdir ( )

Read a single filename of a directory

Returns
string|bool

Definition at line 249 of file FileStreamWrapper.php.

dir_rewinddir ( )

Reset directory name pointer

Returns
bool

Definition at line 265 of file FileStreamWrapper.php.

mkdir (   $path,
  $mode,
  $options = 0 
)

Create a directory

Parameters
string$path
int$mode
int$options
Returns
bool

Definition at line 284 of file FileStreamWrapper.php.

Referenced by FileStreamWrapper\registerOverlayPath().

static overlayPath (   $path)
staticprotected

Checks and overlays a path

Parameters
string$pathThe path to check
Returns
string The potentially overlaid path

Definition at line 140 of file FileStreamWrapper.php.

static register ( )
staticprotected

Method to register the stream wrapper

If the stream is already registered the method returns silently. If there is already another stream wrapper registered for the scheme used by file:// scheme a will be thrown.

Exceptions
BadFunctionCallException
Returns
void

Definition at line 170 of file FileStreamWrapper.php.

static registerOverlayPath (   $overlay,
  $replace,
  $createFolder = true 
)
static

Register a path relative to the root path (set in init) to be overlaid

Parameters
string$overlayRelative path to the root folder
string$replaceThe path that should replace the overlay path
bool$createFolderTRUE of the folder should be created (mkdir)
Returns
void

Definition at line 124 of file FileStreamWrapper.php.

References FileStreamWrapper\mkdir().

Referenced by LocalDriverTest\getFileReturnsCorrectIdentifier(), LocalDriverTest\getSpecificFileInformationReturnsRequestedFileInformation(), GeneralUtilityTest\mkdirDeepCreatesDirectoryWithDoubleSlashes(), FileStreamWrapperTest\pathsAreOverlaidAndFinalDirectoryStructureCanBeQueried(), FileStreamWrapperTest\symlinksCanBeCreated(), and FileStreamWrapperTest\windowsPathsCanBeProcessed().

rename (   $pathFrom,
  $pathTo 
)

Rename a file

Parameters
string$pathFrom
string$pathTo
Returns
bool

Definition at line 300 of file FileStreamWrapper.php.

static restore ( )
staticprotected

Restore the file handler

Returns
void

Definition at line 191 of file FileStreamWrapper.php.

rmdir (   $path)

Remove a directory

Parameters
string$path
Returns
bool

Definition at line 316 of file FileStreamWrapper.php.

stream_cast (   $castAs)

Retrieve the underlying resource

Parameters
int$castAsCan be STREAM_CAST_FOR_SELECT when stream_select() is calling stream_cast() or STREAM_CAST_AS_STREAM when stream_cast() is called for other uses.
Returns
resource|bool

Definition at line 333 of file FileStreamWrapper.php.

References FileStreamWrapper\$fileHandle.

stream_close ( )

Close a file

Definition at line 346 of file FileStreamWrapper.php.

stream_eof ( )

Test for end-of-file on a file pointer

Returns
bool

Definition at line 361 of file FileStreamWrapper.php.

stream_flush ( )

Flush the output

Returns
bool

Definition at line 377 of file FileStreamWrapper.php.

stream_lock (   $operation)

Advisory file locking

Parameters
int$operation
Returns
bool

Definition at line 394 of file FileStreamWrapper.php.

stream_metadata (   $path,
  $options,
  $value 
)

Change file options

Parameters
string$path
int$options
mixed$value
Returns
bool

Definition at line 413 of file FileStreamWrapper.php.

stream_open (   $path,
  $mode,
  $options,
$opened_path 
)

Open a file

Parameters
string$path
string$mode
int$options
string&$opened_path
Returns
bool

Definition at line 450 of file FileStreamWrapper.php.

stream_read (   $length)

Read from a file

Parameters
int$length
Returns
string

Definition at line 468 of file FileStreamWrapper.php.

stream_seek (   $offset,
  $whence = SEEK_SET 
)

Seek to specific location in a stream

Parameters
int$offset
int$whence= SEEK_SET
Returns
bool

Definition at line 486 of file FileStreamWrapper.php.

stream_set_option (   $option,
  $arg1,
  $arg2 
)

Change stream options (not implemented)

Parameters
int$option
int$arg1
int$arg2
Returns
bool

Definition at line 505 of file FileStreamWrapper.php.

stream_stat ( )

Retrieve information about a file resource

Returns
array

Definition at line 515 of file FileStreamWrapper.php.

stream_tell ( )

Retrieve the current position of a stream

Returns
int

Definition at line 531 of file FileStreamWrapper.php.

stream_truncate (   $size)

Truncates a file to the given size

Parameters
int$sizeTruncate to this size
Returns
bool

Definition at line 548 of file FileStreamWrapper.php.

stream_write (   $data)

Write to stream

Parameters
string$data
Returns
int

Definition at line 565 of file FileStreamWrapper.php.

unlink (   $path)

Unlink a file

Parameters
string$path
Returns
bool

Definition at line 582 of file FileStreamWrapper.php.

url_stat (   $path,
  $flags 
)

Retrieve information about a file

Parameters
string$path
int$flags
Returns
array

Definition at line 598 of file FileStreamWrapper.php.

Member Data Documentation

$dirHandle = null
protected

Definition at line 63 of file FileStreamWrapper.php.

$fileHandle = null
protected

Definition at line 68 of file FileStreamWrapper.php.

Referenced by FileStreamWrapper\stream_cast().

$overlayPaths = []
staticprotected

Definition at line 82 of file FileStreamWrapper.php.

$registered = false
staticprotected

Switch whether class has already been registered as stream wrapper or not

bool

Definition at line 75 of file FileStreamWrapper.php.

$rootPath = ''
staticprotected

Definition at line 89 of file FileStreamWrapper.php.

Referenced by FileStreamWrapper\init().