Add new CSVProvider

This commit is contained in:
Nicolas Le Goff
2014-03-18 10:33:19 +01:00
parent 5a14fb850d
commit a159926a36
4 changed files with 138 additions and 1 deletions

View File

@@ -16,6 +16,7 @@
"gedmo/doctrine-extensions" : "~2.3.0",
"alchemy/google-plus-api-client" : "~0.6.2",
"alchemy/geonames-api-consumer" : "~0.1.0",
"goodby/csv" : "~1.0",
"guzzle/guzzle" : "~3.0",
"imagine/imagine" : "0.6.x-dev@dev",
"jms/serializer" : "~0.10",

59
composer.lock generated
View File

@@ -3,7 +3,7 @@
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "6d21ea16cd4f85707ff5c89c7a5777ac",
"hash": "2b68364c4ebb09b6f5c3902e0afdcc1a",
"packages": [
{
"name": "alchemy-fr/tcpdf-clone",
@@ -1062,6 +1062,63 @@
],
"time": "2013-08-18 07:18:44"
},
{
"name": "goodby/csv",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/goodby/csv.git",
"reference": "da672802985d196cae767da29b11618a676496b0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/goodby/csv/zipball/da672802985d196cae767da29b11618a676496b0",
"reference": "da672802985d196cae767da29b11618a676496b0",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": ">=5.3.2"
},
"require-dev": {
"mikey179/vfsstream": ">=1.1.0",
"mockery/mockery": ">=0.7.2",
"phpunit/phpunit": "3.7.*",
"suin/php-expose": ">=1.0"
},
"type": "library",
"autoload": {
"psr-0": {
"Goodby\\CSV": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "suin",
"email": "suinyeze@gmail.com",
"homepage": "https://www.facebook.com/suinyeze",
"role": "Developer, Renaming Specialist"
},
{
"name": "reoring",
"email": "mori.reo@gmail.com",
"homepage": "https://www.facebook.com/reoring",
"role": "Developer"
}
],
"description": "CSV import/export library",
"homepage": "https://github.com/goodby/csv",
"keywords": [
"csv",
"export",
"import"
],
"time": "2013-11-22 19:10:34"
},
{
"name": "guzzle/guzzle",
"version": "v3.7.4",

View File

@@ -83,6 +83,7 @@ use Alchemy\Phrasea\Core\Provider\BorderManagerServiceProvider;
use Alchemy\Phrasea\Core\Provider\CacheServiceProvider;
use Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider;
use Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider;
use Alchemy\Phrasea\Core\Provider\CSVServiceProvider;
use Alchemy\Phrasea\Core\Provider\FileServeServiceProvider;
use Alchemy\Phrasea\Core\Provider\FtpServiceProvider;
use Alchemy\Geonames\GeonamesServiceProvider;
@@ -193,6 +194,7 @@ class Application extends SilexApplication
$this->register(new BrowserServiceProvider());
$this->register(new ConfigurationServiceProvider());
$this->register(new ConfigurationTesterServiceProvider);
$this->register(new CSVServiceProvider());
$this->register(new RegistrationServiceProvider());
$this->register(new CacheServiceProvider());
$this->register(new ImagineServiceProvider());

View File

@@ -0,0 +1,77 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Provider;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Goodby\CSV\Export\Standard\Exporter;
use Goodby\CSV\Export\Standard\ExporterConfig;
use Goodby\CSV\Import\Standard\Lexer;
use Goodby\CSV\Import\Standard\Interpreter;
use Goodby\CSV\Import\Standard\LexerConfig;
use Symfony\Component\HttpFoundation\StreamedResponse;
class CSVServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$app['csv.exporter.config'] = $app->share(function () {
$config = new ExporterConfig();
return $config
->setDelimiter(",")
->setEnclosure('"')
->setEscape("\\")
->setToCharset('UTF-8')
->setFromCharset('UTF-8');
});
$app['csv.exporter'] = $app->share(function ($app) {
return new Exporter($app['csv.exporter.config']);
});
$app['csv.lexer.config'] = $app->share(function ($app) {
return new LexerConfig();
});
$app['csv.lexer'] = $app->share(function ($app) {
return new Lexer($app['csv.lexer.config']);
});
$app['csv.interpreter'] = $app->share(function ($app) {
return new Interpreter();
});
$app['csv.response'] = $app->protect(function ($callback) use ($app) {
// set headers to fix ie issues
$response = new StreamedResponse($callback, 200, array(
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Last-Modified' => gmdate('D, d M Y H:i:s'). ' GMT',
'Cache-Control' => 'no-store, no-cache, must-revalidate',
'Cache-Control' => 'post-check=0, pre-check=0',
'Pragma' => 'no-cache',
'Content-Type' => 'text/csv',
'Cache-Control' => 'max-age=3600, must-revalidate',
'Content-Disposition' => 'max-age=3600, must-revalidate',
));
$response->headers->set('Content-Disposition', $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'export.csv'
));
});
}
public function boot(Application $app)
{
}
}