class Pike\FileSystem
Abstraktoi php:n omat tiedostonhallintafunktiot.
Synopsis
class FileSystem implements FileSystemInterface {
/* Metodit */
public write ( string $path, string $content ) : int|false
public read ( string $path ) : string|false
public unlink ( string $path ) : bool
public copy ( string $path, string $destPath ) : bool
public rename ( string $oldPath, string $newPath ) : bool
public move ( string $oldPath, string $newPath ) : bool
public mkDir ( string $path, int $perms = 0755, bool $recursive = true ) : bool
public rmDir ( string $path, $context = null ) : bool
public isFile ( string $path ) : bool
public isDir ( string $path ) : bool
public readDir ( string $path, string $filterPattern = '*', int $flags = GLOB_ERR ) : string[]|false
public readDirRecursive ( string $path, string $filterRegexp = '/.*/', int $flags = FilesystemIterator::CURRENT_AS_PATHNAME ) : mixed[]
public lastModTime ( string $path ) : int|false
public static normalizePath ( string $path ) : string
}
Metodit
write()
Kirjoittaa tiedostoon.
Signature
public function write ( string $path, string $content ) : int|false
Esimerkit
Katso myös Tiedostojen hallinta > Tiedostoon kirjoittaminen.
$numBytesWritten = $fs->write(__DIR__ . '/tiedosto.txt', 'Sisältö');
read()
Lukee tiedoston.
Signature
public function read ( string $path ) : string|false
Esimerkit
Katso myös Tiedostojen hallinta > Tiedoston lukeminen.
$contents = $fs->read(__DIR__ . '/tiedosto.txt');
unlink()
Poistaa tiedoston.
Signature
public function unlink ( string $path ) : bool
Esimerkit
Katso myös Tiedostojen hallinta > Tiedoston poistaminen.
$ok = $fs->unlink(__DIR__ . '/tiedosto.txt');
copy()
Kopioi tiedoston.
Signature
public function copy ( string $path, string $destPath ) : bool
Esimerkit
Katso myös Tiedostojen hallinta > Tiedoston kopioiminen.
$ok = $fs->copy(__DIR__ . '/tiedosto.txt', __DIR__ . '/copied.txt');
rename()
Nimeää tai siirtää tiedoston.
Signature
public function rename ( string $oldPath, string $newPath ) : bool
Esimerkit
Katso myös Tiedostojen hallinta > Tiedoston nimeäminen tai siirtäminen.
$ok = $fs->rename(__DIR__ . '/vanha.txt', __DIR__ . '/uusi.txt');
move()
ks. rename().
mkDir()
Luo kansion tai kansioita.
Signature
public function mkDir ( string $path, int $perms = 0755, bool $recursive = true ) : bool
Esimerkit
Katso myös Tiedostojen hallinta > Kansion luominen.
$ok = $fs->mkDir(__DIR__ . '/kansio');
rmDir()
Poistaa kansion.
Signature
public function rmDir ( string $path, $context = null ) : bool
Esimerkit
Katso myös Tiedostojen hallinta > Kansion poistaminen.
$ok = $fs->rmDir(__DIR__ . '/kansio');
isFile()
Kertoo onko tiedosto olemassa.
Signature
public function isFile ( string $path ) : bool
Esimerkit
Katso myös Tiedostojen hallinta > Tiedostopolun tarkistaminen.
$isFile = $fs->isFile(__DIR__ . '/tiedosto.txt');
isDir()
Kertoo onko kansio olemassa.
Signature
public function isDir ( string $path ) : bool
Esimerkit
Katso myös Tiedostojen hallinta > Kansiopolun tarkistaminen.
$isDir = $fs->isDir(__DIR__ . '/kansio');
readDir()
Lukee kansion sisällön ei-rekursiivisesti.
Signature
public function readDir ( string $path, string $filterPattern = '*', int $flags = GLOB_ERR ) : string[]|false
Esimerkit
Katso myös Tiedostojen hallinta > Kansion sisällön lukeminen (Ei rekursiivinen).
$fullFilePaths = $fs->readDir(__DIR__ . '/kansio');
readDirRecursive()
Lukee kansion sisällön rekursiivisesti.
Signature
public function readDirRecursive ( string $path, string $filterRegexp = '/.*/', int $flags = FilesystemIterator::CURRENT_AS_PATHNAME ) : mixed[]
Esimerkit
Katso myös Tiedostojen hallinta > Kansion sisällön lukeminen (Rekursiivinen).
$fullFilePaths = $fs->readDirRecursive(__DIR__ . '/kansio');
lastModTime()
Kertoo milloin tiedostoa on edellisen kerran muokattu.
Signature
public function lastModTime ( string $path ) : int|false
Esimerkit
Katso myös Tiedostojen hallinta > Viimeisimmän modifikaation lukeminen (Rekursiivinen).
$unixTime = $fs->lastModTime(__DIR__ . '/tiedosto.txt');
static normalizePath()
Normalisoi tiedostopolun.
Signature
public static function normalizePath ( string $path ) : string
Esimerkit
Katso myös Tiedostojen hallinta > Polun normalisointi.
$normalized = FileSystem::normalizePath($notNormalized);