TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Core\Tests\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

◆ destroy()

◆ dir_closedir()

TYPO3\CMS\Core\Tests\FileStreamWrapper::dir_closedir ( )

Close the directory

Returns
bool

Definition at line 212 of file FileStreamWrapper.php.

◆ dir_opendir()

TYPO3\CMS\Core\Tests\FileStreamWrapper::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()

TYPO3\CMS\Core\Tests\FileStreamWrapper::dir_readdir ( )

Read a single filename of a directory

Returns
string|bool

Definition at line 249 of file FileStreamWrapper.php.

◆ dir_rewinddir()

TYPO3\CMS\Core\Tests\FileStreamWrapper::dir_rewinddir ( )

Reset directory name pointer

Returns
bool

Definition at line 265 of file FileStreamWrapper.php.

◆ init()

◆ mkdir()

TYPO3\CMS\Core\Tests\FileStreamWrapper::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 TYPO3\CMS\Core\Tests\FileStreamWrapper\registerOverlayPath().

◆ overlayPath()

static TYPO3\CMS\Core\Tests\FileStreamWrapper::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.

◆ register()

static TYPO3\CMS\Core\Tests\FileStreamWrapper::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

Definition at line 170 of file FileStreamWrapper.php.

◆ registerOverlayPath()

static TYPO3\CMS\Core\Tests\FileStreamWrapper::registerOverlayPath (   $overlay,
  $replace,
  $createFolder = true 
)
static

◆ rename()

TYPO3\CMS\Core\Tests\FileStreamWrapper::rename (   $pathFrom,
  $pathTo 
)

Rename a file

Parameters
string$pathFrom
string$pathTo
Returns
bool

Definition at line 300 of file FileStreamWrapper.php.

◆ restore()

static TYPO3\CMS\Core\Tests\FileStreamWrapper::restore ( )
staticprotected

Restore the file handler

Returns
void

Definition at line 191 of file FileStreamWrapper.php.

◆ rmdir()

TYPO3\CMS\Core\Tests\FileStreamWrapper::rmdir (   $path)

Remove a directory

Parameters
string$path
Returns
bool

Definition at line 316 of file FileStreamWrapper.php.

◆ stream_cast()

TYPO3\CMS\Core\Tests\FileStreamWrapper::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 TYPO3\CMS\Core\Tests\FileStreamWrapper\$fileHandle.

◆ stream_close()

TYPO3\CMS\Core\Tests\FileStreamWrapper::stream_close ( )

Close a file

Definition at line 346 of file FileStreamWrapper.php.

◆ stream_eof()

TYPO3\CMS\Core\Tests\FileStreamWrapper::stream_eof ( )

Test for end-of-file on a file pointer

Returns
bool

Definition at line 361 of file FileStreamWrapper.php.

◆ stream_flush()

TYPO3\CMS\Core\Tests\FileStreamWrapper::stream_flush ( )

Flush the output

Returns
bool

Definition at line 377 of file FileStreamWrapper.php.

◆ stream_lock()

TYPO3\CMS\Core\Tests\FileStreamWrapper::stream_lock (   $operation)

Advisory file locking

Parameters
int$operation
Returns
bool

Definition at line 394 of file FileStreamWrapper.php.

◆ stream_metadata()

TYPO3\CMS\Core\Tests\FileStreamWrapper::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()

TYPO3\CMS\Core\Tests\FileStreamWrapper::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()

TYPO3\CMS\Core\Tests\FileStreamWrapper::stream_read (   $length)

Read from a file

Parameters
int$length
Returns
string

Definition at line 468 of file FileStreamWrapper.php.

◆ stream_seek()

TYPO3\CMS\Core\Tests\FileStreamWrapper::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()

TYPO3\CMS\Core\Tests\FileStreamWrapper::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()

TYPO3\CMS\Core\Tests\FileStreamWrapper::stream_stat ( )

Retrieve information about a file resource

Returns
array

Definition at line 515 of file FileStreamWrapper.php.

◆ stream_tell()

TYPO3\CMS\Core\Tests\FileStreamWrapper::stream_tell ( )

Retrieve the current position of a stream

Returns
int

Definition at line 531 of file FileStreamWrapper.php.

◆ stream_truncate()

TYPO3\CMS\Core\Tests\FileStreamWrapper::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()

TYPO3\CMS\Core\Tests\FileStreamWrapper::stream_write (   $data)

Write to stream

Parameters
string$data
Returns
int

Definition at line 565 of file FileStreamWrapper.php.

◆ unlink()

TYPO3\CMS\Core\Tests\FileStreamWrapper::unlink (   $path)

Unlink a file

Parameters
string$path
Returns
bool

Definition at line 582 of file FileStreamWrapper.php.

◆ url_stat()

TYPO3\CMS\Core\Tests\FileStreamWrapper::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

TYPO3\CMS\Core\Tests\FileStreamWrapper::$dirHandle = null
protected

Definition at line 63 of file FileStreamWrapper.php.

◆ $fileHandle

TYPO3\CMS\Core\Tests\FileStreamWrapper::$fileHandle = null
protected

◆ $overlayPaths

TYPO3\CMS\Core\Tests\FileStreamWrapper::$overlayPaths = []
staticprotected

Definition at line 82 of file FileStreamWrapper.php.

◆ $registered

TYPO3\CMS\Core\Tests\FileStreamWrapper::$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

TYPO3\CMS\Core\Tests\FileStreamWrapper::$rootPath = ''
staticprotected

Definition at line 89 of file FileStreamWrapper.php.

Referenced by TYPO3\CMS\Core\Tests\FileStreamWrapper\init().