Download the PHP package vkr/csv-bundle without Composer

On this page you can find all versions of the php package vkr/csv-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package csv-bundle

About

This is a simple bundle for CSV creation in Symfony. It doesn't have any configuration and no dependencies except for Symfony, however it works best if you use Doctrine and want to parse a query result into CSV format.

Installation

Nothing to install except enabling the bundle in .

Usage

Basic usage

First, you need to have some kind of data source. This bundle is very flexible about how your data source looks - basically, it has to be an array or array-like object (anything that works with ), and its elements can be either arrays or objects. In other words, it will work with any non-null value that is returned by Doctrine's or .

You also need to define fields that will make it into your CSV. If your data source consists of arrays, those fields are just keys of those arrays. If you work with objects, field names must comply with the following rule with respect to the object's public getters:

Once you have a data source and field names, you can form the CSV data in your controller:

The variable will hold the following string:

If there are any commas in the data source values, those will be swapped for whitespaces.

Field labels

If you want to create 'nice' titles for the first row of your CSV, you can use the third argument of , array of field labels. If it is not empty, it should contain the same number of elements as . For example:

The resulting data will look as follows:

Note that neither nor can normally contain separator symbols, otherwise will be thrown. However, if you define a field with a separator symbol and a corresponding label without the separator, the script will work as usual:

Custom separators

If you want to use something else than comma as a separator, you can specify the fourth argument of . You can also change the separator replacement string by specifying the fifth argument. Note that separator replacement cannot occur in both field names and field labels.

The resulting data will look as follows:

Handling dates inside data

If an element of your data source cannot be implicitly converted to string, the bundle will throw . The only exception to this are objects that are frequently returned by Doctrine. If you expect to receive a object, you should specify the sixth argument of which should be a format string that is accepted by method.

The resulting data will look as follows:

If the format string contains separator symbols, those will be replaced as well.

If you did not specify the sixth argument or it is malformed, the bundle will not give you any errors, rather you will get a standard result of calling without arguments, that will depend on your PHP settings.

Fillers

The seventh, and final argument of determines what to do if the field value on one or more of elements of your data source is null or undefined. If this argument is not specified, an empty string is returned. For example:

The resulting data without look as follows:

If you specify that

you will get this:

Separator symbols inside fillers will be replaced.

Forming CSV file from data

The variable returned by is not yet a CSV file, it is just a string. To make Symfony return a file, you need to define headers and return a response. This bundle includes a simple helper function for header definition, . It accepts an optional argument which is a file name without extension. If this argument is not specified, the file will be called .

Here is how you return a file from the controller:

The resulting file will be named .

API

string CSVCreator::parseDataToCSV(array|Traversable $dataSource, string[] $fields, string[] $fieldLabels = [], string $separator = ',', string $replacement = ' ', string $dateFormat = '', string $filler = '')

string[] CSVCreator::setHeaders(string $filename = '')


All versions of csv-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
symfony/symfony Version ~2.8|~3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vkr/csv-bundle contains the following files

Loading the files please wait ....