<commit_before><?php

namespace Shopware\Components\SwagImportExport\Utils;

use Shopware\Bundle\MediaBundle\MediaService;

class FileHelper
{
    /**
     * @param string $file
     * @param string $content
     * @param int|null $flag
     * @throws \Exception
     */
    public function writeStringToFile($file, $content, $flag = null)
    {
        $file = str_replace(Shopware()->DocPath(), '', $file);
        
        /** @var MediaService $mediaService */
        $mediaService = Shopware()->Container()->get('shopware_media.media_service');

        if ($flag === null) {
            $str = $mediaService->write($file, $content);
        } else {
            $content = $mediaService->read($file) . $content;
            $str = $mediaService->write($file, $content);
        }

        if ($str === false) {
            throw new \Exception("Cannot write in '$file'");
        }
    }
}<commit_msg>PT-4615: Fixed an bug, that created sub-directories instead of using the absolute export path when using the shopware CLI<commit_after><?php

namespace Shopware\Components\SwagImportExport\Utils;

class FileHelper
{
    /**
     * @param string $file
     * @param string $content
     * @param int|null $flag
     * @throws \Exception
     */
    public function writeStringToFile($file, $content, $flag = null)
    {
        try {
            file_put_contents($file, $content, $flag);
        } catch (\Exception $e) {
            throw new \Exception("Cannot write in '$file'");
        }
    }
}
{'fraction_non_alphanumeric': 0.13925729442970822, 'fraction_numerical': 0.002652519893899204, 'mean_word_length': 2.4530892448512587, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '927271', 'n_tokens_mistral': 435, 'n_tokens_neox': 429, 'n_words': 107}