PHPackages                             luispastendev/csv-generator - 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. luispastendev/csv-generator

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

luispastendev/csv-generator
===========================

Generador de archivos csv

1.1.1(3y ago)09[2 issues](https://github.com/luispastendev/csv-generator/issues)MITPHPPHP &gt;=7.3

Since Feb 9Pushed 3y ago1 watchersCompare

[ Source](https://github.com/luispastendev/csv-generator)[ Packagist](https://packagist.org/packages/luispastendev/csv-generator)[ RSS](/packages/luispastendev-csv-generator/feed)WikiDiscussions main Synced 1mo ago

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

CSV Generator
=============

[](#csv--generator)

Generador de archivos formato csv

Instalación
-----------

[](#instalación)

Puedes realizarlo por composer mediante el comando:

```
composer require luispastendev/csv-generator
```

Uso
---

[](#uso)

Para utilizar esta libreria es muy simple, solo generamos la instancia del archivo y la utilizamos de la siguiente forma:

```
use CSVGenerator\CSVGenerator;

// Especificamos la ruta de donde se generara el archivo con ext csv.
// si el archivo ya existe se creara uno nuevo
$file = __DIR__ . '/test.csv';

// clasico
$csv_generator = new CSVGenerator;
$csv_generator->create($file, ['id', 'name', 'company']);
$csv_generator->add([1, 'luis', 'company1']);
$csv_generator->add([2, 'foo', 'company2']);

// chaining functions
(new CSVGenerator)->create($file, ['id', 'name', 'company'])
    ->add([
        [1, 'luis', 'company1'],
        [2, 'foo', 'company2']
    ]);
```

Agregar datos
-------------

[](#agregar-datos)

Puedes crear datos en lote o poco a poco dentro del flujo de tu aplicación

```
$file = __DIR__ . '/test.csv';

$generator = new CSVGenerator($file);

// paso a paso
$generator->add([1, 'luis', 'company1']);
$generator->add([2, 'foo', 'company2']);

// en lote
$generator->add([
    [1, 'luis', 'company1'],
    [2, 'foo', 'company2'],
    [3, 'bar', 'company3']
);
```

Tambien puedes crear un archivo con datos con la funcion `create()`

```
$path = __DIR__ . '/test.csv';

(new CSVGenerator)->create($path, [
    [1, 'luis', 'company1'],
    // ...
]);
```

Si el archivo se encuentra duplicado la libreria va generar un nuevo archivo con suffix

```
src/
├── test.csv
├── test_1.csv
└── test_2.csv
```

Trabajar con archivos existentes
--------------------------------

[](#trabajar-con-archivos-existentes)

Puedes trabajar con archivos que ya existen para agregar contenido nuevo

```
$path = __DIR__ . '/ya-existo.csv';

$generator = new CSVGenerator($path);
$generator->add([1,'foo','bar']);

// o tambien ...

(new CSVGenerator)->setFile($path)->add([
    [1,'foo','bar'],
    //...
]);
```

Si tu lo necesitas puedes obtener información del archivo existente o generado

```
$generator->setFile($path)->add([10, 'php', 'fff']);
$info = $generator->getFileInfo();

// [
//    'filename'  => 'ya-existo.csv',
//    'basename'  => 'ya-existo',
//    'extension' => 'csv',
//    'path'      => /path/dir/
// ]
```

API
---

[](#api)

#### `add`

[](#add)

```
/**
 * Se encarga de agregar data a un archivo existente regresa
 * falso si ocurrio algun problema
 *
 * @param array $rows
 *
 * @return bool
 */

// rows puede ser un array unidimensional o bidi ej: [..] o [[...], [...]]
$obj->add(array $rows);
```

#### `create`

[](#create)

```
/**
 * Se encarga de crear un archivo y agregar datos
 *
 * @param string $path
 * @param array $rows
 * @return self
 */

// rows puede ser un array unidimensional o bidi ej: [..] o [[...], [...]]
$obj->create(string $pathfile, array $rows);
```

#### `setFile`

[](#setfile)

```
/**
 * Establece un archivo para trabajar sobre el.
 *
 * @param string $path
 * @return self
 */

$obj->setFile(string $path);
```

#### `getFileInfo`

[](#getfileinfo)

```
/**
 * Regresa información del archivo nuevo o existente.
 *
 * @return array
 */

$obj->getFileInfo(string $path);
```

Test
----

[](#test)

Los test de estas librerias se encuentran programados en `pest` correr los test de este proyecto necesitaras realizar `composer install` y ejecutar el siguiente comando en consola

```
./vendor/bin/pest

PASS  Tests\Feature\CSVGeneratorTest
✓ it create file via constructor
✓ it create file via method create
✓ it create file when name is duplicated
✓ it create csv file with data
✓ it attempt add data to csv without file
✓ it generate correct csv format.
✓ it generate file in steps
✓ it generate file in steps with chaining functions
✓ it write to an existing file
✓ it get file name

PASS  Tests\Unit\CSVGeneratorTest
✓ it add suffix to a name
✓ it generate filename with suffix
✓ it valid file fails

Tests:  13 passed

```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 69.2% 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 ~6 days

Total

2

Last Release

1187d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1bc6a330bfb4af428f2cf5be0d6b3fecd01385c5f892d073a2747a33f5bc15a6?d=identicon)[luispastendev](/maintainers/luispastendev)

---

Top Contributors

[![luispastenneubox](https://avatars.githubusercontent.com/u/182805429?v=4)](https://github.com/luispastenneubox "luispastenneubox (9 commits)")[![luispastendev](https://avatars.githubusercontent.com/u/4117596?v=4)](https://github.com/luispastendev "luispastendev (4 commits)")

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/luispastendev-csv-generator/health.svg)

```
[![Health](https://phpackages.com/badges/luispastendev-csv-generator/health.svg)](https://phpackages.com/packages/luispastendev-csv-generator)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

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