Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker/src/Symfony/Filesyst...
File: Filesystem.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of the Symfony package.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier <fabien@symfony.com>
[5] Fix | Delete
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Provides basic utility to manipulate the file system.
[12] Fix | Delete
*
[13] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[14] Fix | Delete
*/
[15] Fix | Delete
class Symfony_Filesystem_Filesystem
[16] Fix | Delete
{
[17] Fix | Delete
/**
[18] Fix | Delete
* Copies a file.
[19] Fix | Delete
*
[20] Fix | Delete
* This method only copies the file if the origin file is newer than the target file.
[21] Fix | Delete
*
[22] Fix | Delete
* By default, if the target already exists, it is not overridden.
[23] Fix | Delete
*
[24] Fix | Delete
* @param string $originFile The original filename
[25] Fix | Delete
* @param string $targetFile The target filename
[26] Fix | Delete
* @param bool $override Whether to override an existing file or not
[27] Fix | Delete
*
[28] Fix | Delete
* @throws Symfony_Filesystem_Exception_FileNotFoundException When originFile doesn't exist
[29] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException When copy fails
[30] Fix | Delete
*/
[31] Fix | Delete
public function copy($originFile, $targetFile, $override = false)
[32] Fix | Delete
{
[33] Fix | Delete
if (stream_is_local($originFile) && !is_file($originFile)) {
[34] Fix | Delete
throw new Symfony_Filesystem_Exception_FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
$this->mkdir(dirname($targetFile));
[38] Fix | Delete
[39] Fix | Delete
if (!$override && is_file($targetFile)) {
[40] Fix | Delete
$doCopy = filemtime($originFile) > filemtime($targetFile);
[41] Fix | Delete
} else {
[42] Fix | Delete
$doCopy = true;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
if ($doCopy) {
[46] Fix | Delete
// https://bugs.php.net/bug.php?id=64634
[47] Fix | Delete
$source = fopen($originFile, 'r');
[48] Fix | Delete
$target = fopen($targetFile, 'w+');
[49] Fix | Delete
stream_copy_to_stream($source, $target);
[50] Fix | Delete
fclose($source);
[51] Fix | Delete
fclose($target);
[52] Fix | Delete
unset($source, $target);
[53] Fix | Delete
[54] Fix | Delete
if (!is_file($targetFile)) {
[55] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* Creates a directory recursively.
[62] Fix | Delete
*
[63] Fix | Delete
* @param string|array|Traversable $dirs The directory path
[64] Fix | Delete
* @param integer $mode The directory mode
[65] Fix | Delete
*
[66] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException On any directory creation failure
[67] Fix | Delete
*/
[68] Fix | Delete
public function mkdir($dirs, $mode = 0777)
[69] Fix | Delete
{
[70] Fix | Delete
foreach ($this->toIterator($dirs) as $dir) {
[71] Fix | Delete
if (is_dir($dir)) {
[72] Fix | Delete
continue;
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
if (true !== @mkdir($dir, $mode, true)) {
[76] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to create "%s".', $dir), 0, null, $dir);
[77] Fix | Delete
}
[78] Fix | Delete
}
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Checks the existence of files or directories.
[83] Fix | Delete
*
[84] Fix | Delete
* @param string|array|Traversable $files A filename, an array of files, or a Traversable instance to check
[85] Fix | Delete
*
[86] Fix | Delete
* @return bool true if the file exists, false otherwise
[87] Fix | Delete
*/
[88] Fix | Delete
public function exists($files)
[89] Fix | Delete
{
[90] Fix | Delete
foreach ($this->toIterator($files) as $file) {
[91] Fix | Delete
if (!file_exists($file)) {
[92] Fix | Delete
return false;
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
return true;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Sets access and modification time of file.
[101] Fix | Delete
*
[102] Fix | Delete
* @param string|array|Traversable $files A filename, an array of files, or a Traversable instance to create
[103] Fix | Delete
* @param integer $time The touch time as a unix timestamp
[104] Fix | Delete
* @param integer $atime The access time as a unix timestamp
[105] Fix | Delete
*
[106] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException When touch fails
[107] Fix | Delete
*/
[108] Fix | Delete
public function touch($files, $time = null, $atime = null)
[109] Fix | Delete
{
[110] Fix | Delete
foreach ($this->toIterator($files) as $file) {
[111] Fix | Delete
$touch = $time ? @touch($file, $time, $atime) : @touch($file);
[112] Fix | Delete
if (true !== $touch) {
[113] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to touch "%s".', $file), 0, null, $file);
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Removes files or directories.
[120] Fix | Delete
*
[121] Fix | Delete
* @param string|array|Traversable $files A filename, an array of files, or a Traversable instance to remove
[122] Fix | Delete
*
[123] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException When removal fails
[124] Fix | Delete
*/
[125] Fix | Delete
public function remove($files)
[126] Fix | Delete
{
[127] Fix | Delete
$files = iterator_to_array($this->toIterator($files));
[128] Fix | Delete
$files = array_reverse($files);
[129] Fix | Delete
foreach ($files as $file) {
[130] Fix | Delete
if (!file_exists($file) && !is_link($file)) {
[131] Fix | Delete
continue;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
if (is_dir($file) && !is_link($file)) {
[135] Fix | Delete
$this->remove(new Symfony_Filesystem_FilesystemIterator($file));
[136] Fix | Delete
[137] Fix | Delete
if (true !== @rmdir($file)) {
[138] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to remove directory "%s".', $file), 0, null, $file);
[139] Fix | Delete
}
[140] Fix | Delete
} else {
[141] Fix | Delete
// https://bugs.php.net/bug.php?id=52176
[142] Fix | Delete
if ($this->isWindows() && is_dir($file)) {
[143] Fix | Delete
if (true !== @rmdir($file)) {
[144] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file);
[145] Fix | Delete
}
[146] Fix | Delete
} else {
[147] Fix | Delete
if (true !== @unlink($file)) {
[148] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file);
[149] Fix | Delete
}
[150] Fix | Delete
}
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Change mode for an array of files or directories.
[157] Fix | Delete
*
[158] Fix | Delete
* @param string|array|Traversable $files A filename, an array of files, or a Traversable instance to change mode
[159] Fix | Delete
* @param integer $mode The new mode (octal)
[160] Fix | Delete
* @param integer $umask The mode mask (octal)
[161] Fix | Delete
* @param bool $recursive Whether change the mod recursively or not
[162] Fix | Delete
*
[163] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException When the change fail
[164] Fix | Delete
*/
[165] Fix | Delete
public function chmod($files, $mode, $umask = 0000, $recursive = false)
[166] Fix | Delete
{
[167] Fix | Delete
foreach ($this->toIterator($files) as $file) {
[168] Fix | Delete
if ($recursive && is_dir($file) && !is_link($file)) {
[169] Fix | Delete
$this->chmod(new Symfony_Filesystem_FilesystemIterator($file), $mode, $umask, true);
[170] Fix | Delete
}
[171] Fix | Delete
if (true !== @chmod($file, $mode & ~$umask)) {
[172] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to chmod file "%s".', $file), 0, null, $file);
[173] Fix | Delete
}
[174] Fix | Delete
}
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Change the owner of an array of files or directories
[179] Fix | Delete
*
[180] Fix | Delete
* @param string|array|Traversable $files A filename, an array of files, or a Traversable instance to change owner
[181] Fix | Delete
* @param string $user The new owner user name
[182] Fix | Delete
* @param bool $recursive Whether change the owner recursively or not
[183] Fix | Delete
*
[184] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException When the change fail
[185] Fix | Delete
*/
[186] Fix | Delete
public function chown($files, $user, $recursive = false)
[187] Fix | Delete
{
[188] Fix | Delete
foreach ($this->toIterator($files) as $file) {
[189] Fix | Delete
if ($recursive && is_dir($file) && !is_link($file)) {
[190] Fix | Delete
$this->chown(new Symfony_Filesystem_FilesystemIterator($file), $user, true);
[191] Fix | Delete
}
[192] Fix | Delete
if (is_link($file) && function_exists('lchown')) {
[193] Fix | Delete
if (true !== @lchown($file, $user)) {
[194] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
[195] Fix | Delete
}
[196] Fix | Delete
} else {
[197] Fix | Delete
if (true !== @chown($file, $user)) {
[198] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
[199] Fix | Delete
}
[200] Fix | Delete
}
[201] Fix | Delete
}
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
/**
[205] Fix | Delete
* Change the group of an array of files or directories
[206] Fix | Delete
*
[207] Fix | Delete
* @param string|array|Traversable $files A filename, an array of files, or a Traversable instance to change group
[208] Fix | Delete
* @param string $group The group name
[209] Fix | Delete
* @param bool $recursive Whether change the group recursively or not
[210] Fix | Delete
*
[211] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException When the change fail
[212] Fix | Delete
*/
[213] Fix | Delete
public function chgrp($files, $group, $recursive = false)
[214] Fix | Delete
{
[215] Fix | Delete
foreach ($this->toIterator($files) as $file) {
[216] Fix | Delete
if ($recursive && is_dir($file) && !is_link($file)) {
[217] Fix | Delete
$this->chgrp(new Symfony_Filesystem_FilesystemIterator($file), $group, true);
[218] Fix | Delete
}
[219] Fix | Delete
if (is_link($file) && function_exists('lchgrp')) {
[220] Fix | Delete
if (true !== @lchgrp($file, $group)) {
[221] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to chgrp file "%s".', $file), 0, null, $file);
[222] Fix | Delete
}
[223] Fix | Delete
} else {
[224] Fix | Delete
if (true !== @chgrp($file, $group)) {
[225] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to chgrp file "%s".', $file), 0, null, $file);
[226] Fix | Delete
}
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
/**
[232] Fix | Delete
* Renames a file or a directory.
[233] Fix | Delete
*
[234] Fix | Delete
* @param string $origin The origin filename or directory
[235] Fix | Delete
* @param string $target The new filename or directory
[236] Fix | Delete
* @param bool $overwrite Whether to overwrite the target if it already exists
[237] Fix | Delete
*
[238] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException When target file or directory already exists
[239] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException When origin cannot be renamed
[240] Fix | Delete
*/
[241] Fix | Delete
public function rename($origin, $target, $overwrite = false)
[242] Fix | Delete
{
[243] Fix | Delete
// we check that target does not exist
[244] Fix | Delete
if (!$overwrite && is_readable($target)) {
[245] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target);
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
if (true !== @rename($origin, $target)) {
[249] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Cannot rename "%s" to "%s".', $origin, $target), 0, null, $target);
[250] Fix | Delete
}
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Creates a symbolic link or copy a directory.
[255] Fix | Delete
*
[256] Fix | Delete
* @param string $originDir The origin directory path
[257] Fix | Delete
* @param string $targetDir The symbolic link name
[258] Fix | Delete
* @param bool $copyOnWindows Whether to copy files if on Windows
[259] Fix | Delete
*
[260] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException When symlink fails
[261] Fix | Delete
*
[262] Fix | Delete
* Warning: DO NOT call this function "s y m l i n k", the whole file gets deleted by some "very advanced" antivirus checker.
[263] Fix | Delete
*/
[264] Fix | Delete
public function symboliclink($originDir, $targetDir, $copyOnWindows = false)
[265] Fix | Delete
{
[266] Fix | Delete
if (!function_exists('symlink') && $copyOnWindows) {
[267] Fix | Delete
$this->mirror($originDir, $targetDir);
[268] Fix | Delete
[269] Fix | Delete
return;
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
$this->mkdir(dirname($targetDir));
[273] Fix | Delete
[274] Fix | Delete
$ok = false;
[275] Fix | Delete
if (is_link($targetDir)) {
[276] Fix | Delete
if (readlink($targetDir) != $originDir) {
[277] Fix | Delete
$this->remove($targetDir);
[278] Fix | Delete
} else {
[279] Fix | Delete
$ok = true;
[280] Fix | Delete
}
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
if (!$ok) {
[284] Fix | Delete
$fn = 'symlink';
[285] Fix | Delete
if (true !== @$fn($originDir, $targetDir)) {
[286] Fix | Delete
$report = error_get_last();
[287] Fix | Delete
if (is_array($report)) {
[288] Fix | Delete
if ($this->isWindows() && false !== strpos($report['message'], 'error code(1314)')) {
[289] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?');
[290] Fix | Delete
}
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to create symbolic link from "%s" to "%s".', $originDir, $targetDir), 0, null, $targetDir);
[294] Fix | Delete
}
[295] Fix | Delete
}
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
/**
[299] Fix | Delete
* Given an existing path, convert it to a path relative to a given starting path
[300] Fix | Delete
*
[301] Fix | Delete
* @param string $endPath Absolute path of target
[302] Fix | Delete
* @param string $startPath Absolute path where traversal begins
[303] Fix | Delete
*
[304] Fix | Delete
* @return string Path of target relative to starting path
[305] Fix | Delete
*/
[306] Fix | Delete
public function makePathRelative($endPath, $startPath)
[307] Fix | Delete
{
[308] Fix | Delete
// Normalize separators on windows
[309] Fix | Delete
if ($this->isWindows()) {
[310] Fix | Delete
$endPath = strtr($endPath, '\\', '/');
[311] Fix | Delete
$startPath = strtr($startPath, '\\', '/');
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
// Split the paths into arrays
[315] Fix | Delete
$startPathArr = explode('/', trim($startPath, '/'));
[316] Fix | Delete
$endPathArr = explode('/', trim($endPath, '/'));
[317] Fix | Delete
[318] Fix | Delete
$index = 0;
[319] Fix | Delete
$depth = 0;
[320] Fix | Delete
if ($startPath !== '/') {
[321] Fix | Delete
// Find for which directory the common path stops
[322] Fix | Delete
while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) {
[323] Fix | Delete
$index++;
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
[327] Fix | Delete
$depth = count($startPathArr) - $index;
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
// Repeated "../" for each level need to reach the common path
[331] Fix | Delete
$traverser = str_repeat('../', $depth);
[332] Fix | Delete
[333] Fix | Delete
$endPathRemainder = implode('/', array_slice($endPathArr, $index));
[334] Fix | Delete
[335] Fix | Delete
// Construct $endPath from traversing to the common path, then to the remaining $endPath
[336] Fix | Delete
$relativePath = $traverser.(strlen($endPathRemainder) > 0 ? $endPathRemainder.'/' : '');
[337] Fix | Delete
[338] Fix | Delete
return (strlen($relativePath) === 0) ? './' : $relativePath;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Mirrors a directory to another.
[343] Fix | Delete
*
[344] Fix | Delete
* @param string $originDir The origin directory
[345] Fix | Delete
* @param string $targetDir The target directory
[346] Fix | Delete
* @param Traversable $iterator A Traversable instance
[347] Fix | Delete
* @param array $options An array of boolean options
[348] Fix | Delete
* Valid options are:
[349] Fix | Delete
* - $options['override'] Whether to override an existing file on copy or not (see copy())
[350] Fix | Delete
* - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see sym_link() without the underscore)
[351] Fix | Delete
* - $options['delete'] Whether to delete files that are not in the source directory (defaults to false)
[352] Fix | Delete
*
[353] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException When file type is unknown
[354] Fix | Delete
*/
[355] Fix | Delete
public function mirror($originDir, $targetDir, Traversable $iterator = null, $options = array())
[356] Fix | Delete
{
[357] Fix | Delete
$targetDir = rtrim($targetDir, '/\\');
[358] Fix | Delete
$originDir = rtrim($originDir, '/\\');
[359] Fix | Delete
[360] Fix | Delete
// Iterate in destination folder to remove obsolete entries
[361] Fix | Delete
if ($this->exists($targetDir) && isset($options['delete']) && $options['delete']) {
[362] Fix | Delete
$deleteIterator = $iterator;
[363] Fix | Delete
if (null === $deleteIterator) {
[364] Fix | Delete
$flags = Symfony_Filesystem_FilesystemIterator::SKIP_DOTS;
[365] Fix | Delete
$deleteIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($targetDir, $flags), RecursiveIteratorIterator::CHILD_FIRST);
[366] Fix | Delete
}
[367] Fix | Delete
/** @var SplFileObject $file */
[368] Fix | Delete
foreach ($deleteIterator as $file) {
[369] Fix | Delete
$origin = str_replace($targetDir, $originDir, $file->getPathname());
[370] Fix | Delete
if (!$this->exists($origin)) {
[371] Fix | Delete
$this->remove($file);
[372] Fix | Delete
}
[373] Fix | Delete
}
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
$copyOnWindows = false;
[377] Fix | Delete
if (isset($options['copy_on_windows']) && !function_exists('symlink')) {
[378] Fix | Delete
$copyOnWindows = $options['copy_on_windows'];
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
if (null === $iterator) {
[382] Fix | Delete
$flags = $copyOnWindows ? Symfony_Filesystem_FilesystemIterator::SKIP_DOTS | Symfony_Filesystem_FilesystemIterator::FOLLOW_SYMLINKS : Symfony_Filesystem_FilesystemIterator::SKIP_DOTS;
[383] Fix | Delete
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($originDir, $flags), RecursiveIteratorIterator::SELF_FIRST);
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
foreach ($iterator as $file) {
[387] Fix | Delete
$target = str_replace($originDir, $targetDir, $file->getPathname());
[388] Fix | Delete
[389] Fix | Delete
if ($copyOnWindows) {
[390] Fix | Delete
if (is_link($file) || is_file($file)) {
[391] Fix | Delete
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
[392] Fix | Delete
} elseif (is_dir($file)) {
[393] Fix | Delete
$this->mkdir($target);
[394] Fix | Delete
} else {
[395] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
[396] Fix | Delete
}
[397] Fix | Delete
} else {
[398] Fix | Delete
if (is_link($file)) {
[399] Fix | Delete
$this->symboliclink($file, $target);
[400] Fix | Delete
} elseif (is_dir($file)) {
[401] Fix | Delete
$this->mkdir($target);
[402] Fix | Delete
} elseif (is_file($file)) {
[403] Fix | Delete
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
[404] Fix | Delete
} else {
[405] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
[406] Fix | Delete
}
[407] Fix | Delete
}
[408] Fix | Delete
}
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
/**
[412] Fix | Delete
* Returns whether the file path is an absolute path.
[413] Fix | Delete
*
[414] Fix | Delete
* @param string $file A file path
[415] Fix | Delete
*
[416] Fix | Delete
* @return bool
[417] Fix | Delete
*/
[418] Fix | Delete
public function isAbsolutePath($file)
[419] Fix | Delete
{
[420] Fix | Delete
if (strspn($file, '/\\', 0, 1)
[421] Fix | Delete
|| (strlen($file) > 3 && ctype_alpha($file[0])
[422] Fix | Delete
&& substr($file, 1, 1) === ':'
[423] Fix | Delete
&& (strspn($file, '/\\', 2, 1))
[424] Fix | Delete
)
[425] Fix | Delete
|| null !== parse_url($file, PHP_URL_SCHEME)
[426] Fix | Delete
) {
[427] Fix | Delete
return true;
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
return false;
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
/**
[434] Fix | Delete
* Atomically dumps content into a file.
[435] Fix | Delete
*
[436] Fix | Delete
* @param string $filename The file to be written to.
[437] Fix | Delete
* @param string $content The data to write into the file.
[438] Fix | Delete
* @param integer $mode The file mode (octal).
[439] Fix | Delete
*
[440] Fix | Delete
* @throws Symfony_Filesystem_Exception_IOException If the file cannot be written to.
[441] Fix | Delete
*/
[442] Fix | Delete
public function dumpFile($filename, $content, $mode = 0666)
[443] Fix | Delete
{
[444] Fix | Delete
$dir = dirname($filename);
[445] Fix | Delete
[446] Fix | Delete
if (!is_dir($dir)) {
[447] Fix | Delete
$this->mkdir($dir);
[448] Fix | Delete
} elseif (!is_writable($dir)) {
[449] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
$tmpFile = tempnam($dir, basename($filename));
[453] Fix | Delete
[454] Fix | Delete
if (false === @file_put_contents($tmpFile, $content)) {
[455] Fix | Delete
throw new Symfony_Filesystem_Exception_IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
$this->rename($tmpFile, $filename, true);
[459] Fix | Delete
$this->chmod($filename, $mode);
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
/**
[463] Fix | Delete
* @param mixed $files
[464] Fix | Delete
*
[465] Fix | Delete
* @return Traversable
[466] Fix | Delete
*/
[467] Fix | Delete
private function toIterator($files)
[468] Fix | Delete
{
[469] Fix | Delete
if (!$files instanceof Traversable) {
[470] Fix | Delete
$files = new ArrayObject(is_array($files) ? $files : array($files));
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
return $files;
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
private function isWindows()
[477] Fix | Delete
{
[478] Fix | Delete
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
[479] Fix | Delete
}
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function