PHPackages                             tobento/service-file-creator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. tobento/service-file-creator

ActiveLibrary[File &amp; Storage](/categories/file-storage)

tobento/service-file-creator
============================

Easily creating files.

2.0(7mo ago)0367↓75%4MITPHPPHP &gt;=8.4

Since Jun 23Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/service-file-creator)[ Packagist](https://packagist.org/packages/tobento/service-file-creator)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-service-file-creator/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (4)

File Creator Service
====================

[](#file-creator-service)

With the File Creator Service you can create files easily.

Table of Contents
-----------------

[](#table-of-contents)

- [Getting started](#getting-started)
    - [Requirements](#requirements)
    - [Highlights](#highlights)
    - [Simple Example](#simple-example)
- [Documentation](#documentation)
    - [File Creator](#file-creator)
    - [Writers](#writers)
        - [Writer Interface](#writer-interface)
        - [CSV Writer](#csv-writer)
    - [Formatters](#formatters)
        - [Printr Formatter](#printr-formatter)
- [Credits](#credits)

---

Getting started
===============

[](#getting-started)

Add the latest version of the File Creator service project running this command.

```
composer require tobento/service-file-creator

```

Requirements
------------

[](#requirements)

- PHP 8.4 or greater

Highlights
----------

[](#highlights)

- Framework-agnostic, will work with any project
- Decoupled design

Simple Example
--------------

[](#simple-example)

Here is a simple example of how to use the Menu service.

```
use Tobento\Service\FileCreator\FileCreator;
use Tobento\Service\FileCreator\FileCreatorException;

try {
    new FileCreator()
        ->content('Lorem ipsum')
        ->newline()
        ->content('Lorem ipsum')
        ->create('home/public/files/filename.txt', FileCreator::CONTENT_NEW);
    // it is ok.
} catch (FileCreatorException $e) {
    // it failed.
}
```

Documentation
=============

[](#documentation)

File Creator
------------

[](#file-creator)

The create method has the following default parameter values:

```
use Tobento\Service\FileCreator\FileCreator;
use Tobento\Service\FileCreator\FileCreatorException;

try {
    new FileCreator()
        ->content('Lorem ipsum')
        ->create(
            file: 'home/public/files/filename.txt',
            handling: FileCreator::NO_OVERWRITE,
            modeFile: 0644,
            modeDir: 0755
        );
    // it is ok.
} catch (FileCreatorException $e) {
    // it failed.
}
```

The following parameters are available for the handling:

HandlingDescriptionFileCreator::NO\_OVERWRITECannot overwrite existing file. If the file exist, it throws FileCreatorExceptionFileCreator::CONTENT\_APPENDAppend content if file exists, otherwise creates new fileFileCreator::CONTENT\_NEWCreates new file with the contentThe create method returns a new instance allowing the following:

```
use Tobento\Service\FileCreator\FileCreator;
use Tobento\Service\FileCreator\FileCreatorException;

try {
    new FileCreator()
        ->content('Lorem ipsum')
        ->newline()
        ->content('Lorem ipsum')
        ->create('home/public/files/filename.txt', FileCreator::CONTENT_NEW)
        ->newline(num: 2)
        ->content('Lorem ipsum')
        ->create('home/public/files/filename.txt', FileCreator::CONTENT_APPEND);
    // it is ok.
} catch (FileCreatorException $e) {
    // it failed.
}
```

Writers
-------

[](#writers)

### Writer Interface

[](#writer-interface)

Writers must implement the following interface.

```
namespace Tobento\Service\FileCreator;

/**
 * WriterInterface
 */
interface WriterInterface
{
    /**
     * Write the content.
     *
     * @param resource $resource
     * @return void
     */
    public function write($resource): void;
}
```

### CSV Writer

[](#csv-writer)

```
use Tobento\Service\FileCreator\FileCreator;
use Tobento\Service\FileCreator\FileCreatorException;
use Tobento\Service\FileCreator\Writer\Csv;

$items = [
    ['id' => 1, 'title' => 'cars'],
    ['id' => 2, 'title' => 'plants'],
];

$csvWriter = new Csv(
    items: $items,
    delimiter: ',', // default
    enclosure: '"', // default
    escapeChar: '\\', // default
);

try {
    new FileCreator()
        ->writer($csvWriter)
        ->create('home/public/files/filename.csv', FileCreator::CONTENT_NEW);
    // it is ok.
} catch (FileCreatorException $e) {
    // it failed.
}
```

Formatters
----------

[](#formatters)

### Printr Formatter

[](#printr-formatter)

```
use Tobento\Service\FileCreator\FileCreator;
use Tobento\Service\FileCreator\FileCreatorException;
use Tobento\Service\FileCreator\Formatter\Printr;

$items = [
    ['id' => 1, 'title' => 'cars'],
    ['id' => 2, 'title' => 'plants'],
];

try {
    new FileCreator()
        ->content((new Printr())->format($items))
        ->create('home/public/files/filename.txt', FileCreator::CONTENT_NEW);
    // it is ok.
} catch (FileCreatorException $e) {
    // it failed.
}
```

Credits
=======

[](#credits)

- [Tobias Strub](https://www.tobento.ch)
- [All Contributors](../../contributors)

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance62

Regular maintenance activity

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~388 days

Total

5

Last Release

237d ago

Major Versions

1.x-dev → 2.02025-09-24

PHP version history (2 changes)1.0.0PHP &gt;=8.0

2.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/055d6a1b5c2384bb179c75ab0b55914231d898fdc4dffeb30770f81200e52206?d=identicon)[TOBENTOch](/maintainers/TOBENTOch)

---

Top Contributors

[![tobento-ch](https://avatars.githubusercontent.com/u/16684832?v=4)](https://github.com/tobento-ch "tobento-ch (9 commits)")

---

Tags

packagetobentofile creator

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tobento-service-file-creator/health.svg)

```
[![Health](https://phpackages.com/badges/tobento-service-file-creator/health.svg)](https://phpackages.com/packages/tobento-service-file-creator)
```

###  Alternatives

[oneofftech/laravel-tus-upload

Upload files to your Laravel application with the tus.io resumable upload protocol.

517.3k](/packages/oneofftech-laravel-tus-upload)[erlandmuchasaj/laravel-file-uploader

A simple package to help you easily upload files to your laravel project.

128.7k](/packages/erlandmuchasaj-laravel-file-uploader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
