vendor/sulu/sulu/src/Sulu/Bundle/MediaBundle/DependencyInjection/Configuration.php line 201

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\MediaBundle\DependencyInjection;
  11. use League\Flysystem\AwsS3v3\AwsS3Adapter;
  12. use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
  13. use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter;
  14. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  15. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  16. use Symfony\Component\Config\Definition\ConfigurationInterface;
  17. class Configuration implements ConfigurationInterface
  18. {
  19.     public const STORAGE_GOOGLE_CLOUD 'google_cloud';
  20.     public const STORAGE_S3 's3';
  21.     public const STORAGE_AZURE_BLOB 'azure_blob';
  22.     public function getConfigTreeBuilder()
  23.     {
  24.         $treeBuilder = new TreeBuilder('sulu_media');
  25.         $rootNode $treeBuilder->getRootNode();
  26.         $rootNode->children()
  27.             ->scalarNode('adobe_creative_key')->defaultNull()->end()
  28.             ->scalarNode('adapter')
  29.                 ->defaultValue('auto')
  30.             ->end()
  31.             ->arrayNode('image_format_files')
  32.                 ->prototype('scalar')->end()
  33.             ->end()
  34.             ->arrayNode('system_collections')
  35.                 ->useAttributeAsKey('key')
  36.                 ->prototype('array')
  37.                     ->children()
  38.                         ->arrayNode('meta_title')
  39.                             ->prototype('scalar')->end()
  40.                         ->end()
  41.                         ->arrayNode('collections')
  42.                             ->useAttributeAsKey('key')
  43.                                 ->prototype('array')
  44.                                 ->children()
  45.                                     ->arrayNode('meta_title')
  46.                                         ->prototype('scalar')->end()
  47.                                     ->end()
  48.                                 ->end()
  49.                             ->end()
  50.                         ->end()
  51.                     ->end()
  52.                 ->end()
  53.             ->end()
  54.             ->arrayNode('search')
  55.                 ->addDefaultsIfNotSet()
  56.                 ->children()
  57.                     ->scalarNode('default_image_format')->defaultValue('sulu-100x100')->end()
  58.                     ->booleanNode('enabled')->info(
  59.                         'Enable integration with SuluMediaBundle'
  60.                     )->defaultValue(false)->end()
  61.                 ->end()
  62.             ->end()
  63.             ->arrayNode('ghost_script')
  64.                 ->addDefaultsIfNotSet()
  65.                 ->children()
  66.                      ->scalarNode('path')->defaultValue('gs')->end()
  67.                 ->end()
  68.             ->end()
  69.             ->arrayNode('upload')
  70.                 ->addDefaultsIfNotSet()
  71.                 ->children()
  72.                     ->integerNode('max_filesize')
  73.                         ->defaultValue(256)
  74.                         ->min(0)
  75.                     ->end()
  76.                     ->arrayNode('blocked_file_types')
  77.                         ->prototype('scalar')->end()
  78.                         ->defaultValue([])
  79.                     ->end()
  80.                 ->end()
  81.             ->end()
  82.             ->arrayNode('format_manager')
  83.                 ->addDefaultsIfNotSet()
  84.                 ->children()
  85.                     ->arrayNode('response_headers')
  86.                         ->prototype('scalar')->end()->defaultValue([
  87.                             'Expires' => '+1 month',
  88.                             'Pragma' => 'public',
  89.                             'Cache-Control' => 'public',
  90.                         ])
  91.                     ->end()
  92.                     ->arrayNode('default_imagine_options')
  93.                         ->prototype('scalar')->end()
  94.                     ->end()
  95.                     ->arrayNode('blocked_file_types')
  96.                         ->setDeprecated('The configuration "sulu_media.format_manager.blocked_file_types" is deprecated. Use "sulu_media.upload.blocked_file_types" instead.')
  97.                         ->prototype('scalar')->end()
  98.                         ->defaultValue([])
  99.                     ->end()
  100.                     ->arrayNode('mime_types')
  101.                         ->prototype('scalar')->end()
  102.                     ->end()
  103.                     ->arrayNode('types')
  104.                         ->prototype('array')
  105.                             ->children()
  106.                                 ->scalarNode('type')->cannotBeEmpty()->isRequired()->end()
  107.                                 ->arrayNode('mimeTypes')->requiresAtLeastOneElement()
  108.                                     ->prototype('scalar')->end()
  109.                                 ->end()
  110.                             ->end()
  111.                         ->end()->defaultValue([
  112.                             [
  113.                                 'type' => 'document',
  114.                                 'mimeTypes' => ['*'],
  115.                             ],
  116.                             [
  117.                                 'type' => 'image',
  118.                                 'mimeTypes' => ['image/*'],
  119.                             ],
  120.                             [
  121.                                 'type' => 'video',
  122.                                 'mimeTypes' => ['video/*'],
  123.                             ],
  124.                             [
  125.                                 'type' => 'audio',
  126.                                 'mimeTypes' => ['audio/*'],
  127.                             ],
  128.                         ])
  129.                     ->end()
  130.                 ->end()
  131.             ->end()
  132.             ->arrayNode('format_cache')
  133.                 ->addDefaultsIfNotSet()
  134.                 ->children()
  135.                     ->scalarNode('path')->defaultValue('%kernel.project_dir%/public/uploads/media')->end()
  136.                     ->booleanNode('save_image')->defaultValue(true)->end()
  137.                     ->scalarNode('segments')->defaultValue(10)->end()
  138.                 ->end()
  139.             ->end()
  140.             ->arrayNode('disposition_type')
  141.                 ->addDefaultsIfNotSet()
  142.                 ->children()
  143.                     ->enumNode('default')->values(['inline''attachment'])->defaultValue('attachment')->end()
  144.                     ->arrayNode('mime_types_inline')
  145.                         ->prototype('scalar')->end()
  146.                     ->end()
  147.                     ->arrayNode('mime_types_attachment')
  148.                         ->prototype('scalar')->end()
  149.                     ->end()
  150.                 ->end()
  151.             ->end()
  152.             ->arrayNode('routing')
  153.                 ->addDefaultsIfNotSet()
  154.                 ->children()
  155.                     ->scalarNode('media_proxy_path')->defaultValue('/uploads/media/{slug}')->end()
  156.                     ->scalarNode('media_download_path')->defaultValue('/media/{id}/download/{slug}')->end()
  157.                     ->scalarNode('media_download_path_admin')->defaultValue('/admin/media/{id}/download/{slug}')->end()
  158.                 ->end()
  159.             ->end()
  160.             ->arrayNode('ffmpeg')
  161.                 ->children()
  162.                     ->scalarNode('ffmpeg_binary')
  163.                         ->isRequired()
  164.                     ->end()
  165.                     ->scalarNode('ffprobe_binary')
  166.                         ->isRequired()
  167.                     ->end()
  168.                     ->scalarNode('binary_timeout')->defaultValue(60)->end()
  169.                     ->scalarNode('threads_count')->defaultValue(4)->end()
  170.                 ->end()
  171.             ->end();
  172.         $this->addObjectsSection($rootNode);
  173.         $this->addStorageSection($rootNode);
  174.         return $treeBuilder;
  175.     }
  176.     private function addStorageSection(ArrayNodeDefinition $node)
  177.     {
  178.         $storages = ['local'];
  179.         $storagesNode $node->children()
  180.             ->arrayNode('storages')
  181.                 ->addDefaultsIfNotSet()
  182.                 ->children()
  183.                     ->arrayNode('local')
  184.                         ->addDefaultsIfNotSet()
  185.                         ->children()
  186.                             ->scalarNode('path')->defaultValue('%kernel.project_dir%/var/uploads/media')->end()
  187.                             ->scalarNode('segments')->defaultValue(10)->end()
  188.                         ->end()
  189.                     ->end();
  190.         if (\class_exists(GoogleStorageAdapter::class)) {
  191.             $storages[] = self::STORAGE_GOOGLE_CLOUD;
  192.             $storagesNode
  193.                 ->arrayNode(self::STORAGE_GOOGLE_CLOUD)
  194.                     ->addDefaultsIfNotSet()
  195.                     ->children()
  196.                         ->scalarNode('key_file_path')->isRequired()->end()
  197.                         ->scalarNode('bucket_name')->isRequired()->end()
  198.                         ->scalarNode('path_prefix')->defaultNull()->end()
  199.                         ->scalarNode('segments')->defaultValue(10)->end()
  200.                     ->end()
  201.                 ->end();
  202.         }
  203.         if (\class_exists(AwsS3Adapter::class)) {
  204.             $storages[] = self::STORAGE_S3;
  205.             $storagesNode
  206.                 ->arrayNode(self::STORAGE_S3)
  207.                     ->addDefaultsIfNotSet()
  208.                     ->children()
  209.                         ->scalarNode('key')->isRequired()->end()
  210.                         ->scalarNode('secret')->isRequired()->end()
  211.                         ->scalarNode('region')->isRequired()->end()
  212.                         ->scalarNode('bucket_name')->isRequired()->end()
  213.                         ->scalarNode('path_prefix')->defaultNull()->end()
  214.                         ->scalarNode('version')->defaultValue('latest')->end()
  215.                         ->scalarNode('endpoint')->defaultNull()->end()
  216.                         ->scalarNode('segments')->defaultValue(10)->end()
  217.                         ->arrayNode('arguments')
  218.                             ->scalarPrototype()->end()
  219.                         ->end()
  220.                     ->end()
  221.                 ->end();
  222.         }
  223.         if (\class_exists(AzureBlobStorageAdapter::class)) {
  224.             $storages[] = self::STORAGE_AZURE_BLOB;
  225.             $storagesNode
  226.                 ->arrayNode(self::STORAGE_AZURE_BLOB)
  227.                     ->addDefaultsIfNotSet()
  228.                     ->children()
  229.                         ->scalarNode('connection_string')->isRequired()->end()
  230.                         ->scalarNode('container_name')->isRequired()->end()
  231.                         ->scalarNode('path_prefix')->defaultNull()->end()
  232.                         ->scalarNode('segments')->defaultValue(10)->end()
  233.                     ->end()
  234.                 ->end();
  235.         }
  236.         $node->children()
  237.                 ->scalarNode('storage')->defaultValue('local')->end()
  238.             ->end();
  239.     }
  240.     /**
  241.      * Adds `objects` section.
  242.      */
  243.     private function addObjectsSection(ArrayNodeDefinition $node)
  244.     {
  245.         $node
  246.             ->children()
  247.                 ->arrayNode('objects')
  248.                     ->addDefaultsIfNotSet()
  249.                     ->children()
  250.                         ->arrayNode('media')
  251.                             ->addDefaultsIfNotSet()
  252.                             ->children()
  253.                                 ->scalarNode('model')
  254.                                     ->defaultValue('Sulu\Bundle\MediaBundle\Entity\Media')
  255.                                 ->end()
  256.                                 ->scalarNode('repository')
  257.                                     ->defaultValue('Sulu\Bundle\MediaBundle\Entity\MediaRepository')
  258.                                 ->end()
  259.                             ->end()
  260.                         ->end()
  261.                     ->end()
  262.                 ->end()
  263.             ->end();
  264.     }
  265. }