76 lines
1.5 KiB
PHP
76 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Helper;
|
|
|
|
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
use Symfony\Component\Finder\Finder;
|
|
|
|
|
|
class Hiltes
|
|
{
|
|
// init file system
|
|
protected $fsObject;
|
|
protected $current_dir_path;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->fsObject = new Filesystem();
|
|
$this->current_dir_path = getcwd();
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Aufbau des Dateinamens:
|
|
* WU + Datum(TTMM) + Fortlaufendenummer (x2) + “.“ +Filialnummer(x4)
|
|
* Beispieldateiname : WU220401.0001
|
|
*/
|
|
public function createFileName() :String
|
|
{
|
|
$date = date('dm');
|
|
$number = '01';
|
|
$filial = '0001';
|
|
return 'WU'.$date.$number.'.'.$filial;
|
|
}
|
|
|
|
|
|
public function import()
|
|
{
|
|
|
|
$finder = new Finder();
|
|
$finder->files()->in($this->current_dir_path . "/hiltes/h2c/");
|
|
|
|
foreach ($finder as $file) {
|
|
$contents = $file->getContents();
|
|
|
|
var_dump($contents);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @param string $data
|
|
* @return void
|
|
*/
|
|
public function export(string $data)
|
|
{
|
|
|
|
try {
|
|
|
|
$new_file_path = $this->current_dir_path . "/hiltes/c2h/".$this->createFileName();
|
|
|
|
if (!$this->fsObject->exists($new_file_path))
|
|
{
|
|
$this->fsObject->touch($new_file_path);
|
|
$this->fsObject->chmod($new_file_path, 0777);
|
|
$this->fsObject->dumpFile($new_file_path, $data);
|
|
}
|
|
} catch (IOExceptionInterface $exception) {
|
|
echo "Error creating file at". $exception->getPath();
|
|
}
|
|
}
|
|
|
|
|
|
}
|