Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
<?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 Sonata\Exporter\Bridge\Symfony\Bundle;
use Sonata\Exporter\Bridge\Symfony\DependencyInjection\Compiler\ExporterCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
final class SonataExporterBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new ExporterCompilerPass());
}
/**
* {@inheritdoc}
*/
protected function getContainerExtensionClass()
{
return 'Exporter\Bridge\Symfony\DependencyInjection\SonataExporterExtension';
}
}
class_exists(\Exporter\Bridge\Symfony\Bundle\SonataExporterBundle::class);

View File

@@ -0,0 +1,41 @@
<?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 Sonata\Exporter\Bridge\Symfony\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* @author Grégoire Paris <postmaster@greg0ire.fr>
*/
final class ExporterCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('sonata.exporter.exporter')) {
return;
}
$definition = $container->findDefinition('sonata.exporter.exporter');
$writers = $container->findTaggedServiceIds('sonata.exporter.writer');
foreach (array_keys($writers) as $id) {
$definition->addMethodCall('addWriter', [new Reference($id)]);
}
}
}
class_exists(\Exporter\Bridge\Symfony\DependencyInjection\Compiler\ExporterCompilerPass::class);

View File

@@ -0,0 +1,127 @@
<?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 Sonata\Exporter\Bridge\Symfony\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files.
*
* @author Grégoire Paris <postmaster@greg0ire.fr>
*/
final class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('sonata_exporter');
$rootNode
->children()
->arrayNode('exporter')
->addDefaultsIfNotSet()
->children()
->arrayNode('default_writers')
->defaultValue(['csv', 'json', 'xls', 'xml'])
->prototype('scalar')->end()
->end()
->end()
->end()
->arrayNode('writers')
->addDefaultsIfNotSet()
->children()
->arrayNode('csv')
->addDefaultsIfNotSet()
->children()
->scalarNode('filename')
->defaultValue('php://output')
->info('path to the output file')
->end()
->scalarNode('delimiter')
->defaultValue(',')
->info('delimits csv values')
->end()
->scalarNode('enclosure')
->defaultValue('"')
->info('will be used when a value contains the delimiter')
->end()
->scalarNode('escape')
->defaultValue('\\')
->info('will be used when a value contains the enclosure')
->end()
->booleanNode('show_headers')
->defaultValue(true)
->info('add column names as the first line')
->end()
->booleanNode('with_bom')
->defaultValue(false)
->info('include the byte order mark')
->end()
->end()
->end()
->arrayNode('json')
->addDefaultsIfNotSet()
->children()
->scalarNode('filename')
->defaultValue('php://output')
->info('path to the output file')
->end()
->end()
->end()
->arrayNode('xls')
->addDefaultsIfNotSet()
->children()
->scalarNode('filename')
->defaultValue('php://output')
->info('path to the output file')
->end()
->booleanNode('show_headers')
->defaultValue(true)
->info('add column names as the first line')
->end()
->end()
->end()
->arrayNode('xml')
->addDefaultsIfNotSet()
->children()
->scalarNode('filename')
->defaultValue('php://output')
->info('path to the output file')
->end()
->booleanNode('show_headers')
->defaultValue(true)
->info('add column names as the first line')
->end()
->scalarNode('main_element')
->defaultValue('datas')
->info('name of the wrapping element')
->end()
->scalarNode('child_element')
->defaultValue('data')
->info('name of elements corresponding to rows')
->end()
->end()
->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
}
class_exists(\Exporter\Bridge\Symfony\DependencyInjection\Configuration::class);

View File

@@ -0,0 +1,66 @@
<?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 Sonata\Exporter\Bridge\Symfony\DependencyInjection;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
/**
* @author Grégoire Paris <postmaster@greg0ire.fr>
*/
final class SonataExporterExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
$this->configureExporter($container, $config['exporter']);
$this->configureWriters($container, $config['writers']);
}
private function configureExporter(ContainerBuilder $container, array $config)
{
foreach (['csv', 'json', 'xls', 'xml'] as $format) {
if (\in_array($format, $config['default_writers'])) {
$container->getDefinition('sonata.exporter.writer.'.$format)->addTag(
'sonata.exporter.writer'
);
}
}
}
private function configureWriters(ContainerBuilder $container, array $config)
{
foreach ($config as $format => $settings) {
foreach ($settings as $key => $value) {
$container->setParameter(sprintf(
'sonata.exporter.writer.%s.%s',
$format,
$key
), $value);
}
}
}
}
class_exists(\Exporter\Bridge\Symfony\DependencyInjection\SonataExporterExtension::class);

View File

@@ -0,0 +1,27 @@
<?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">
<argument>%sonata.exporter.writer.csv.filename%</argument>
<argument>%sonata.exporter.writer.csv.delimiter%</argument>
<argument>%sonata.exporter.writer.csv.enclosure%</argument>
<argument>%sonata.exporter.writer.csv.escape%</argument>
<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">
<argument>%sonata.exporter.writer.json.filename%</argument>
</service>
<service id="sonata.exporter.writer.xls" class="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">
<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"/>
</services>
</container>