protected function publishFile($sourceStream, $relativeTargetPathAndFilename)
{
$pathInfo = UnicodeFunctions::pathinfo($relativeTargetPathAndFilename);
if (isset($pathInfo['extension']) && array_key_exists(strtolower($pathInfo['extension']), $this->extensionBlacklist) && $this->extensionBlacklist[strtolower($pathInfo['extension'])] === true) {
throw new TargetException(sprintf('Could not publish "%s" into resource publishing target "%s" because the filename extension "%s" is blacklisted.', $sourceStream, $this->name, strtolower($pathInfo['extension'])), 1447148472);
}
$targetPathAndFilename = $this->path . $relativeTargetPathAndFilename;
if (@fstat($sourceStream) === false) {
throw new TargetException(sprintf('Could not publish "%s" into resource publishing target "%s" because the source file is not accessible (file stat failed).', $sourceStream, $this->name), 1375258499);
}
if (!file_exists(dirname($targetPathAndFilename))) {
Files::createDirectoryRecursively(dirname($targetPathAndFilename));
}
if (!is_writable(dirname($targetPathAndFilename))) {
throw new Exception(sprintf('Could not publish "%s" into resource publishing target "%s" because the target file "%s" is not writable.', $sourceStream, $this->name, $targetPathAndFilename), 1428917322, isset($exception) ? $exception : null);
}
try {
$targetFileHandle = fopen($targetPathAndFilename, 'w');
$result = stream_copy_to_stream($sourceStream, $targetFileHandle);
fclose($targetFileHandle);
} catch (\Exception $exception) {
$result = false;
}
if ($result === false) {
throw new TargetException(sprintf('Could not publish "%s" into resource publishing target "%s" because the source file could not be copied to the target location.', $sourceStream, $this->name), 1375258399, isset($exception) ? $exception : null);
}
$this->systemLogger->log(sprintf('FileSystemTarget: Published file. (target: %s, file: %s)', $this->name, $relativeTargetPathAndFilename), LOG_DEBUG);
}