Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
-60
View File
@@ -1,60 +0,0 @@
# DO NOT EDIT THIS FILE!
#
# It's auto-generated by sonata-project/dev-kit package.
all:
@echo "Please choose a task."
.PHONY: all
lint: lint-composer lint-yaml lint-composer lint-xml lint-php
.PHONY: lint
lint-composer:
composer validate
.PHONY: lint-composer
lint-yaml:
yaml-lint --ignore-non-yaml-files --quiet --exclude vendor .
.PHONY: lint-yaml
lint-xml:
find . \( -name '*.xml' -or -name '*.xliff' \) \
-not -path './vendor/*' \
-not -path './src/Resources/public/vendor/*' \
| while read xmlFile; \
do \
XMLLINT_INDENT=' ' xmllint --encode UTF-8 --format "$$xmlFile"|diff - "$$xmlFile"; \
if [ $$? -ne 0 ] ;then exit 1; fi; \
done
.PHONY: lint-xml
lint-php:
php-cs-fixer fix --ansi --verbose --diff --dry-run
.PHONY: lint-php
cs-fix: cs-fix-php cs-fix-xml
.PHONY: cs-fix
cs-fix-php:
php-cs-fixer fix --verbose
.PHONY: cs-fix-php
cs-fix-xml:
find . \( -name '*.xml' -or -name '*.xliff' \) \
-not -path './vendor/*' \
-not -path './src/Resources/public/vendor/*' \
| while read xmlFile; \
do \
XMLLINT_INDENT=' ' xmllint --encode UTF-8 --format "$$xmlFile" --output "$$xmlFile"; \
done
.PHONY: cs-fix-xml
test:
phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml
.PHONY: test
docs:
cd docs && sphinx-build -W -b html -d _build/doctrees . _build/html
.PHONY: docs
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Bridge\Symfony\Bundle;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\SonataExporterBundle', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\SonataExporterBundle class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\SonataExporterBundle instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\SonataExporterBundle',
__NAMESPACE__.'\SonataExporterBundle'
);
if (false) {
final class SonataExporterBundle extends \Sonata\Exporter\Bridge\Symfony\Bundle\SonataExporterBundle
{
}
}
@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Bridge\Symfony\DependencyInjection\Compiler;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\ExporterCompilerPass', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\ExporterCompilerPass class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\ExporterCompilerPass instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\ExporterCompilerPass',
__NAMESPACE__.'\ExporterCompilerPass'
);
if (false) {
/**
* @deprecated since version 1.x, to be removed in 2.0.
*/
final class ExporterCompilerPass extends \Sonata\Exporter\Bridge\Symfony\DependencyInjection\Compiler\ExporterCompilerPass
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Bridge\Symfony\DependencyInjection;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\Configuration', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\Configuration class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\Configuration instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\Configuration',
__NAMESPACE__.'\Configuration'
);
if (false) {
final class Configuration extends \Sonata\Exporter\Bridge\Symfony\DependencyInjection\Configuration
{
}
}
@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Bridge\Symfony\DependencyInjection;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\SonataExporterExtension', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\SonataExporterExtension class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\SonataExporterExtension instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\SonataExporterExtension',
__NAMESPACE__.'\SonataExporterExtension'
);
if (false) {
/**
* @deprecated since version 1.x, to be removed in 2.0.
*/
final class SonataExporterExtension extends \Sonata\Exporter\Bridge\Symfony\DependencyInjection\SonataExporterExtension
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Exception;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\InvalidDataFormatException', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\InvalidDataFormatException class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\InvalidDataFormatException instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\InvalidDataFormatException',
__NAMESPACE__.'\InvalidDataFormatException'
);
if (false) {
class InvalidDataFormatException extends \Sonata\Exporter\Exception\InvalidDataFormatException
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Exception;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\InvalidMethodCallException', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\InvalidMethodCallException class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\InvalidMethodCallException instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\InvalidMethodCallException',
__NAMESPACE__.'\InvalidMethodCallException'
);
if (false) {
class InvalidMethodCallException extends \Sonata\Exporter\Exception\InvalidMethodCallException
{
}
}
-34
View File
@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\Exporter', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\Exporter class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\Exporter instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\Exporter',
__NAMESPACE__.'\Exporter'
);
if (false) {
/**
* @deprecated since version 1.x, to be removed in 2.0.
*/
final class Exporter
{
}
}
-31
View File
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\Handler', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\Handler class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\Handler instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\Handler',
__NAMESPACE__.'\Handler'
);
if (false) {
class Handler extends \Sonata\Exporter\Handler
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\AbstractXmlSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\AbstractXmlSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\AbstractXmlSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\AbstractXmlSourceIterator',
__NAMESPACE__.'\AbstractXmlSourceIterator'
);
if (false) {
abstract class AbstractXmlSourceIterator extends \Sonata\Exporter\Source\AbstractXmlSourceIterator
{
}
}
@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\ArraySourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\ArraySourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\ArraySourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\ArraySourceIterator',
__NAMESPACE__.'\ArraySourceIterator'
);
if (false) {
/**
* @deprecated since version 1.x, to be removed in 2.0.
*/
class ArraySourceIterator extends \Sonata\Exporter\Source\ArraySourceIterator
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\ChainSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\ChainSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\ChainSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\ChainSourceIterator',
__NAMESPACE__.'\ChainSourceIterator'
);
if (false) {
class ChainSourceIterator extends \Sonata\Exporter\Source\ChainSourceIterator
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\CsvSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\CsvSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\CsvSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\CsvSourceIterator',
__NAMESPACE__.'\CsvSourceIterator'
);
if (false) {
class CsvSourceIterator extends \Sonata\Exporter\Source\CsvSourceIterator
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\DoctrineDBALConnectionSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\DoctrineDBALConnectionSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\DoctrineDBALConnectionSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\DoctrineDBALConnectionSourceIterator',
__NAMESPACE__.'\DoctrineDBALConnectionSourceIterator'
);
if (false) {
class DoctrineDBALConnectionSourceIterator extends \Sonata\Exporter\Source\DoctrineDBALConnectionSourceIterator
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\DoctrineODMQuerySourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\DoctrineODMQuerySourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\DoctrineODMQuerySourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\DoctrineODMQuerySourceIterator',
__NAMESPACE__.'\DoctrineODMQuerySourceIterator'
);
if (false) {
class DoctrineODMQuerySourceIterator extends \Sonata\Exporter\Source\DoctrineODMQuerySourceIterator
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\DoctrineORMQuerySourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\DoctrineORMQuerySourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\DoctrineORMQuerySourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\DoctrineORMQuerySourceIterator',
__NAMESPACE__.'\DoctrineORMQuerySourceIterator'
);
if (false) {
class DoctrineORMQuerySourceIterator extends \Sonata\Exporter\Source\DoctrineORMQuerySourceIterator
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\IteratorCallbackSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\IteratorCallbackSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\IteratorCallbackSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\IteratorCallbackSourceIterator',
__NAMESPACE__.'\IteratorCallbackSourceIterator'
);
if (false) {
class IteratorCallbackSourceIterator extends \Sonata\Exporter\Source\IteratorCallbackSourceIterator
{
}
}
@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\IteratorSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\IteratorSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\IteratorSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\IteratorSourceIterator',
__NAMESPACE__.'\IteratorSourceIterator'
);
if (false) {
/**
* @deprecated since version 1.x, to be removed in 2.0.
*/
class IteratorSourceIterator extends \Sonata\Exporter\Source\IteratorSourceIterator
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\PDOStatementSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\PDOStatementSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\PDOStatementSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\PDOStatementSourceIterator',
__NAMESPACE__.'\PDOStatementSourceIterator'
);
if (false) {
class PDOStatementSourceIterator extends \Sonata\Exporter\Source\PDOStatementSourceIterator
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\PropelCollectionSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\PropelCollectionSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\PropelCollectionSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\PropelCollectionSourceIterator',
__NAMESPACE__.'\PropelCollectionSourceIterator'
);
if (false) {
class PropelCollectionSourceIterator extends \Sonata\Exporter\Source\PropelCollectionSourceIterator
{
}
}
@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!interface_exists('\Sonata\\'.__NAMESPACE__.'\SourceIteratorInterface', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\SourceIteratorInterface class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\SourceIteratorInterface instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\SourceIteratorInterface',
__NAMESPACE__.'\SourceIteratorInterface'
);
if (false) {
/**
* @deprecated since version 1.x, to be removed in 2.0.
*/
interface SourceIteratorInterface extends \Sonata\Exporter\Source\SourceIteratorInterface
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\SymfonySitemapSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\SymfonySitemapSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\SymfonySitemapSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\SymfonySitemapSourceIterator',
__NAMESPACE__.'\SymfonySitemapSourceIterator'
);
if (false) {
class SymfonySitemapSourceIterator extends \Sonata\Exporter\Source\SymfonySitemapSourceIterator
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\XmlExcelSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\XmlExcelSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\XmlExcelSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\XmlExcelSourceIterator',
__NAMESPACE__.'\XmlExcelSourceIterator'
);
if (false) {
class XmlExcelSourceIterator extends \Sonata\Exporter\Source\XmlExcelSourceIterator
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Source;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\XmlSourceIterator', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\XmlSourceIterator class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\XmlSourceIterator instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\XmlSourceIterator',
__NAMESPACE__.'\XmlSourceIterator'
);
if (false) {
class XmlSourceIterator extends \Sonata\Exporter\Source\XmlSourceIterator
{
}
}
@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Test;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\AbstractTypedWriterTestCase', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\AbstractTypedWriterTestCase class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\AbstractTypedWriterTestCase instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\AbstractTypedWriterTestCase',
__NAMESPACE__.'\AbstractTypedWriterTestCase'
);
if (false) {
/**
* @deprecated since version 1.x, to be removed in 2.0.
*/
abstract class AbstractTypedWriterTestCase extends \Sonata\Exporter\Test\AbstractTypedWriterTestCase
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\CsvWriter', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\CsvWriter class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\CsvWriter instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\CsvWriter',
__NAMESPACE__.'\CsvWriter'
);
if (false) {
class CsvWriter extends \Sonata\Exporter\Writer\CsvWriter
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\CsvWriterTerminate', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\CsvWriterTerminate class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\CsvWriterTerminate instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\CsvWriterTerminate',
__NAMESPACE__.'\CsvWriterTerminate'
);
if (false) {
final class CsvWriterTerminate extends \Sonata\Exporter\Writer\CsvWriterTerminate
{
}
}
@@ -1,30 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\FormattedBoolWriter', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\FormattedBoolWriter class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\FormattedBoolWriter instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\FormattedBoolWriter',
__NAMESPACE__.'\FormattedBoolWriter'
);
if (false) {
class FormattedBoolWriter extends \Sonata\Exporter\Writer\FormattedBoolWriter
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\GsaFeedWriter', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\GsaFeedWriter class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\GsaFeedWriter instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\GsaFeedWriter',
__NAMESPACE__.'\GsaFeedWriter'
);
if (false) {
class GsaFeedWriter extends \Sonata\Exporter\Writer\GsaFeedWriter
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\InMemoryWriter', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\InMemoryWriter class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\InMemoryWriter instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\InMemoryWriter',
__NAMESPACE__.'\InMemoryWriter'
);
if (false) {
class InMemoryWriter extends \Sonata\Exporter\Writer\InMemoryWriter
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\JsonWriter', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\JsonWriter class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\JsonWriter instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\JsonWriter',
__NAMESPACE__.'\JsonWriter'
);
if (false) {
class JsonWriter extends \Sonata\Exporter\Writer\JsonWriter
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\SitemapWriter', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\SitemapWriter class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\SitemapWriter instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\SitemapWriter',
__NAMESPACE__.'\SitemapWriter'
);
if (false) {
class SitemapWriter extends \Sonata\Exporter\Writer\SitemapWriter
{
}
}
@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!interface_exists('\Sonata\\'.__NAMESPACE__.'\TypedWriterInterface', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\TypedWriterInterface class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\TypedWriterInterface instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\TypedWriterInterface',
__NAMESPACE__.'\TypedWriterInterface'
);
if (false) {
/**
* @deprecated since version 1.x, to be removed in 2.0.
*/
interface TypedWriterInterface extends \Sonata\Exporter\Writer\TypedWriterInterface
{
}
}
@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!interface_exists('\Sonata\\'.__NAMESPACE__.'\WriterInterface', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\WriterInterface class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\WriterInterface instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\WriterInterface',
__NAMESPACE__.'\WriterInterface'
);
if (false) {
/**
* @deprecated since version 1.x, to be removed in 2.0.
*/
interface WriterInterface extends Exporter\Writer
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\XlsWriter', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\XlsWriter class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\XlsWriter instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\XlsWriter',
__NAMESPACE__.'\XlsWriter'
);
if (false) {
class XlsWriter extends \Sonata\Exporter\Writer\XlsWriter
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\XmlExcelWriter', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\XmlExcelWriter class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\XmlExcelWriter instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\XmlExcelWriter',
__NAMESPACE__.'\XmlExcelWriter'
);
if (false) {
class XmlExcelWriter extends \Sonata\Exporter\Writer\XmlExcelWriter
{
}
}
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Exporter\Writer;
if (!class_exists('\Sonata\\'.__NAMESPACE__.'\XmlWriter', false)) {
@trigger_error(
'The '.__NAMESPACE__.'\XmlWriter class is deprecated since version 1.x and will be removed in 2.0.'
.' Use \Sonata\\'.__NAMESPACE__.'\XmlWriter instead',
E_USER_DEPRECATED
);
}
class_alias(
'\Sonata\\'.__NAMESPACE__.'\XmlWriter',
__NAMESPACE__.'\XmlWriter'
);
if (false) {
class XmlWriter extends \Sonata\Exporter\Writer\XmlWriter
{
}
}
+41 -19
View File
@@ -3,11 +3,13 @@
"type": "library",
"description": "Lightweight Exporter library",
"keywords": [
"export",
"bundle",
"client",
"csv",
"xls",
"data",
"client"
"export",
"symfony-bundle",
"xls"
],
"homepage": "https://github.com/sonata-project/Exporter",
"license": "MIT",
@@ -19,25 +21,37 @@
}
],
"require": {
"php": "^5.6 || ^7.0"
"php": "^7.3 || ^8.0"
},
"conflict": {
"doctrine/mongodb-odm": "<2.0"
},
"require-dev": {
"doctrine/annotations": "^1.13",
"doctrine/dbal": "^2.5",
"doctrine/mongodb-odm": "^2.0",
"doctrine/orm": "^2.4.5",
"matthiasnoback/symfony-config-test": "^2.0",
"matthiasnoback/symfony-dependency-injection-test": "^1.0",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.84",
"phpstan/phpstan-phpunit": "^0.12.18",
"phpstan/phpstan-strict-rules": "^0.12.10",
"phpstan/phpstan-symfony": "^0.12.21",
"propel/propel1": "^1.6",
"symfony/config": "^2.8 || ^3.2 || ^4.0",
"symfony/dependency-injection": "^2.8 || ^3.2 || ^4.0",
"symfony/http-foundation": "^2.8 || ^3.2 || ^4.0",
"symfony/http-kernel": "^2.8 || ^3.2 || ^4.0",
"symfony/phpunit-bridge": "^4.0",
"symfony/property-access": "^2.8 || ^3.2 || ^4.0",
"symfony/routing": "^2.8 || ^3.2 || ^4.0"
"psalm/plugin-phpunit": "^0.16",
"psalm/plugin-symfony": "^2.0",
"symfony/config": "^4.4 || ^5.3",
"symfony/dependency-injection": "^4.4 || ^5.3",
"symfony/http-foundation": "^4.4 || ^5.3",
"symfony/http-kernel": "^4.4 || ^5.3",
"symfony/phpunit-bridge": "^5.3",
"symfony/property-access": "^4.4 || ^5.3",
"symfony/routing": "^4.4 || ^5.3",
"vimeo/psalm": "^4.9.2"
},
"suggest": {
"ext-curl": "*",
"propel/propel1": "^1.6",
"propel/propel1": "To export propel collections",
"symfony/property-access": "To be able to export from database entities",
"symfony/routing": "To be able to export the routes of a Symfony app"
},
@@ -46,18 +60,26 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
"dev-master": "2.x-dev"
}
},
"autoload": {
"psr-4": {
"Exporter\\": "aliases/",
"Sonata\\Exporter\\": "src/"
"Sonata\\Exporter\\": "src/",
"Sonata\\Exporter\\Bridge\\Symfony\\": "src/Bridge/Symfony/"
}
},
"autoload-dev": {
"psr-4": {
"Exporter\\Test\\": "tests/"
"Sonata\\Exporter\\Tests\\": "tests/"
}
},
"scripts": {
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/simple-phpunit install"
],
"post-update-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/simple-phpunit install"
]
}
}
-39
View File
@@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT THIS FILE!
It's auto-generated by sonata-project/dev-kit package.
-->
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Sonata Exporter Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<php>
<ini name="precision" value="8"/>
</php>
</phpunit>
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -11,27 +13,24 @@
namespace Sonata\Exporter\Bridge\Symfony\Bundle;
use Sonata\Exporter\Bridge\Symfony\DependencyInjection\Compiler\ExporterCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Sonata\Exporter\Bridge\Symfony\SonataExporterBundle as ForwardCompatibleSonataExporterBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
final class SonataExporterBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new ExporterCompilerPass());
}
@trigger_error(sprintf(
'The %s\SonataExporterBundle class is deprecated since sonata-project/exporter 2.4, to be removed in version 3.0. Use %s instead.',
__NAMESPACE__,
ForwardCompatibleSonataExporterBundle::class
), \E_USER_DEPRECATED);
if (false) {
/**
* {@inheritdoc}
* NEXT_MAJOR: remove this class.
*
* @deprecated since sonata-project/exporter 2.4, to be removed in version 3.0. Use Sonata\Exporter\Bridge\Symfony\SonataExporterBundle instead.
*/
protected function getContainerExtensionClass()
final class SonataExporterBundle extends Bundle
{
return 'Exporter\Bridge\Symfony\DependencyInjection\SonataExporterExtension';
}
}
class_exists(\Exporter\Bridge\Symfony\Bundle\SonataExporterBundle::class);
class_alias(ForwardCompatibleSonataExporterBundle::class, __NAMESPACE__.'\SonataExporterBundle');
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -20,10 +22,7 @@ use Symfony\Component\DependencyInjection\Reference;
*/
final class ExporterCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->has('sonata.exporter.exporter')) {
return;
@@ -37,5 +36,3 @@ final class ExporterCompilerPass implements CompilerPassInterface
}
}
}
class_exists(\Exporter\Bridge\Symfony\DependencyInjection\Compiler\ExporterCompilerPass::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -21,15 +23,12 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
*/
final class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('sonata_exporter');
$treeBuilder = new TreeBuilder('sonata_exporter');
$rootNode
$treeBuilder
->getRootNode()
->children()
->arrayNode('exporter')
->addDefaultsIfNotSet()
@@ -117,11 +116,8 @@ final class Configuration implements ConfigurationInterface
->end()
->end()
->end()
->end()
;
->end();
return $treeBuilder;
}
}
class_exists(\Exporter\Bridge\Symfony\DependencyInjection\Configuration::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -22,10 +24,7 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension;
*/
final class SonataExporterExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$processor = new Processor();
$configuration = new Configuration();
@@ -38,10 +37,10 @@ final class SonataExporterExtension extends Extension
$this->configureWriters($container, $config['writers']);
}
private function configureExporter(ContainerBuilder $container, array $config)
private function configureExporter(ContainerBuilder $container, array $config): void
{
foreach (['csv', 'json', 'xls', 'xml'] as $format) {
if (\in_array($format, $config['default_writers'])) {
if (\in_array($format, $config['default_writers'], true)) {
$container->getDefinition('sonata.exporter.writer.'.$format)->addTag(
'sonata.exporter.writer'
);
@@ -49,7 +48,7 @@ final class SonataExporterExtension extends Extension
}
}
private function configureWriters(ContainerBuilder $container, array $config)
private function configureWriters(ContainerBuilder $container, array $config): void
{
foreach ($config as $format => $settings) {
foreach ($settings as $key => $value) {
@@ -62,5 +61,3 @@ final class SonataExporterExtension extends Extension
}
}
}
class_exists(\Exporter\Bridge\Symfony\DependencyInjection\SonataExporterExtension::class);
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sonata.exporter.writer.csv" class="Exporter\Writer\CsvWriter" public="false">
<service id="sonata.exporter.writer.csv" class="Sonata\Exporter\Writer\CsvWriter" public="false">
<argument>%sonata.exporter.writer.csv.filename%</argument>
<argument>%sonata.exporter.writer.csv.delimiter%</argument>
<argument>%sonata.exporter.writer.csv.enclosure%</argument>
@@ -9,19 +9,19 @@
<argument>%sonata.exporter.writer.csv.show_headers%</argument>
<argument>%sonata.exporter.writer.csv.with_bom%</argument>
</service>
<service id="sonata.exporter.writer.json" class="Exporter\Writer\JsonWriter" public="false">
<service id="sonata.exporter.writer.json" class="Sonata\Exporter\Writer\JsonWriter" public="false">
<argument>%sonata.exporter.writer.json.filename%</argument>
</service>
<service id="sonata.exporter.writer.xls" class="Exporter\Writer\XlsWriter" public="false">
<service id="sonata.exporter.writer.xls" class="Sonata\Exporter\Writer\XlsWriter" public="false">
<argument>%sonata.exporter.writer.xls.filename%</argument>
<argument>%sonata.exporter.writer.xls.show_headers%</argument>
</service>
<service id="sonata.exporter.writer.xml" class="Exporter\Writer\XmlWriter" public="false">
<service id="sonata.exporter.writer.xml" class="Sonata\Exporter\Writer\XmlWriter" public="false">
<argument>%sonata.exporter.writer.xml.filename%</argument>
<argument>%sonata.exporter.writer.xml.main_element%</argument>
<argument>%sonata.exporter.writer.xml.child_element%</argument>
</service>
<service id="sonata.exporter.exporter" class="Exporter\Exporter" public="true"/>
<service id="Exporter\Exporter" alias="sonata.exporter.exporter"/>
<service id="sonata.exporter.exporter" class="Sonata\Exporter\Exporter" public="true"/>
<service id="Sonata\Exporter\Exporter" alias="sonata.exporter.exporter"/>
</services>
</container>
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -11,8 +13,6 @@
namespace Sonata\Exporter\Exception;
class InvalidDataFormatException extends \RuntimeException
final class InvalidDataFormatException extends RuntimeException implements SonataExporterException
{
}
class_exists(\Exporter\Exception\InvalidDataFormatException::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -11,8 +13,6 @@
namespace Sonata\Exporter\Exception;
class InvalidMethodCallException extends \RuntimeException
final class InvalidMethodCallException extends RuntimeException implements SonataExporterException
{
}
class_exists(\Exporter\Exception\InvalidMethodCallException::class);
+7 -13
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -38,15 +40,9 @@ final class Exporter
}
/**
* @param string $format
* @param string $filename
* @param SourceIteratorInterface $source
*
* @throws \RuntimeException
*
* @return StreamedResponse
*/
public function getResponse($format, $filename, SourceIteratorInterface $source)
public function getResponse(string $format, string $filename, SourceIteratorInterface $source): StreamedResponse
{
if (!\array_key_exists($format, $this->writers)) {
throw new \RuntimeException(sprintf(
@@ -57,8 +53,8 @@ final class Exporter
}
$writer = $this->writers[$format];
$callback = function () use ($source, $writer) {
$handler = \Exporter\Handler::create($source, $writer);
$callback = static function () use ($source, $writer): void {
$handler = Handler::create($source, $writer);
$handler->export();
};
@@ -76,7 +72,7 @@ final class Exporter
*
* @return string[] writer formats as returned by the TypedWriterInterface::getFormat() method
*/
public function getAvailableFormats()
public function getAvailableFormats(): array
{
return array_keys($this->writers);
}
@@ -86,10 +82,8 @@ final class Exporter
*
* @param TypedWriterInterface $writer a possible writer for exporting data
*/
public function addWriter(TypedWriterInterface $writer)
public function addWriter(TypedWriterInterface $writer): void
{
$this->writers[$writer->getFormat()] = $writer;
}
}
class_exists(\Exporter\Exporter::class);
+7 -17
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -14,29 +16,25 @@ namespace Sonata\Exporter;
use Sonata\Exporter\Source\SourceIteratorInterface;
use Sonata\Exporter\Writer\WriterInterface;
class Handler
final class Handler
{
/**
* @var SourceIteratorInterface
*/
protected $source;
private $source;
/**
* @var WriterInterface
*/
protected $writer;
private $writer;
/**
* @param SourceIteratorInterface $source
* @param WriterInterface $writer
*/
public function __construct(SourceIteratorInterface $source, WriterInterface $writer)
{
$this->source = $source;
$this->writer = $writer;
}
public function export()
public function export(): void
{
$this->writer->open();
@@ -47,16 +45,8 @@ class Handler
$this->writer->close();
}
/**
* @param SourceIteratorInterface $source
* @param WriterInterface $writer
*
* @return Handler
*/
public static function create(SourceIteratorInterface $source, WriterInterface $writer)
public static function create(SourceIteratorInterface $source, WriterInterface $writer): self
{
return new self($source, $writer);
}
}
class_exists(\Exporter\Handler::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -21,17 +23,17 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
/**
* @var string
*/
protected $filename = null;
protected $filename;
/**
* @var resource
* @var resource|null
*/
protected $file = null;
protected $file;
/**
* @var bool|null
* @var bool
*/
protected $hasHeaders = null;
protected $hasHeaders;
/**
* @var string[]
@@ -39,9 +41,9 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
protected $columns = [];
/**
* @var resource
* @var resource|null
*/
protected $parser = null;
protected $parser;
/**
* @var int
@@ -56,7 +58,7 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
/**
* @var mixed
*/
protected $currentRow = null;
protected $currentRow;
/**
* @var array
@@ -73,11 +75,7 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
*/
protected $position = 0;
/**
* @param string $filename
* @param bool $hasHeaders
*/
public function __construct($filename, $hasHeaders = true)
public function __construct(string $filename, bool $hasHeaders = true)
{
$this->filename = $filename;
$this->hasHeaders = $hasHeaders;
@@ -87,64 +85,54 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
* Start element handler.
*
* @param resource $parser
* @param string $name
* @param array $attributes
*/
abstract public function tagStart($parser, $name, $attributes = []);
abstract public function tagStart($parser, string $name, array $attributes = []);
/**
* End element handler.
*
* @param resource $parser
* @param string $name
*/
abstract public function tagEnd($parser, $name);
abstract public function tagEnd($parser, string $name);
/**
* Tag content handler.
*
* @param resource $parser
* @param string $data
*/
abstract public function tagContent($parser, $data);
abstract public function tagContent($parser, string $data);
/**
* {@inheritdoc}
* @return mixed
*/
public function current()
final public function current()
{
return $this->currentRow;
}
/**
* {@inheritdoc}
* @return mixed
*/
public function key()
final public function key()
{
return $this->position;
}
/**
* {@inheritdoc}
*/
public function next()
final public function next(): void
{
$this->parseRow();
$this->prepareCurrentRow();
++$this->position;
}
/**
* {@inheritdoc}
*/
public function rewind()
final public function rewind(): void
{
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'tagStart', 'tagEnd');
xml_set_character_data_handler($this->parser, 'tagContent');
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 0);
xml_set_element_handler($this->parser, [$this, 'tagStart'], [$this, 'tagEnd']);
xml_set_character_data_handler($this->parser, [$this, 'tagContent']);
xml_parser_set_option($this->parser, \XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($this->parser, \XML_OPTION_SKIP_WHITE, 0);
$this->file = fopen($this->filename, 'r');
@@ -160,10 +148,7 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
$this->prepareCurrentRow();
}
/**
* {@inheritdoc}
*/
public function valid()
final public function valid(): bool
{
if (!\is_array($this->currentRow)) {
xml_parser_free($this->parser);
@@ -178,7 +163,7 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
/**
* Parse until </Row> reached.
*/
protected function parseRow()
final protected function parseRow(): void
{
// only parse the next row if only one in buffer
if (\count($this->bufferedRow) > 1) {
@@ -201,7 +186,7 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
/**
* Prepare the row to return.
*/
protected function prepareCurrentRow()
protected function prepareCurrentRow(): void
{
$this->currentRow = array_shift($this->bufferedRow);
if (\is_array($this->currentRow)) {
@@ -217,5 +202,3 @@ abstract class AbstractXmlSourceIterator implements SourceIteratorInterface
}
}
}
class_exists(\Exporter\Source\AbstractXmlSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -11,15 +13,10 @@
namespace Sonata\Exporter\Source;
class ArraySourceIterator extends IteratorSourceIterator
final class ArraySourceIterator extends IteratorSourceIterator
{
/**
* @param array $data
*/
public function __construct(array $data)
{
parent::__construct(new \ArrayIterator($data));
}
}
class_exists(\Exporter\Source\ArraySourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -11,63 +13,49 @@
namespace Sonata\Exporter\Source;
use ArrayIterator;
class ChainSourceIterator implements SourceIteratorInterface
final class ChainSourceIterator implements SourceIteratorInterface
{
/**
* @var ArrayIterator
* @var \ArrayIterator
*/
protected $sources;
private $sources;
/**
* @param array $sources
*/
public function __construct(array $sources = [])
{
$this->sources = new ArrayIterator();
$this->sources = new \ArrayIterator();
foreach ($sources as $source) {
$this->addSource($source);
}
}
/**
* @param SourceIteratorInterface $source
*/
public function addSource(SourceIteratorInterface $source)
public function addSource(SourceIteratorInterface $source): void
{
$this->sources->append($source);
}
/**
* {@inheritdoc}
* @return mixed
*/
public function current()
{
return $this->sources->current()->current();
}
/**
* {@inheritdoc}
*/
public function next()
public function next(): void
{
$this->sources->current()->next();
}
/**
* {@inheritdoc}
* @return mixed
*/
public function key()
{
return $this->sources->current()->key();
}
/**
* {@inheritdoc}
*/
public function valid()
public function valid(): bool
{
while (!$this->sources->current()->valid()) {
$this->sources->next();
@@ -82,15 +70,10 @@ class ChainSourceIterator implements SourceIteratorInterface
return true;
}
/**
* {@inheritdoc}
*/
public function rewind()
public function rewind(): void
{
if ($this->sources->current()) {
$this->sources->current()->rewind();
}
}
}
class_exists(\Exporter\Source\ChainSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -16,67 +18,65 @@ namespace Sonata\Exporter\Source;
*
* @author Vincent Touzet <vincent.touzet@gmail.com>
*/
class CsvSourceIterator implements SourceIteratorInterface
final class CsvSourceIterator implements SourceIteratorInterface
{
/**
* @var string
*/
protected $filename = null;
private $filename;
/**
* @var resource
* @var resource|null
*/
protected $file = null;
private $file;
/**
* @var string|null
* @var string
*/
protected $delimiter = null;
private $delimiter;
/**
* @var string|null
* @var string
*/
protected $enclosure = null;
private $enclosure;
/**
* @var string|null
* @var string
*/
protected $escape = null;
private $escape;
/**
* @var bool|null
* @var bool
*/
protected $hasHeaders = null;
private $hasHeaders;
/**
* @var array
*/
protected $lines = [];
private $lines = [];
/**
* @var array
*/
protected $columns = [];
private $columns = [];
/**
* @var int
*/
protected $position = 0;
private $position = 0;
/**
* @var array
*/
protected $currentLine = [];
private $currentLine = [];
/**
* @param string $filename
* @param string $delimiter
* @param string $enclosure
* @param string $escape
* @param bool $hasHeaders
*/
public function __construct($filename, $delimiter = ',', $enclosure = '"', $escape = '\\', $hasHeaders = true)
{
public function __construct(
string $filename,
string $delimiter = ',',
string $enclosure = '"',
string $escape = '\\',
bool $hasHeaders = true
) {
$this->filename = $filename;
$this->delimiter = $delimiter;
$this->enclosure = $enclosure;
@@ -85,7 +85,7 @@ class CsvSourceIterator implements SourceIteratorInterface
}
/**
* {@inheritdoc}
* @return mixed
*/
public function current()
{
@@ -93,17 +93,14 @@ class CsvSourceIterator implements SourceIteratorInterface
}
/**
* {@inheritdoc}
* @return mixed
*/
public function key()
{
return $this->position;
}
/**
* {@inheritdoc}
*/
public function next()
public function next(): void
{
$line = fgetcsv($this->file, 0, $this->delimiter, $this->enclosure, $this->escape);
$this->currentLine = $line;
@@ -117,10 +114,7 @@ class CsvSourceIterator implements SourceIteratorInterface
}
}
/**
* {@inheritdoc}
*/
public function rewind()
public function rewind(): void
{
$this->file = fopen($this->filename, 'r');
$this->position = 0;
@@ -139,10 +133,7 @@ class CsvSourceIterator implements SourceIteratorInterface
}
}
/**
* {@inheritdoc}
*/
public function valid()
public function valid(): bool
{
if (!\is_array($this->currentLine)) {
if (\is_resource($this->file)) {
@@ -155,5 +146,3 @@ class CsvSourceIterator implements SourceIteratorInterface
return true;
}
}
class_exists(\Exporter\Source\CsvSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -13,101 +15,72 @@ namespace Sonata\Exporter\Source;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Statement;
use Sonata\Exporter\Exception\InvalidMethodCallException;
class DoctrineDBALConnectionSourceIterator implements SourceIteratorInterface
final class DoctrineDBALConnectionSourceIterator implements SourceIteratorInterface
{
/**
* @var Connection
*/
protected $connection;
private $connection;
/**
* @var string
*/
protected $query;
private $query;
/**
* @var array
*/
protected $parameters;
private $parameters;
/**
* @var mixed
*/
protected $current;
private $current;
/**
* @var int
*/
protected $position;
private $position = 0;
/**
* @var Statement
*/
protected $statement;
private $statement;
/**
* @param Connection $connection
* @param $query
* @param array $parameters
*/
public function __construct(Connection $connection, $query, array $parameters = [])
public function __construct(Connection $connection, string $query, array $parameters = [])
{
$this->connection = $connection;
$this->query = $query;
$this->parameters = $parameters;
$this->position = 0;
}
/**
* {@inheritdoc}
*/
public function current()
{
return $this->current;
}
/**
* {@inheritdoc}
*/
public function next()
public function next(): void
{
$this->current = $this->statement->fetch(\PDO::FETCH_ASSOC);
++$this->position;
}
/**
* {@inheritdoc}
*/
public function key()
{
return $this->position;
}
/**
* {@inheritdoc}
*/
public function valid()
public function valid(): bool
{
return \is_array($this->current);
}
/**
* {@inheritdoc}
*/
public function rewind()
public function rewind(): void
{
if ($this->statement) {
throw new InvalidMethodCallException('Cannot rewind a PDOStatement');
}
$this->statement = $this->connection->prepare($this->query);
$this->statement->execute($this->parameters);
$this->next();
}
}
class_exists(\Exporter\Source\DoctrineDBALConnectionSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -12,149 +14,44 @@
namespace Sonata\Exporter\Source;
use Doctrine\ODM\MongoDB\Query\Query;
use Doctrine\ORM\Internal\Hydration\IterableResult;
use Sonata\Exporter\Exception\InvalidMethodCallException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyPath;
class DoctrineODMQuerySourceIterator implements SourceIteratorInterface
final class DoctrineODMQuerySourceIterator extends AbstractPropertySourceIterator implements SourceIteratorInterface
{
/**
* @var Query
*/
protected $query;
private $query;
/**
* @var IterableResult
* @param array<string> $fields Fields to export
*/
protected $iterator;
/**
* @var array
*/
protected $propertyPaths;
/**
* @var PropertyAccess
*/
protected $propertyAccessor;
/**
* @var string default DateTime format
*/
protected $dateTimeFormat;
/**
* @param Query $query The Doctrine Query
* @param array $fields Fields to export
* @param string $dateTimeFormat
*/
public function __construct(Query $query, array $fields, $dateTimeFormat = 'r')
public function __construct(Query $query, array $fields, string $dateTimeFormat = 'r')
{
$this->query = clone $query;
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
$this->propertyPaths = [];
foreach ($fields as $name => $field) {
if (\is_string($name) && \is_string($field)) {
$this->propertyPaths[$name] = new PropertyPath($field);
} else {
$this->propertyPaths[$field] = new PropertyPath($field);
}
}
$this->dateTimeFormat = $dateTimeFormat;
parent::__construct($fields, $dateTimeFormat);
}
/**
* {@inheritdoc}
* @return mixed
*/
public function current()
{
$current = $this->iterator->current();
$data = [];
$data = $this->getCurrentData($current);
foreach ($this->propertyPaths as $name => $propertyPath) {
$data[$name] = $this->getValue($this->propertyAccessor->getValue($current, $propertyPath));
}
$this->query->getDocumentManager()->getUnitOfWork()->detach($current);
$this->query->getDocumentManager()->clear();
return $data;
}
/**
* {@inheritdoc}
*/
public function next()
public function rewind(): void
{
$this->iterator->next();
}
/**
* {@inheritdoc}
*/
public function key()
{
return $this->iterator->key();
}
/**
* {@inheritdoc}
*/
public function valid()
{
return $this->iterator->valid();
}
/**
* {@inheritdoc}
*/
public function rewind()
{
if ($this->iterator) {
throw new InvalidMethodCallException('Cannot rewind a Doctrine\ODM\Query');
if (null === $this->iterator) {
$this->iterator = $this->query->getIterator();
}
$this->iterator = $this->query->iterate();
$this->iterator->rewind();
}
/**
* @param string $dateTimeFormat
*/
public function setDateTimeFormat($dateTimeFormat)
{
$this->dateTimeFormat = $dateTimeFormat;
}
/**
* @return string
*/
public function getDateTimeFormat()
{
return $this->dateTimeFormat;
}
/**
* @param $value
*
* @return string|null
*/
protected function getValue($value)
{
if (\is_array($value) || $value instanceof \Traversable) {
$value = null;
} elseif ($value instanceof \DateTimeInterface) {
$value = $value->format($this->dateTimeFormat);
} elseif (\is_object($value)) {
$value = (string) $value;
}
return $value;
}
}
class_exists(\Exporter\Source\DoctrineODMQuerySourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -12,56 +14,26 @@
namespace Sonata\Exporter\Source;
use Doctrine\ORM\Query;
use Sonata\Exporter\Exception\InvalidMethodCallException;
use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\PropertyAccess\PropertyPath;
class DoctrineORMQuerySourceIterator implements SourceIteratorInterface
/**
* @final since sonata-project/exporter 2.4.
*/
class DoctrineORMQuerySourceIterator extends AbstractPropertySourceIterator implements SourceIteratorInterface
{
const DATE_PARTS = [
'y' => 'Y',
'm' => 'M',
'd' => 'D',
];
const TIME_PARTS = [
'h' => 'H',
'i' => 'M',
's' => 'S',
];
/**
* @var \Doctrine\ORM\Query
* @var Query
*/
protected $query;
/**
* @var \Doctrine\ORM\Internal\Hydration\IterableResult
* @var int
*/
protected $iterator;
private $batchSize;
/**
* @var array
* @param array<string> $fields Fields to export
*/
protected $propertyPaths;
/**
* @var PropertyAccessor
*/
protected $propertyAccessor;
/**
* @var string default DateTime format
*/
protected $dateTimeFormat;
/**
* @param \Doctrine\ORM\Query $query The Doctrine Query
* @param array $fields Fields to export
* @param string $dateTimeFormat
*/
public function __construct(Query $query, array $fields, $dateTimeFormat = 'r')
public function __construct(Query $query, array $fields, string $dateTimeFormat = 'r', int $batchSize = 100)
{
$this->query = clone $query;
$this->query->setParameters($query->getParameters());
@@ -69,142 +41,42 @@ class DoctrineORMQuerySourceIterator implements SourceIteratorInterface
$this->query->setHint($name, $value);
}
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
$this->batchSize = $batchSize;
$this->propertyPaths = [];
foreach ($fields as $name => $field) {
if (\is_string($name) && \is_string($field)) {
$this->propertyPaths[$name] = new PropertyPath($field);
} else {
$this->propertyPaths[$field] = new PropertyPath($field);
}
}
$this->dateTimeFormat = $dateTimeFormat;
parent::__construct($fields, $dateTimeFormat);
}
/**
* {@inheritdoc}
* @return mixed
*/
public function current()
{
$current = $this->iterator->current();
$data = [];
$data = $this->getCurrentData($current);
foreach ($this->propertyPaths as $name => $propertyPath) {
try {
$data[$name] = $this->getValue($this->propertyAccessor->getValue($current[0], $propertyPath));
} catch (UnexpectedTypeException $e) {
//non existent object in path will be ignored
$data[$name] = null;
}
if (0 === ($this->iterator->key() % $this->batchSize)) {
$this->query->getEntityManager()->clear();
}
$this->query->getEntityManager()->getUnitOfWork()->detach($current[0]);
return $data;
}
/**
* {@inheritdoc}
*/
public function next()
final public function rewind(): void
{
$this->iterator->next();
}
/**
* {@inheritdoc}
*/
public function key()
{
return $this->iterator->key();
}
/**
* {@inheritdoc}
*/
public function valid()
{
return $this->iterator->valid();
}
/**
* {@inheritdoc}
*/
public function rewind()
{
if ($this->iterator) {
throw new InvalidMethodCallException('Cannot rewind a Doctrine\ORM\Query');
}
$this->iterator = $this->query->iterate();
$this->iterator = $this->iterableToIterator($this->query->toIterable());
$this->iterator->rewind();
}
/**
* @param string $dateTimeFormat
*/
public function setDateTimeFormat($dateTimeFormat)
private function iterableToIterator(iterable $iterable): \Iterator
{
$this->dateTimeFormat = $dateTimeFormat;
}
/**
* @return string
*/
public function getDateTimeFormat()
{
return $this->dateTimeFormat;
}
/**
* @param \DateInterval $interval
*
* @return string An ISO8601 duration
*/
public function getDuration(\DateInterval $interval)
{
$datePart = '';
foreach (self::DATE_PARTS as $datePartAttribute => $datePartAttributeString) {
if ($interval->$datePartAttribute !== 0) {
$datePart .= $interval->$datePartAttribute.$datePartAttributeString;
}
if ($iterable instanceof \Iterator) {
return $iterable;
}
if (\is_array($iterable)) {
return new \ArrayIterator($iterable);
}
$timePart = '';
foreach (self::TIME_PARTS as $timePartAttribute => $timePartAttributeString) {
if ($interval->$timePartAttribute !== 0) {
$timePart .= $interval->$timePartAttribute.$timePartAttributeString;
}
}
if ('' === $datePart && '' === $timePart) {
return 'P0Y';
}
return 'P'.$datePart.('' !== $timePart ? 'T'.$timePart : '');
}
/**
* @param $value
*
* @return string|null
*/
protected function getValue($value)
{
if (\is_array($value) || $value instanceof \Traversable) {
$value = null;
} elseif ($value instanceof \DateTimeInterface) {
$value = $value->format($this->dateTimeFormat);
} elseif ($value instanceof \DateInterval) {
$value = $this->getDuration($value);
} elseif (\is_object($value)) {
$value = (string) $value;
}
return $value;
return new \ArrayIterator(iterator_to_array($iterable));
}
}
class_exists(\Exporter\Source\DoctrineORMQuerySourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -16,12 +18,12 @@ namespace Sonata\Exporter\Source;
*
* @author Florent Denis <fdenis@ekino.com>
*/
class IteratorCallbackSourceIterator extends IteratorSourceIterator
final class IteratorCallbackSourceIterator extends IteratorSourceIterator
{
/**
* @var \Closure
*/
protected $transformer;
private $transformer;
/**
* @param \Iterator $iterator Iterator with string array elements
@@ -35,12 +37,10 @@ class IteratorCallbackSourceIterator extends IteratorSourceIterator
}
/**
* {@inheritdoc}
* @return mixed
*/
public function current()
{
return \call_user_func($this->transformer, $this->iterator->current());
}
}
class_exists(\Exporter\Source\IteratorCallbackSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -29,53 +31,39 @@ class IteratorSourceIterator implements SourceIteratorInterface
$this->iterator = $iterator;
}
/**
* @return \Iterator
*/
public function getIterator()
final public function getIterator(): \Iterator
{
return $this->iterator;
}
/**
* {@inheritdoc}
* @return mixed
*/
public function current()
{
return $this->iterator->current();
}
/**
* {@inheritdoc}
*/
public function next()
final public function next(): void
{
$this->iterator->next();
}
/**
* {@inheritdoc}
* @return mixed
*/
public function key()
final public function key()
{
return $this->iterator->key();
}
/**
* {@inheritdoc}
*/
public function valid()
final public function valid(): bool
{
return $this->iterator->valid();
}
/**
* {@inheritdoc}
*/
public function rewind()
final public function rewind(): void
{
$this->iterator->rewind();
}
}
class_exists(\Exporter\Source\IteratorSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -13,75 +15,61 @@ namespace Sonata\Exporter\Source;
use Sonata\Exporter\Exception\InvalidMethodCallException;
class PDOStatementSourceIterator implements SourceIteratorInterface
final class PDOStatementSourceIterator implements SourceIteratorInterface
{
/**
* @var \PDOStatement
*/
protected $statement;
private $statement;
/**
* @var mixed
*/
protected $current;
private $current;
/**
* @var int
*/
protected $position;
private $position = 0;
/**
* @var bool
*/
protected $rewinded;
private $rewinded = false;
/**
* @param \PDOStatement $statement
*/
public function __construct(\PDOStatement $statement)
{
$this->statement = $statement;
$this->position = 0;
$this->rewinded = false;
}
/**
* {@inheritdoc}
* @return mixed
*/
public function current()
{
return $this->current;
}
/**
* {@inheritdoc}
*/
public function next()
public function next(): void
{
$this->current = $this->statement->fetch(\PDO::FETCH_ASSOC);
++$this->position;
}
/**
* {@inheritdoc}
* @return mixed
*/
public function key()
{
return $this->position;
}
/**
* {@inheritdoc}
*/
public function valid()
public function valid(): bool
{
return \is_array($this->current);
}
/**
* {@inheritdoc}
*/
public function rewind()
public function rewind(): void
{
if ($this->rewinded) {
throw new InvalidMethodCallException('Cannot rewind a PDOStatement');
@@ -91,5 +79,3 @@ class PDOStatementSourceIterator implements SourceIteratorInterface
$this->rewinded = true;
}
}
class_exists(\Exporter\Source\PDOStatementSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -12,152 +14,35 @@
namespace Sonata\Exporter\Source;
use PropelCollection;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\PropertyAccess\PropertyPath;
/**
* Read data from a PropelCollection.
*
* @author Kévin Gomez <contact@kevingomez.fr>
*/
class PropelCollectionSourceIterator implements SourceIteratorInterface
final class PropelCollectionSourceIterator extends AbstractPropertySourceIterator implements SourceIteratorInterface
{
/**
* @var \PropelCollection
*/
protected $collection;
private $collection;
/**
* @var \ArrayIterator
* @param array<string> $fields Fields to export
*/
protected $iterator;
/**
* @var array
*/
protected $propertyPaths;
/**
* @var PropertyAccessor
*/
protected $propertyAccessor;
/**
* @var string default DateTime format
*/
protected $dateTimeFormat;
/**
* @param PropelCollection $collection
* @param array $fields Fields to export
* @param string $dateTimeFormat
*/
public function __construct(PropelCollection $collection, array $fields, $dateTimeFormat = 'r')
public function __construct(\PropelCollection $collection, array $fields, string $dateTimeFormat = 'r')
{
$this->collection = clone $collection;
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
$this->propertyPaths = [];
foreach ($fields as $name => $field) {
if (\is_string($name) && \is_string($field)) {
$this->propertyPaths[$name] = new PropertyPath($field);
} else {
$this->propertyPaths[$field] = new PropertyPath($field);
}
}
$this->dateTimeFormat = $dateTimeFormat;
parent::__construct($fields, $dateTimeFormat);
}
/**
* {@inheritdoc}
*/
public function current()
public function rewind(): void
{
$current = $this->iterator->current();
$data = [];
foreach ($this->propertyPaths as $name => $propertyPath) {
$data[$name] = $this->getValue($this->propertyAccessor->getValue($current, $propertyPath));
if (null === $this->iterator) {
$this->iterator = $this->collection->getIterator();
}
return $data;
}
/**
* {@inheritdoc}
*/
public function next()
{
$this->iterator->next();
}
/**
* {@inheritdoc}
*/
public function key()
{
return $this->iterator->key();
}
/**
* {@inheritdoc}
*/
public function valid()
{
return $this->iterator->valid();
}
/**
* {@inheritdoc}
*/
public function rewind()
{
if ($this->iterator) {
$this->iterator->rewind();
return;
}
$this->iterator = $this->collection->getIterator();
$this->iterator->rewind();
}
/**
* @param string $dateTimeFormat
*/
public function setDateTimeFormat($dateTimeFormat)
{
$this->dateTimeFormat = $dateTimeFormat;
}
/**
* @return string
*/
public function getDateTimeFormat()
{
return $this->dateTimeFormat;
}
/**
* @param $value
*
* @return string|null
*/
protected function getValue($value)
{
if (\is_array($value) || $value instanceof \Traversable) {
$value = null;
} elseif ($value instanceof \DateTimeInterface) {
$value = $value->format($this->dateTimeFormat);
} elseif (\is_object($value)) {
$value = (string) $value;
}
return $value;
}
}
class_exists(\Exporter\Source\PropelCollectionSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -11,8 +13,9 @@
namespace Sonata\Exporter\Source;
/**
* @phpstan-extends \Iterator<array<mixed>>
*/
interface SourceIteratorInterface extends \Iterator
{
}
interface_exists(\Exporter\Source\SourceIteratorInterface::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -14,45 +16,40 @@ namespace Sonata\Exporter\Source;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
class SymfonySitemapSourceIterator implements SourceIteratorInterface
final class SymfonySitemapSourceIterator implements SourceIteratorInterface
{
/**
* @var RouterInterface
*/
protected $router;
private $router;
/**
* @var SourceIteratorInterface
*/
protected $source;
private $source;
/**
* @var string
*/
protected $routeName;
private $routeName;
/**
* @var array
*/
protected $parameters;
private $parameters;
/**
* @param SourceIteratorInterface $source
* @param RouterInterface $router
* @param string $routeName
* @param array $parameters
*/
public function __construct(SourceIteratorInterface $source, RouterInterface $router, $routeName, array $parameters = [])
{
public function __construct(
SourceIteratorInterface $source,
RouterInterface $router,
string $routeName,
array $parameters = []
) {
$this->source = $source;
$this->router = $router;
$this->routeName = $routeName;
$this->parameters = $parameters;
}
/**
* {@inheritdoc}
*/
public function current()
{
$data = $this->source->current();
@@ -66,37 +63,23 @@ class SymfonySitemapSourceIterator implements SourceIteratorInterface
return $data;
}
/**
* {@inheritdoc}
*/
public function next()
public function next(): void
{
$this->source->next();
}
/**
* {@inheritdoc}
*/
public function key()
{
return $this->source->key();
}
/**
* {@inheritdoc}
*/
public function valid()
public function valid(): bool
{
return $this->source->valid();
}
/**
* {@inheritdoc}
*/
public function rewind()
public function rewind(): void
{
$this->source->rewind();
}
}
class_exists(\Exporter\Source\SymfonySitemapSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -16,21 +18,14 @@ namespace Sonata\Exporter\Source;
*
* @author Vincent Touzet <vincent.touzet@gmail.com>
*/
class XmlExcelSourceIterator extends AbstractXmlSourceIterator
final class XmlExcelSourceIterator extends AbstractXmlSourceIterator
{
/**
* @param string $filename
* @param bool $hasHeaders
*/
public function __construct($filename, $hasHeaders = true)
public function __construct(string $filename, bool $hasHeaders = true)
{
parent::__construct($filename, $hasHeaders);
}
/**
* {@inheritdoc}
*/
public function tagStart($parser, $name, $attributes = [])
public function tagStart($parser, string $name, array $attributes = []): void
{
switch ($name) {
case 'ss:Row':
@@ -47,10 +42,7 @@ class XmlExcelSourceIterator extends AbstractXmlSourceIterator
}
}
/**
* {@inheritdoc}
*/
public function tagEnd($parser, $name)
public function tagEnd($parser, string $name): void
{
switch ($name) {
case 'ss:Row':
@@ -68,13 +60,8 @@ class XmlExcelSourceIterator extends AbstractXmlSourceIterator
}
}
/**
* {@inheritdoc}
*/
public function tagContent($parser, $data)
public function tagContent($parser, string $data): void
{
$this->bufferedRow['i_'.$this->currentRowIndex][$this->currentColumnIndex] .= $data;
}
}
class_exists(\Exporter\Source\XmlExcelSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -16,34 +18,26 @@ namespace Sonata\Exporter\Source;
*
* @author Vincent Touzet <vincent.touzet@gmail.com>
*/
class XmlSourceIterator extends AbstractXmlSourceIterator
final class XmlSourceIterator extends AbstractXmlSourceIterator
{
/**
* @var string
*/
protected $mainTag;
private $mainTag;
/**
* @var string
*/
protected $dataTag;
private $dataTag;
/**
* @param string $filename
* @param string $mainTag
* @param string $dataTag
*/
public function __construct($filename, $mainTag = 'datas', $dataTag = 'data')
public function __construct(string $filename, string $mainTag = 'datas', string $dataTag = 'data')
{
parent::__construct($filename, false);
$this->mainTag = $mainTag;
$this->dataTag = $dataTag;
}
/**
* {@inheritdoc}
*/
public function tagStart($parser, $name, $attributes = [])
public function tagStart($parser, string $name, array $attributes = []): void
{
switch ($name) {
case $this->mainTag:
@@ -63,10 +57,7 @@ class XmlSourceIterator extends AbstractXmlSourceIterator
}
}
/**
* {@inheritdoc}
*/
public function tagEnd($parser, $name)
public function tagEnd($parser, string $name): void
{
switch ($name) {
case $this->mainTag:
@@ -84,21 +75,17 @@ class XmlSourceIterator extends AbstractXmlSourceIterator
}
}
/**
* {@inheritdoc}
*/
public function tagContent($parser, $data)
public function tagContent($parser, string $data): void
{
if (isset($this->bufferedRow['i_'.$this->currentRowIndex], $this->bufferedRow['i_'.$this->currentRowIndex][$this->currentColumnIndex])
) {
if (isset(
$this->bufferedRow['i_'.$this->currentRowIndex],
$this->bufferedRow['i_'.$this->currentRowIndex][$this->currentColumnIndex]
)) {
$this->bufferedRow['i_'.$this->currentRowIndex][$this->currentColumnIndex] .= $data;
}
}
/**
* {@inheritdoc}
*/
protected function prepareCurrentRow()
protected function prepareCurrentRow(): void
{
$this->currentRow = array_shift($this->bufferedRow);
if (\is_array($this->currentRow)) {
@@ -110,5 +97,3 @@ class XmlSourceIterator extends AbstractXmlSourceIterator
}
}
}
class_exists(\Exporter\Source\XmlSourceIterator::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -11,38 +13,33 @@
namespace Sonata\Exporter\Test;
use PHPUnit\Framework\TestCase;
use Sonata\Exporter\Writer\TypedWriterInterface;
/**
* @author Grégoire Paris <postmaster@greg0ire.fr>
*/
abstract class AbstractTypedWriterTestCase extends \PHPUnit\Framework\TestCase
abstract class AbstractTypedWriterTestCase extends TestCase
{
/**
* @var WriterInterface
* @var TypedWriterInterface
*/
private $writer;
protected function setUp()
protected function setUp(): void
{
$this->writer = $this->getWriter();
}
public function testFormatIsString()
final public function testFormatIsString(): void
{
$this->assertInternalType('string', $this->writer->getFormat());
static::assertIsString($this->writer->getFormat());
}
public function testDefaultMimeTypeIsString()
final public function testDefaultMimeTypeIsString(): void
{
$this->assertInternalType('string', $this->writer->getDefaultMimeType());
static::assertIsString($this->writer->getDefaultMimeType());
}
/**
* Should return a very simple instance of the writer (no need for complex
* configuration).
*
* @return WriterInterface
*/
abstract protected function getWriter();
abstract protected function getWriter(): TypedWriterInterface;
}
class_exists(\Exporter\Test\AbstractTypedWriterTestCase::class);
+38 -51
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -16,47 +18,47 @@ use Sonata\Exporter\Exception\InvalidDataFormatException;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class CsvWriter implements TypedWriterInterface
final class CsvWriter implements TypedWriterInterface
{
/**
* @var string
*/
protected $filename;
private $filename;
/**
* @var string
*/
protected $delimiter;
private $delimiter;
/**
* @var string
*/
protected $enclosure;
private $enclosure;
/**
* @var string
*/
protected $escape;
private $escape;
/**
* @var resource
*/
protected $file;
private $file;
/**
* @var bool
*/
protected $showHeaders;
private $showHeaders;
/**
* @var int
*/
protected $position;
private $position;
/**
* @var bool
*/
protected $withBom;
private $withBom;
/**
* @var string
@@ -64,22 +66,16 @@ class CsvWriter implements TypedWriterInterface
private $terminate;
/**
* @param string $filename
* @param string $delimiter
* @param string $enclosure
* @param string $escape
* @param bool $showHeaders
* @param bool $withBom
* @param string $terminate
* @throws \RuntimeException
*/
public function __construct(
$filename,
$delimiter = ',',
$enclosure = '"',
$escape = '\\',
$showHeaders = true,
$withBom = false,
$terminate = "\n"
string $filename,
string $delimiter = ',',
string $enclosure = '"',
string $escape = '\\',
bool $showHeaders = true,
bool $withBom = false,
string $terminate = "\n"
) {
$this->filename = $filename;
$this->delimiter = $delimiter;
@@ -95,56 +91,52 @@ class CsvWriter implements TypedWriterInterface
}
}
/**
* {@inheritdoc}
*/
final public function getDefaultMimeType()
public function getDefaultMimeType(): string
{
return 'text/csv';
}
/**
* {@inheritdoc}
*/
final public function getFormat()
public function getFormat(): string
{
return 'csv';
}
/**
* {@inheritdoc}
*/
public function open()
public function open(): void
{
$this->file = fopen($this->filename, 'w', false);
if ("\n" !== $this->terminate) {
stream_filter_register('filterTerminate', CsvWriterTerminate::class);
stream_filter_append($this->file, 'filterTerminate', STREAM_FILTER_WRITE, ['terminate' => $this->terminate]);
stream_filter_append($this->file, 'filterTerminate', \STREAM_FILTER_WRITE, ['terminate' => $this->terminate]);
}
if (true === $this->withBom) {
fprintf($this->file, \chr(0xEF).\chr(0xBB).\chr(0xBF));
}
}
/**
* {@inheritdoc}
*/
public function close()
public function close(): void
{
fclose($this->file);
}
/**
* {@inheritdoc}
*/
public function write(array $data)
public function write(array $data): void
{
if (0 == $this->position && $this->showHeaders) {
if (0 === $this->position && $this->showHeaders) {
$this->addHeaders($data);
++$this->position;
}
if (1 !== \strlen($this->delimiter) ||
1 !== \strlen($this->enclosure) ||
1 !== \strlen($this->escape)) {
throw new InvalidDataFormatException(<<<'EXCEPTION'
Context: trying to write CSV data
Problem: delimiter, enclosure or escape character is actually a
string longer than just one character
Solution: pick an actual character
EXCEPTION);
}
$result = @fputcsv($this->file, $data, $this->delimiter, $this->enclosure, $this->escape);
if (!$result) {
@@ -154,10 +146,7 @@ class CsvWriter implements TypedWriterInterface
++$this->position;
}
/**
* @param array $data
*/
protected function addHeaders(array $data)
private function addHeaders(array $data): void
{
$headers = [];
foreach ($data as $header => $value) {
@@ -167,5 +156,3 @@ class CsvWriter implements TypedWriterInterface
fputcsv($this->file, $headers, $this->delimiter, $this->enclosure, $this->escape);
}
}
class_exists(\Exporter\Writer\CsvWriter::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -17,14 +19,12 @@ namespace Sonata\Exporter\Writer;
final class CsvWriterTerminate extends \php_user_filter
{
/**
* @param $in
* @param $out
* @param $consumed
* @param $closing
*
* @return int
* @param resource $in
* @param resource $out
* @param int $consumed
* @param bool $closing
*/
public function filter($in, $out, &$consumed, $closing)
public function filter($in, $out, &$consumed, $closing): int
{
while ($bucket = stream_bucket_make_writeable($in)) {
if (isset($this->params['terminate'])) {
@@ -34,8 +34,6 @@ final class CsvWriterTerminate extends \php_user_filter
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
return \PSFS_PASS_ON;
}
}
class_exists(\Exporter\Writer\CsvWriterTerminate::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -16,55 +18,41 @@ namespace Sonata\Exporter\Writer;
*
* @author Robin Chalas <robin.chalas@gmail.com>
*/
class FormattedBoolWriter implements WriterInterface
final class FormattedBoolWriter implements WriterInterface
{
/**
* @var WriterInterface
*/
protected $writer;
private $writer;
/**
* @var string
*/
protected $trueLabel;
private $trueLabel;
/**
* @var string
*/
protected $falseLabel;
private $falseLabel;
/**
* @param WriterInterface $writer
* @param string $falseLabel
* @param string $trueLabel
*/
public function __construct(WriterInterface $writer, $trueLabel = 'yes', $falseLabel = 'no')
public function __construct(WriterInterface $writer, string $trueLabel = 'yes', string $falseLabel = 'no')
{
$this->writer = $writer;
$this->trueLabel = $trueLabel;
$this->falseLabel = $falseLabel;
}
/**
* {@inheritdoc}
*/
public function open()
public function open(): void
{
$this->writer->open();
}
/**
* {@inheritdoc}
*/
public function close()
public function close(): void
{
$this->writer->close();
}
/**
* {@inheritdoc}
*/
public function write(array $data)
public function write(array $data): void
{
foreach ($data as $key => $value) {
if (\is_bool($data[$key])) {
@@ -74,5 +62,3 @@ class FormattedBoolWriter implements WriterInterface
$this->writer->write($data);
}
}
class_exists(\Exporter\Writer\FormattedBoolWriter::class);
+22 -29
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -16,9 +18,9 @@ namespace Sonata\Exporter\Writer;
*
* @author Rémi Marseille <marseille@ekino.com>
*/
class GsaFeedWriter implements WriterInterface
final class GsaFeedWriter implements WriterInterface
{
const LIMIT_SIZE = 31457280; // 30MB
public const LIMIT_SIZE = 31457280; // 30MB
/**
* @var \SplFileInfo
@@ -46,7 +48,7 @@ class GsaFeedWriter implements WriterInterface
private $bufferPart;
/**
* @var resource
* @var resource|null
*/
private $buffer;
@@ -61,7 +63,7 @@ class GsaFeedWriter implements WriterInterface
* @param string $datasource A datasouce
* @param string $feedtype A feedtype (full|incremental|metadata-and-url)
*/
public function __construct(\SplFileInfo $folder, $dtd, $datasource, $feedtype)
public function __construct(\SplFileInfo $folder, string $dtd, string $datasource, string $feedtype)
{
$this->folder = $folder;
$this->dtd = $dtd;
@@ -71,20 +73,15 @@ class GsaFeedWriter implements WriterInterface
$this->bufferSize = 0;
}
/**
* {@inheritdoc}
*/
public function open()
public function open(): void
{
$this->generateNewPart();
}
/**
* {@inheritdoc}
*/
public function write(array $data)
public function write(array $data): void
{
$line = sprintf(" <record url=\"%s\" mimetype=\"%s\" action=\"%s\"/>\n",
$line = sprintf(
" <record url=\"%s\" mimetype=\"%s\" action=\"%s\"/>\n",
$data['url'],
$data['mime_type'],
$data['action']
@@ -98,12 +95,9 @@ class GsaFeedWriter implements WriterInterface
$this->bufferSize += fwrite($this->buffer, $line);
}
/**
* {@inheritdoc}
*/
public function close()
public function close(): void
{
if ($this->buffer) {
if (null !== $this->buffer) {
$this->closeFeed();
}
}
@@ -113,22 +107,24 @@ class GsaFeedWriter implements WriterInterface
*
* @throws \RuntimeException
*/
private function generateNewPart()
private function generateNewPart(): void
{
if ($this->buffer) {
if (null !== $this->buffer) {
$this->closeFeed();
}
$this->bufferSize = 0;
++$this->bufferPart;
if (!is_writable($this->folder)) {
if (!$this->folder->isWritable()) {
throw new \RuntimeException(sprintf('Unable to write to folder: %s', $this->folder));
}
$this->buffer = fopen(sprintf('%s/feed_%05d.xml', $this->folder, $this->bufferPart), 'w');
$this->bufferSize += fwrite($this->buffer, <<<XML
$this->bufferSize += fwrite(
$this->buffer,
<<<XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gsafeed PUBLIC "-//Google//DTD GSA Feeds//EN" "$this->dtd">
<gsafeed>
@@ -143,12 +139,11 @@ XML
);
}
/**
* Closes the current feed.
*/
private function closeFeed()
private function closeFeed(): void
{
fwrite($this->buffer, <<<'EOF'
fwrite(
$this->buffer,
<<<'EOF'
</group>
</gsafeed>
EOF
@@ -157,5 +152,3 @@ EOF
fclose($this->buffer);
}
}
class_exists(\Exporter\Writer\GsaFeedWriter::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -11,44 +13,30 @@
namespace Sonata\Exporter\Writer;
class InMemoryWriter implements WriterInterface
final class InMemoryWriter implements WriterInterface
{
/**
* @var array
*/
protected $elements;
private $elements;
/**
* {@inheritdoc}
*/
public function open()
public function open(): void
{
$this->elements = [];
}
/**
* {@inheritdoc}
*/
public function close()
{
return $this->elements;
}
/**
* {@inheritdoc}
*/
public function write(array $data)
public function write(array $data): void
{
$this->elements[] = $data;
}
/**
* @return array
*/
public function getElements()
public function getElements(): array
{
return $this->elements;
}
}
class_exists(\Exporter\Writer\InMemoryWriter::class);
+13 -29
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -14,81 +16,63 @@ namespace Sonata\Exporter\Writer;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class JsonWriter implements TypedWriterInterface
final class JsonWriter implements TypedWriterInterface
{
/**
* @var string
*/
protected $filename;
private $filename;
/**
* @var resource
*/
protected $file;
private $file;
/**
* @var int
*/
protected $position;
private $position = 0;
/**
* @param string $filename
* @throws \RuntimeException
*/
public function __construct($filename)
public function __construct(string $filename)
{
$this->filename = $filename;
$this->position = 0;
if (is_file($filename)) {
throw new \RuntimeException(sprintf('The file %s already exist', $filename));
}
}
/**
* {@inheritdoc}
*/
final public function getDefaultMimeType()
public function getDefaultMimeType(): string
{
return 'application/json';
}
/**
* {@inheritdoc}
*/
final public function getFormat()
public function getFormat(): string
{
return 'json';
}
/**
* {@inheritdoc}
*/
public function open()
public function open(): void
{
$this->file = fopen($this->filename, 'w', false);
fwrite($this->file, '[');
}
/**
* {@inheritdoc}
*/
public function close()
public function close(): void
{
fwrite($this->file, ']');
fclose($this->file);
}
/**
* {@inheritdoc}
*/
public function write(array $data)
public function write(array $data): void
{
fwrite($this->file, ($this->position > 0 ? ',' : '').json_encode($data));
++$this->position;
}
}
class_exists(\Exporter\Writer\JsonWriter::class);
+41 -68
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -14,55 +16,55 @@ namespace Sonata\Exporter\Writer;
/**
* Generates a sitemap site from.
*/
class SitemapWriter implements WriterInterface
final class SitemapWriter implements WriterInterface
{
const LIMIT_SIZE = 10485760;
const LIMIT_URL = 50000;
public const LIMIT_SIZE = 10485760;
public const LIMIT_URL = 50000;
/**
* @var string
*/
protected $folder;
private $folder;
/**
* @var string
*/
protected $pattern;
private $pattern;
/**
* @var string
*/
protected $groupName;
private $groupName;
/**
* @var bool
*/
protected $autoIndex;
private $autoIndex;
/**
* @var resource
* @var resource|null
*/
protected $buffer;
private $buffer;
/**
* @var array
*/
protected $headers;
private $headers;
/**
* @var int
*/
protected $bufferSize = 0;
private $bufferSize = 0;
/**
* @var int
*/
protected $bufferUrlCount = 0;
private $bufferUrlCount = 0;
/**
* @var int
*/
protected $bufferPart = 0;
private $bufferPart = 0;
/**
* @param string $folder The folder to store the sitemap.xml file
@@ -70,49 +72,39 @@ class SitemapWriter implements WriterInterface
* @param array $headers Indicate the need for namespace in the header sitemap
* @param bool $autoIndex If you want to generate index of sitemap (optional)
*/
public function __construct($folder, $groupName = false, array $headers = [], $autoIndex = true)
public function __construct(string $folder, $groupName = false, array $headers = [], bool $autoIndex = true)
{
$this->folder = $folder;
$this->groupName = \is_string($groupName) ? $groupName : '';
$this->headers = $headers;
$this->autoIndex = $autoIndex;
$this->pattern = 'sitemap_'.($this->groupName ? $this->groupName.'_' : '').'%05d.xml';
$this->pattern = 'sitemap_'.('' !== $this->groupName ? $this->groupName.'_' : '').'%05d.xml';
}
/**
* Returns the status of auto generation of index site map.
*
* @return bool
*/
public function isAutoIndex()
public function isAutoIndex(): bool
{
return $this->autoIndex;
}
/**
* Returns folder to store the sitemap.xml file.
*
* @return string
*/
public function getFolder()
public function getFolder(): string
{
return $this->folder;
}
/**
* {@inheritdoc}
*/
public function open()
public function open(): void
{
$this->bufferPart = 0;
$this->generateNewPart();
}
/**
* {@inheritdoc}
*/
public function write(array $data)
public function write(array $data): void
{
$data = $this->buildData($data);
@@ -135,20 +127,17 @@ class SitemapWriter implements WriterInterface
$this->addSitemapLine($line);
}
/**
* {@inheritdoc}
*/
public function close()
public function close(): void
{
if ($this->buffer) {
if (null !== $this->buffer) {
$this->closeSitemap();
}
if ($this->autoIndex) {
self::generateSitemapIndex(
$this->folder,
'sitemap_'.($this->groupName ? $this->groupName.'_' : '').'*.xml',
'sitemap'.($this->groupName ? '_'.$this->groupName : '').'.xml'
'sitemap_'.('' !== $this->groupName ? $this->groupName.'_' : '').'*.xml',
'sitemap'.('' !== $this->groupName ? '_'.$this->groupName : '').'.xml'
);
}
}
@@ -161,12 +150,13 @@ class SitemapWriter implements WriterInterface
* @param string $pattern A sitemap pattern, optional
* @param string $filename A sitemap file name, optional
*/
public static function generateSitemapIndex($folder, $baseUrl, $pattern = 'sitemap*.xml', $filename = 'sitemap.xml')
public static function generateSitemapIndex(string $folder, string $baseUrl, string $pattern = 'sitemap*.xml', string $filename = 'sitemap.xml'): void
{
$content = "<?xml version='1.0' encoding='UTF-8'?".">\n<sitemapindex xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.sitemaps.org/schemas/sitemap/1.0 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd' xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>\n";
foreach (glob(sprintf('%s/%s', $folder, $pattern)) as $file) {
$stat = stat($file);
$content .= sprintf("\t".'<sitemap><loc>%s/%s</loc><lastmod>%s</lastmod></sitemap>'."\n",
$content .= sprintf(
"\t".'<sitemap><loc>%s/%s</loc><lastmod>%s</lastmod></sitemap>'."\n",
$baseUrl,
basename($file),
date('Y-m-d', $stat['mtime'])
@@ -183,9 +173,9 @@ class SitemapWriter implements WriterInterface
*
* @throws \RuntimeException
*/
protected function generateNewPart()
private function generateNewPart(): void
{
if ($this->buffer) {
if (null !== $this->buffer) {
$this->closeSitemap();
}
@@ -206,10 +196,8 @@ class SitemapWriter implements WriterInterface
/**
* Add a new line into the sitemap part.
*
* @param string $line
*/
protected function addSitemapLine($line)
private function addSitemapLine(string $line): void
{
if ($this->bufferUrlCount >= self::LIMIT_URL) {
$this->generateNewPart();
@@ -228,10 +216,8 @@ class SitemapWriter implements WriterInterface
* Build data with default parameters.
*
* @param array $data List of parameters
*
* @return array
*/
protected function buildData(array $data)
private function buildData(array $data): array
{
$default = [
'url' => null,
@@ -252,9 +238,9 @@ class SitemapWriter implements WriterInterface
* Fix type of data, if data type is specific,
* he must to be defined in data and he must to be a array.
*
* @param array &$data List of parameters
* @param array $data List of parameters
*/
protected function fixDataType(array &$data)
private function fixDataType(array &$data): void
{
if ('default' === $data['type']) {
return;
@@ -274,10 +260,8 @@ class SitemapWriter implements WriterInterface
* Generate standard line of sitemap.
*
* @param array $data List of parameters
*
* @return string
*/
protected function generateDefaultLine(array $data)
private function generateDefaultLine(array $data): string
{
return sprintf(' '.'<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%s</priority></url>'."\n", $data['url'], date('Y-m-d', strtotime($data['lastmod'])), $data['changefreq'], $data['priority']);
}
@@ -286,10 +270,8 @@ class SitemapWriter implements WriterInterface
* Generate image line of sitemap.
*
* @param array $data List of parameters
*
* @return string
*/
protected function generateImageLine(array $data)
private function generateImageLine(array $data): string
{
$images = '';
@@ -306,7 +288,7 @@ class SitemapWriter implements WriterInterface
$images .= '<image:image>';
foreach ($image as $key => $element) {
$images .= sprintf('<image:%1$s>%2$s</image:%1$s>', (isset($builder[$key]) ? $builder[$key] : $key), $element);
$images .= sprintf('<image:%1$s>%2$s</image:%1$s>', ($builder[$key] ?? $key), $element);
}
$images .= '</image:image>';
@@ -319,10 +301,8 @@ class SitemapWriter implements WriterInterface
* Generate video line of sitemap.
*
* @param array $data List of parameters
*
* @return string
*/
protected function generateVideoLine(array $data)
private function generateVideoLine(array $data): string
{
$videos = '';
$builder = [
@@ -330,7 +310,7 @@ class SitemapWriter implements WriterInterface
];
foreach ($data['video'] as $key => $video) {
$videos .= sprintf('<video:%1$s>%2$s</video:%1$s>', (isset($builder[$key]) ? $builder[$key] : $key), $video);
$videos .= sprintf('<video:%1$s>%2$s</video:%1$s>', ($builder[$key] ?? $key), $video);
}
return sprintf(' '.'<url><loc>%s</loc><video:video>%s</video:video></url>'."\n", $data['url'], $videos);
@@ -338,10 +318,8 @@ class SitemapWriter implements WriterInterface
/**
* Generate additional header with namespace adapted to the content.
*
* @return string
*/
protected function getHeaderByFlag()
private function getHeaderByFlag(): string
{
$namespaces = [
'video' => 'xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"',
@@ -356,14 +334,9 @@ class SitemapWriter implements WriterInterface
return $result;
}
/**
* Close the sitemap part.
*/
protected function closeSitemap()
private function closeSitemap(): void
{
fwrite($this->buffer, '</urlset>');
fclose($this->buffer);
}
}
class_exists(\Exporter\Writer\SitemapWriter::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -22,7 +24,7 @@ interface TypedWriterInterface extends WriterInterface
*
* @return string the mime type of the output
*/
public function getDefaultMimeType();
public function getDefaultMimeType(): string;
/**
* Returns a string best describing the format of the output (the file
@@ -30,7 +32,5 @@ interface TypedWriterInterface extends WriterInterface
*
* @return string a string without spaces, usable in a translation string
*/
public function getFormat();
public function getFormat(): string;
}
interface_exists(\Exporter\Writer\TypedWriterInterface::class);
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -11,16 +13,19 @@
namespace Sonata\Exporter\Writer;
use Sonata\Exporter\Exception\SonataExporterException;
interface WriterInterface
{
/**
* @throws SonataExporterException
*/
public function open();
/**
* @param array $data
* @throws SonataExporterException
*/
public function write(array $data);
public function close();
}
interface_exists(\Exporter\Writer\WriterInterface::class);
+15 -37
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -14,83 +16,64 @@ namespace Sonata\Exporter\Writer;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class XlsWriter implements TypedWriterInterface
final class XlsWriter implements TypedWriterInterface
{
/**
* @var string
*/
protected $filename;
private $filename;
/**
* @var resource
*/
protected $file;
private $file;
/**
* @var bool
*/
protected $showHeaders;
private $showHeaders;
/**
* @var int
*/
protected $position;
private $position = 0;
/**
* @param $filename
* @param bool $showHeaders
*
* @throws \RuntimeException
*/
public function __construct($filename, $showHeaders = true)
public function __construct(string $filename, bool $showHeaders = true)
{
$this->filename = $filename;
$this->showHeaders = $showHeaders;
$this->position = 0;
if (is_file($filename)) {
throw new \RuntimeException(sprintf('The file %s already exist', $filename));
throw new \RuntimeException(sprintf('The file %s already exists', $filename));
}
}
/**
* {@inheritdoc}
*/
final public function getDefaultMimeType()
public function getDefaultMimeType(): string
{
return 'application/vnd.ms-excel';
}
/**
* {@inheritdoc}
*/
final public function getFormat()
public function getFormat(): string
{
return 'xls';
}
/**
* {@inheritdoc}
*/
public function open()
public function open(): void
{
$this->file = fopen($this->filename, 'w', false);
fwrite($this->file, '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name=ProgId content=Excel.Sheet><meta name=Generator content="https://github.com/sonata-project/exporter"></head><body><table>');
}
/**
* {@inheritdoc}
*/
public function close()
public function close(): void
{
fwrite($this->file, '</table></body></html>');
fclose($this->file);
}
/**
* {@inheritdoc}
*/
public function write(array $data)
public function write(array $data): void
{
$this->init($data);
@@ -103,10 +86,7 @@ class XlsWriter implements TypedWriterInterface
++$this->position;
}
/**
* @param $data
*/
protected function init($data)
private function init(array $data): void
{
if ($this->position > 0) {
return;
@@ -122,5 +102,3 @@ class XlsWriter implements TypedWriterInterface
}
}
}
class_exists(\Exporter\Writer\XlsWriter::class);
+26 -39
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -16,48 +18,48 @@ namespace Sonata\Exporter\Writer;
*
* @author Vincent Touzet <vincent.touzet@gmail.com>
*/
class XmlExcelWriter implements WriterInterface
final class XmlExcelWriter implements WriterInterface
{
/**
* @var string|null
* @var string
*/
protected $filename = null;
private $filename;
/**
* @var resource|null
*/
protected $file = null;
private $file;
/**
* @var bool
*/
protected $showHeaders;
private $showHeaders;
/**
* @var mixed|null
*/
protected $columnsType = null;
private $columnsType;
/**
* @var int
*/
protected $position = 0;
private $position = 0;
/**
* @var string
*/
protected $header = '<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"><OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"></OfficeDocumentSettings><ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"></ExcelWorkbook><Worksheet ss:Name="Sheet 1"><Table>';
protected $footer = '</Table></Worksheet></Workbook>';
private $header = '<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"><OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"></OfficeDocumentSettings><ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"></ExcelWorkbook><Worksheet ss:Name="Sheet 1"><Table>';
private $footer = '</Table></Worksheet></Workbook>';
/**
* @param string $filename
* @param bool $showHeaders
* @param mixed $columnsType Define cells type to use
* If string: force all cells to the given type. e.g: 'Number'
* If array: force only given cells. e.g: array('ean'=>'String', 'price'=>'Number')
* If null: will guess the type. 'Number' if value is numeric, 'String' otherwise
* @param mixed $columnsType Define cells type to use
* If string: force all cells to the given type. e.g: 'Number'
* If array: force only given cells. e.g: array('ean'=>'String', 'price'=>'Number')
* If null: will guess the type. 'Number' if value is numeric, 'String' otherwise
*
* @throws \RuntimeException
*/
public function __construct($filename, $showHeaders = true, $columnsType = null)
public function __construct(string $filename, bool $showHeaders = true, $columnsType = null)
{
$this->filename = $filename;
$this->showHeaders = $showHeaders;
@@ -68,18 +70,15 @@ class XmlExcelWriter implements WriterInterface
}
}
public function open()
public function open(): void
{
$this->file = fopen($this->filename, 'w');
fwrite($this->file, $this->header);
}
/**
* @param array $data
*/
public function write(array $data)
public function write(array $data): void
{
if (0 == $this->position && $this->showHeaders) {
if (0 === $this->position && $this->showHeaders) {
$header = array_keys($data);
fwrite($this->file, $this->getXmlString($header));
++$this->position;
@@ -89,7 +88,7 @@ class XmlExcelWriter implements WriterInterface
++$this->position;
}
public function close()
public function close(): void
{
fwrite($this->file, $this->footer);
fclose($this->file);
@@ -97,12 +96,8 @@ class XmlExcelWriter implements WriterInterface
/**
* Prepare and return XML string for MS Excel XML from array.
*
* @param array $fields
*
* @return string
*/
private function getXmlString(array $fields = [])
private function getXmlString(array $fields = []): string
{
$xmlData = [];
$xmlData[] = '<Row>';
@@ -111,8 +106,8 @@ class XmlExcelWriter implements WriterInterface
$value = str_replace(["\r\n", "\r", "\n"], '&#10;', $value);
$dataType = 'String';
if (0 != $this->position || !$this->showHeaders) {
$dataType = $this->getDataType($key, $value);
if (0 !== $this->position || !$this->showHeaders) {
$dataType = $this->getDataType((string) $key, $value);
}
$xmlData[] = '<Cell><Data ss:Type="'.$dataType.'">'.$value.'</Data></Cell>';
}
@@ -121,13 +116,7 @@ class XmlExcelWriter implements WriterInterface
return implode('', $xmlData);
}
/**
* @param string $key
* @param string $value
*
* @return string
*/
private function getDataType($key, $value)
private function getDataType(string $key, string $value): string
{
$dataType = null;
if (null !== $this->columnsType) {
@@ -151,5 +140,3 @@ class XmlExcelWriter implements WriterInterface
return $dataType;
}
}
class_exists(\Exporter\Writer\XmlExcelWriter::class);
+21 -37
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
@@ -12,46 +14,44 @@
namespace Sonata\Exporter\Writer;
use Sonata\Exporter\Exception\InvalidDataFormatException;
use Sonata\Exporter\Exception\RuntimeException;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class XmlWriter implements TypedWriterInterface
final class XmlWriter implements TypedWriterInterface
{
/**
* @var string
*/
protected $filename;
private $filename;
/**
* @var resource
*/
protected $file;
private $file;
/**
* @var int
*/
protected $position;
private $position = 0;
/**
* @var string
*/
protected $mainElement;
private $mainElement;
/**
* @var string
*/
protected $childElement;
private $childElement;
/**
* @param string $filename
* @param string $mainElement
* @param string $childElement
* @throws \RuntimeException
*/
public function __construct($filename, $mainElement = 'datas', $childElement = 'data')
public function __construct(string $filename, string $mainElement = 'datas', string $childElement = 'data')
{
$this->filename = $filename;
$this->position = 0;
$this->mainElement = $mainElement;
$this->childElement = $childElement;
@@ -60,46 +60,31 @@ class XmlWriter implements TypedWriterInterface
}
}
/**
* {@inheritdoc}
*/
final public function getDefaultMimeType()
public function getDefaultMimeType(): string
{
return 'text/xml';
}
/**
* {@inheritdoc}
*/
final public function getFormat()
public function getFormat(): string
{
return 'xml';
}
/**
* {@inheritdoc}
*/
public function open()
public function open(): void
{
$this->file = fopen($this->filename, 'w', false);
fwrite($this->file, sprintf("<?xml version=\"1.0\" ?>\n<%s>\n", $this->mainElement));
}
/**
* {@inheritdoc}
*/
public function close()
public function close(): void
{
fwrite($this->file, sprintf('</%s>', $this->mainElement));
fclose($this->file);
}
/**
* {@inheritdoc}
*/
public function write(array $data)
public function write(array $data): void
{
fwrite($this->file, sprintf("<%s>\n", $this->childElement));
@@ -111,13 +96,14 @@ class XmlWriter implements TypedWriterInterface
}
/**
* @param string $name
* @param string $value
* @param mixed $value
*
* @throws \RuntimeException
*/
protected function generateNode($name, $value)
private function generateNode(string $name, $value): void
{
if (\is_array($value)) {
throw new \RuntimeException('Not implemented');
throw new RuntimeException('Not implemented');
} elseif (is_scalar($value) || null === $value) {
fwrite($this->file, sprintf("<%s><![CDATA[%s]]></%s>\n", $name, $value, $name));
} else {
@@ -125,5 +111,3 @@ class XmlWriter implements TypedWriterInterface
}
}
}
class_exists(\Exporter\Writer\XmlWriter::class);