PhiO: Object-oriented filesystem library for PHP
  • Namespace
  • Class
  • Tree
  • Todo

Namespaces

  • amekusa
    • phio
  • PHP

Classes

  • Directory
  • File
  • FilePool
  • Filter
  • Perms
  • RegexFilter
  • RegFile

Exceptions

  • ErrorException
  • IOException

Class File

File abstraction

Direct known subclasses

amekusa\phio\Directory, amekusa\phio\RegFile

Abstract
Namespace: amekusa\phio
Author: amekusa post@amekusa.com
Located at File.php

Methods summary

public static amekusa\phio\File
# create( string $Path )

Creates a proper object of amekusa\phio\File subclass from a path

Creates a proper object of amekusa\phio\File subclass from a path

If the path indicates:

  • a directory, creates a amekusa\phio\Directory object.
  • a file, creates a amekusa\phio\RegFile object.

Parameters

$Path

Returns

amekusa\phio\File

Example

Passing an existing directory path, creates a amekusa\phio\Directory object

use amekusa\phio\Directory;

$dir = File::create(__DIR__);

echo 'Is $dir a directory? - ';
echo $dir instanceof Directory ? 'Yes.' : 'No.';
Is $dir a directory? - Yes.

Passing an existing regular file path or non-existent path, creates a amekusa\phio\RegFile object

use amekusa\phio\RegFile;

$file = File::create(__FILE__);

echo 'Is $file a regular file? - ';
echo $file instanceof RegFile ? 'Yes.' : 'No.';
Is $file a regular file? - Yes.

public static amekusa\phio\File
# instance( string $Path, boolean $ForceNew = false )

Returns a amekusa\phio\File instance associated with a specific file path

Returns a amekusa\phio\File instance associated with a specific file path

The operation is the same as amekusa\phio\File::create($Path) except for the returned object is cached in amekusa\phio\FilePool.

Parameters

$Path
The path of a file
$ForceNew
If true, always returns a newly created instance of amekusa\phio\File

Returns

amekusa\phio\File

Example

Cache Demonstration

$X1 = File::create(__FILE__);         // Not cached
$Y1 = File::create(__FILE__);         // Not cached

$X2 = File::instance(__FILE__);       // Not cached
$Y2 = File::instance(__FILE__);       // Cached

$X3 = File::instance(__FILE__, true); // Not cached
$Y3 = File::instance(__FILE__, true); // Not cached
$Z3 = File::instance(__FILE__);       // Cached

echo 'Are $X1 and $Y1 identical? - ';
echo $X1 === $Y1 ? 'Yes.' : 'No.';
echo "\n";

echo 'Are $X2 and $Y2 identical? - ';
echo $X2 === $Y2 ? 'Yes.' : 'No.';
echo "\n";

echo 'Are $X3 and $Y3 identical? - ';
echo $X3 === $Y3 ? 'Yes.' : 'No.';
echo "\n";

echo 'Are $Y3 and $Z3 identical? - ';
echo $Y3 === $Z3 ? 'Yes.' : 'No.';
Are $X1 and $Y1 identical? - No.
Are $X2 and $Y2 identical? - Yes.
Are $X3 and $Y3 identical? - No.
Are $Y3 and $Z3 identical? - Yes.

public
# __construct( string $Path )

Creates a amekusa\phio\File object from a path

Creates a amekusa\phio\File object from a path

Parameters

$Path
File path
public
# __toString( )
public
# isExclusive( )
public
# isOpened( )
public boolean
# exists( )

Returns

boolean
public string
# getPath( )

Returns

string
public string
# getName( )

Returns

string
public amekusa\phio\Perms
# getPerms( )

Returns

amekusa\phio\Perms
public integer|string
# modifiedAt( string $Format = '' )

Parameters

$Format

Returns

integer|string
public amekusa\phio\File
# beExclusive( boolean $IsExclusive = true )

Parameters

$IsExclusive

Returns

amekusa\phio\File
public
# open( )
public
# close( )
public
# moveTo( string|amekusa\phio\Directory $Destination )

Moves this file to another directory

Moves this file to another directory

Parameters

$Destination
The directory that this file moves to

Throws

amekusa\phio\IOException
on failure
public
# remove( )
PhiO: Object-oriented filesystem library for PHP API documentation generated by ApiGen