mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-27 00:56:13 +01:00
tea/Classes/Utility/FileUtility.php

50 lines
1.4 KiB
PHP
Raw Normal View History

2015-10-24 01:16:37 +02:00
<?php
declare(strict_types=1);
2015-10-24 01:16:37 +02:00
namespace OliverKlee\Tea\Utility;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* This class provides functions concerning files.
*
* @author Oliver Klee <typo3-coding@oliverklee.de>
*/
2016-05-07 21:43:25 +02:00
class FileUtility
{
/**
* Concatenates the files given as $sourceFilePaths and writes their contents into $targetFilePath.
*
2016-05-08 14:28:38 +02:00
* @param string $targetFilePath
2016-05-07 21:43:25 +02:00
* @param string[] $sourceFilePaths
*
* @return void
*
* @throws \InvalidArgumentException
*/
public function concatenate(string $targetFilePath, array $sourceFilePaths)
2016-05-07 21:43:25 +02:00
{
if ($targetFilePath === '') {
throw new \InvalidArgumentException('$targetFileName must not be empty.', 1445631384);
}
2015-10-24 01:16:37 +02:00
2016-05-07 21:43:25 +02:00
$concatenatedContents = '';
foreach ($sourceFilePaths as $sourceFilePath) {
$concatenatedContents .= file_get_contents($sourceFilePath);
}
2015-10-24 01:16:37 +02:00
2016-05-07 21:43:25 +02:00
file_put_contents($targetFilePath, $concatenatedContents);
}
2015-10-24 01:16:37 +02:00
}