classes/phing/system/io/PhingFile.php

\PhingFile

An abstract representation of file and directory pathnames.

package
phing.system.io
version
$Revision: 1260 $

Properties

Propertyprivate  $path= 'null'

This abstract pathname's normalized pathname string. A normalized pathname string uses the default name-separator character and does not contain any duplicate or redundant separators.

Default valuenullDetails
Type
Propertypublic  $pathSeparator= ''
static

path separator string, static, obtained from FileSystem (; or :)

Details
Type
Propertyprivateint  $prefixLength= '0'

The length of this abstract pathname's prefix, or zero if it has no prefix.

Default value0Details
Type
int
Propertypublic  $separator= ''
static

separator string, static, obtained from FileSystem

Details
Type

Methods

methodpublic  __construct(  $arg1 = null,  $arg2 = null ) :
constructor
Parameters
Name Type Description
$arg1
$arg2
methodpublic  __toString( ) : string
Return string representation of the object
Returns
Type Description
string
methodprotected  _constructFileParentStringChild( \unknown_type $parent, \unknown_type $child = null ) :
Enter description here ...
Parameters
Name Type Description
$parent \unknown_type
$child \unknown_type
methodprotected  _constructPathname( \unknown_type $pathname ) :
Enter description here ...
Parameters
Name Type Description
$pathname \unknown_type
methodprotected  _constructStringParentStringChild( \unknown_type $parent, \unknown_type $child = null ) :
Enter description here ...
Parameters
Name Type Description
$parent \unknown_type
$child \unknown_type
methodpublic  _slashify( \PhingFile|string $path, boolean $isDirectory ) : string
Enter description here ...
Parameters
Name Type Description
$path \PhingFile|string
$isDirectory boolean
Returns
Type Description
string
methodpublic  canRead( ) : boolean
Tests whether the application can read the file denoted by this abstract pathname.
Returns
Type Description
boolean
methodpublic  canWrite( ) : boolean
Tests whether the application can modify to the file denoted by this abstract pathname.
Returns
Type Description
boolean
methodpublic  compareTo( \PhingFile $file ) : int
Compares two abstract pathnames lexicographically. The ordering defined by this method depends upon the underlying system. On UNIX systems, alphabetic case is significant in comparing pathnames; on Win32 systems it is not.
Parameters
Name Type Description
$file \PhingFile Th file whose pathname sould be compared to the pathname of this file.
Returns
Type Description
int
methodpublic  contents( ) : string
Convenience method for returning the contents of this file as a string.

This method uses file_get_contents() to read file in an optimized way.

Returns
Type Description
string
Details
throws
- if file cannot be read
methodpublic  copyTo( \PhingFile $destFile ) : boolean
Simple-copies file denoted by this abstract pathname into another PhingFile
Parameters
Name Type Description
$destFile \PhingFile The new abstract pathname for the named file
Returns
Type Description
boolean
methodpublic  createNewFile(  $parents = true,  $mode = 0777 ) : boolean
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.
Parameters
Name Type Description
$parents
$mode
Returns
Type Description
boolean
Details
throws
if file can't be created
methodpublic  createTempFile(  $prefix,  $suffix,  $directory ) : \PhingFile
staticStatic method that creates a unique filename whose name begins with $prefix and ends with $suffix in the directory $directory. $directory is a reference to a PhingFile Object.

Then, the file is locked for exclusive reading/writing.

Parameters
Name Type Description
$prefix
$suffix
$directory
Returns
Type Description
\PhingFile
Details
author
manuel holtgrewe, grin@gmx.net
throws
methodpublic  delete(  $recursive = false ) : boolean
Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted.
Parameters
Name Type Description
$recursive
Returns
Type Description
boolean
methodpublic  deleteOnExit( ) :
Requests that the file or directory denoted by this abstract pathname be deleted when php terminates. Deletion will be attempted only for normal termination of php and if and if only Phing::shutdown() is called.

Once deletion has been requested, it is not possible to cancel the request. This method should therefore be used with care.

methodpublic  equals(  $obj ) : boolean
Tests this abstract pathname for equality with the given object.

Returns true if and only if the argument is not null and is an abstract pathname that denotes the same file or directory as this abstract pathname. Whether or not two abstract pathnames are equal depends upon the underlying system. On UNIX systems, alphabetic case is significant in comparing pathnames; on Win32 systems it is not.

Parameters
Name Type Description
$obj
Returns
Type Description
boolean
methodpublic  exists( ) : boolean
Tests whether the file denoted by this abstract pathname exists.
Returns
Type Description
boolean
methodpublic  getAbsoluteFile( ) : string
Returns the absolute form of this abstract pathname. Equivalent to getAbsolutePath.
Returns
Type Description
string
methodpublic  getAbsolutePath( ) : string
Returns the absolute pathname string of this abstract pathname.

If this abstract pathname is already absolute, then the pathname string is simply returned as if by the getPath method. If this abstract pathname is the empty abstract pathname then the pathname string of the current user directory, which is named by the system property user.dir, is returned. Otherwise this pathname is resolved in a system-dependent way. On UNIX systems, a relative pathname is made absolute by resolving it against the current user directory. On Win32 systems, a relative pathname is made absolute by resolving it against the current directory of the drive named by the pathname, if any; if not, it is resolved against the current user directory.

Returns
Type Description
string
Details
see
\#isAbsolute()
methodpublic  getCanonicalFile( ) : \PhingFile
Returns the canonical form of this abstract pathname. Equivalent to getCanonicalPath(.
Returns
Type Description
\PhingFile
methodpublic  getCanonicalPath( ) : string
Returns the canonical pathname string of this abstract pathname.

A canonical pathname is both absolute and unique. The precise definition of canonical form is system-dependent. This method first converts this pathname to absolute form if necessary, as if by invoking the getAbsolutePath() method, and then maps it to its unique form in a system-dependent way. This typically involves removing redundant names such as "." and .. from the pathname, resolving symbolic links (on UNIX platforms), and converting drive letters to a standard case (on Win32 platforms).

Every pathname that denotes an existing file or directory has a unique canonical form. Every pathname that denotes a nonexistent file or directory also has a unique canonical form. The canonical form of the pathname of a nonexistent file or directory may be different from the canonical form of the same pathname after the file or directory is created. Similarly, the canonical form of the pathname of an existing file or directory may be different from the canonical form of the same pathname after the file or directory is deleted.

Returns
Type Description
string
methodpublic  getGroup( ) : int
Retrieve the group of this file.
Returns
Type Description
int
methodpublic  getLinkTarget( ) : string
Returns the target of the symbolic link denoted by this abstract pathname
Returns
Type Description
string
methodpublic  getMode( ) : int
Retrieve the mode of this file.
Returns
Type Description
int
methodpublic  getName( ) : \The
Returns the name of the file or directory denoted by this abstract pathname. This is just the last name in the pathname's name sequence. If the pathname's name sequence is empty, then the empty string is returned.
Returns
Type Description
\The
methodpublic  getParent( ) : \The
Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.

Returns
Type Description
\The
methodpublic  getParentFile( ) : \The
Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.

The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.

Returns
Type Description
\The
methodpublic  getPath( ) : string
Converts this abstract pathname into a pathname string. The resulting string uses the default name-separator character to separate the names in the name sequence.
Returns
Type Description
string
methodpublic  getPathWithoutBase( string $basedir ) : string
Returns path without leading basedir.
Parameters
Name Type Description
$basedir string Base directory to strip
Returns
Type Description
string
Details
uses
\getPath()
methodpublic  getPrefixLength( ) : int
Returns the length of this abstract pathname's prefix.
Returns
Type Description
int
methodpublic  getTempDir( ) : string
Returns the path to the temp directory.
Returns
Type Description
string
methodpublic  getUser( ) : int
Retrieve the owner of this file.
Returns
Type Description
int
methodpublic  isAbsolute( ) : boolean
Tests whether this abstract pathname is absolute. The definition of absolute pathname is system dependent. On UNIX systems, a pathname is absolute if its prefix is "/". On Win32 systems, a pathname is absolute if its prefix is a drive specifier followed by "\\", or if its prefix is "\\".
Returns
Type Description
boolean
methodpublic  isDirectory( ) : boolean
Tests whether the file denoted by this abstract pathname is a directory.
Returns
Type Description
boolean
methodpublic  isFile( ) : boolean
Tests whether the file denoted by this abstract pathname is a normal file. A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.
Returns
Type Description
boolean
methodpublic  isHidden( ) : boolean
Tests whether the file named by this abstract pathname is a hidden file. The exact definition of hidden is system-dependent. On UNIX systems, a file is considered to be hidden if its name begins with a period character ('.'). On Win32 systems, a file is considered to be hidden if it has been marked as such in the filesystem. Currently there seems to be no way to dermine isHidden on Win file systems via PHP
Returns
Type Description
boolean
methodpublic  isLink( ) : boolean
Tests whether the file denoted by this abstract pathname is a symbolic link.
Returns
Type Description
boolean
methodpublic  lastModified( ) : int
Returns the time that the file denoted by this abstract pathname was last modified.
Returns
Type Description
int
methodpublic  length( ) : int
Returns the length of the file denoted by this abstract pathname.

The return value is unspecified if this pathname denotes a directory.

Returns
Type Description
int
methodpublic  listDir( \$filter $filter = null ) : array
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.

If this abstract pathname does not denote a directory, then this method returns null Otherwise an array of strings is returned, one for each file or directory in the directory. Names denoting the directory itself and the directory's parent directory are not included in the result. Each string is a file name rather than a complete path.

There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

Parameters
Name Type Description
$filter \$filter string
Returns
Type Description
array
methodpublic  listFiles( \PhingFile[] $filter = null ) :
Enter description here ...
Parameters
Name Type Description
$filter \PhingFile[]
methodpublic  listRoots( ) : array
List the available filesystem roots.

A particular platform may support zero or more hierarchically-organized file systems. Each file system has a root directory from which all other files in that file system can be reached. Windows platforms, for example, have a root directory for each active drive; UNIX platforms have a single root directory, namely "/". The set of available filesystem roots is affected by various system-level operations such the insertion or ejection of removable media and the disconnecting or unmounting of physical or virtual disk drives.

This method returns an array of PhingFile objects that denote the root directories of the available filesystem roots. It is guaranteed that the canonical pathname of any file physically present on the local machine will begin with one of the roots returned by this method.

The canonical pathname of a file that resides on some other machine and is accessed via a remote-filesystem protocol such as SMB or NFS may or may not begin with one of the roots returned by this method. If the pathname of a remote file is syntactically indistinguishable from the pathname of a local file then it will begin with one of the roots returned by this method. Thus, for example, PhingFile objects denoting the root directories of the mapped network drives of a Windows platform will be returned by this method, while PhingFile objects containing UNC pathnames will not be returned by this method.

Returns
Type Description
array
methodpublic  mkdir(  $mode = 0755 ) : boolean
Creates the directory named by this abstract pathname.
Parameters
Name Type Description
$mode
Returns
Type Description
boolean
Details
throws
methodpublic  mkdirs(  $mode = 0755 ) : boolean
Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.
Parameters
Name Type Description
$mode
Returns
Type Description
boolean
Details
throws
methodpublic  removeTempFile( ) :
If necessary, $File the lock on $File is removed and then the file is deleted
Details
access
public
methodpublic  renameTo( \PhingFile $destFile ) : boolean
Renames the file denoted by this abstract pathname.
Parameters
Name Type Description
$destFile \PhingFile The new abstract pathname for the named file
Returns
Type Description
boolean
methodpublic  setGroup(  $group ) :
Sets the group of the file.
Parameters
Name Type Description
$group
methodpublic  setLastModified( int $time ) : boolean
Sets the last-modified time of the file or directory named by this abstract pathname.

All platforms support file-modification times to the nearest second, but some provide more precision. The argument will be truncated to fit the supported precision. If the operation succeeds and no intervening operations on the file take place, then the next invocation of the lastModified method will return the (possibly truncated) time argument that was passed to this method.

Parameters
Name Type Description
$time int

The new last-modified time, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)

Returns
Type Description
boolean
methodpublic  setMode( int $mode ) :
Sets the mode of the file
Parameters
Name Type Description
$mode int Ocatal mode.
methodpublic  setReadOnly( ) : boolean
Marks the file or directory named by this abstract pathname so that only read operations are allowed. After invoking this method the file or directory is guaranteed not to change until it is either deleted or marked to allow write access. Whether or not a read-only file or directory may be deleted depends upon the underlying system.
Returns
Type Description
boolean
methodpublic  setUser( mixed $user ) :
Sets the owner of the file.
Parameters
Name Type Description
$user mixed User name or number.
methodpublic  toString( ) : string
Backwards compatibility - @see __toString()
Returns
Type Description
string
methodpublic  toURI( ) : void
Constructs a file: URI that represents this abstract pathname.
Details
todo
Not implemented yet
methodpublic  toURL( ) : void
Converts this abstract pathname into a file: URL. The exact form of the URL is system-dependent. If it can be determined that the file denoted by this abstract pathname is a directory, then the resulting URL will end with a slash.

Usage note: This method does not automatically escape characters that are illegal in URLs. It is recommended that new code convert an abstract pathname into a URL by first converting it into a URI, via the toURI() method, and then converting the URI into a URL via the URI::toURL()

Details
todo
Not implemented yet
Documentation was generated by DocBlox 0.13.1.