Complex classes like SonataMediaExtension often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SonataMediaExtension, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class SonataMediaExtension extends Extension implements PrependExtensionInterface |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | private $bundleConfigs; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritdoc} |
||
| 36 | */ |
||
| 37 | public function load(array $configs, ContainerBuilder $container) |
||
| 38 | { |
||
| 39 | $processor = new Processor(); |
||
| 40 | $configuration = new Configuration(); |
||
| 41 | $config = $processor->processConfiguration($configuration, $configs); |
||
| 42 | |||
| 43 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
||
| 44 | $loader->load('provider.xml'); |
||
| 45 | $loader->load('media.xml'); |
||
| 46 | $loader->load('twig.xml'); |
||
| 47 | $loader->load('security.xml'); |
||
| 48 | $loader->load('extra.xml'); |
||
| 49 | $loader->load('form.xml'); |
||
| 50 | $loader->load('gaufrette.xml'); |
||
| 51 | $loader->load('validators.xml'); |
||
| 52 | $loader->load('serializer.xml'); |
||
| 53 | |||
| 54 | if (!in_array(strtolower($config['db_driver']), array('doctrine_orm', 'doctrine_mongodb', 'doctrine_phpcr'))) { |
||
| 55 | throw new \InvalidArgumentException(sprintf('SonataMediaBundle - Invalid db driver "%s".', $config['db_driver'])); |
||
| 56 | } |
||
| 57 | |||
| 58 | $bundles = $container->getParameter('kernel.bundles'); |
||
| 59 | |||
| 60 | if (isset($bundles['FOSRestBundle']) && isset($bundles['NelmioApiDocBundle'])) { |
||
| 61 | $loader->load(sprintf('api_form_%s.xml', $config['db_driver'])); |
||
| 62 | |||
| 63 | if ('doctrine_orm' == $config['db_driver']) { |
||
| 64 | $loader->load('api_controllers.xml'); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if (isset($bundles['SonataNotificationBundle'])) { |
||
| 69 | $loader->load('consumer.xml'); |
||
| 70 | } |
||
| 71 | |||
| 72 | if (isset($bundles['SonataFormatterBundle'])) { |
||
| 73 | $loader->load('formatter.xml'); |
||
| 74 | } |
||
| 75 | |||
| 76 | if (isset($bundles['SonataBlockBundle'])) { |
||
| 77 | $loader->load('block.xml'); |
||
| 78 | } |
||
| 79 | |||
| 80 | if (isset($bundles['SonataSeoBundle'])) { |
||
| 81 | $loader->load('seo_block.xml'); |
||
| 82 | } |
||
| 83 | |||
| 84 | if (!isset($bundles['LiipImagineBundle'])) { |
||
| 85 | $container->removeDefinition('sonata.media.thumbnail.liip_imagine'); |
||
| 86 | } |
||
| 87 | |||
| 88 | if ($this->isClassificationEnabled($config)) { |
||
| 89 | $loader->load('category.xml'); |
||
| 90 | $container->setAlias('sonata.media.manager.category', $config['category_manager']); |
||
| 91 | } |
||
| 92 | |||
| 93 | if (!array_key_exists($config['default_context'], $config['contexts'])) { |
||
| 94 | throw new \InvalidArgumentException(sprintf('SonataMediaBundle - Invalid default context : %s, available : %s', $config['default_context'], json_encode(array_keys($config['contexts'])))); |
||
| 95 | } |
||
| 96 | |||
| 97 | $loader->load(sprintf('%s.xml', $config['db_driver'])); |
||
| 98 | |||
| 99 | if (isset($bundles['SonataAdminBundle'])) { |
||
| 100 | $loader->load(sprintf('%s_admin.xml', $config['db_driver'])); |
||
| 101 | |||
| 102 | $sonataAdminConfig = $this->bundleConfigs['SonataAdminBundle']; |
||
| 103 | |||
| 104 | $sonataRoles = array(); |
||
| 105 | if (isset($sonataAdminConfig['security']['role_admin'])) { |
||
| 106 | $sonataRoles[] = $sonataAdminConfig['security']['role_admin']; |
||
| 107 | } else { |
||
| 108 | $sonataRoles[] = 'ROLE_ADMIN'; |
||
| 109 | } |
||
| 110 | |||
| 111 | if (isset($sonataAdminConfig['security']['role_super_admin'])) { |
||
| 112 | $sonataRoles[] = $sonataAdminConfig['security']['role_super_admin']; |
||
| 113 | } else { |
||
| 114 | $sonataRoles[] = 'ROLE_SUPER_ADMIN'; |
||
| 115 | } |
||
| 116 | |||
| 117 | $container->getDefinition('sonata.media.security.superadmin_strategy') |
||
| 118 | ->replaceArgument(2, $sonataRoles); |
||
| 119 | } |
||
| 120 | |||
| 121 | $this->configureFilesystemAdapter($container, $config); |
||
| 122 | $this->configureCdnAdapter($container, $config); |
||
| 123 | |||
| 124 | $pool = $container->getDefinition('sonata.media.pool'); |
||
| 125 | $pool->replaceArgument(0, $config['default_context']); |
||
| 126 | |||
| 127 | $strategies = array(); |
||
| 128 | |||
| 129 | foreach ($config['contexts'] as $name => $settings) { |
||
| 130 | $formats = array(); |
||
| 131 | |||
| 132 | foreach ($settings['formats'] as $format => $value) { |
||
| 133 | $formats[$name.'_'.$format] = $value; |
||
| 134 | } |
||
| 135 | |||
| 136 | $strategies[] = $settings['download']['strategy']; |
||
| 137 | $pool->addMethodCall('addContext', array($name, $settings['providers'], $formats, $settings['download'])); |
||
| 138 | } |
||
| 139 | |||
| 140 | $container->setParameter('sonata.media.admin_format', $config['admin_format']); |
||
| 141 | |||
| 142 | $strategies = array_unique($strategies); |
||
| 143 | |||
| 144 | foreach ($strategies as $strategyId) { |
||
| 145 | $pool->addMethodCall('addDownloadStrategy', array($strategyId, new Reference($strategyId))); |
||
| 146 | } |
||
| 147 | |||
| 148 | if ('doctrine_orm' == $config['db_driver']) { |
||
| 149 | $this->registerDoctrineMapping($config); |
||
| 150 | } |
||
| 151 | |||
| 152 | $container->setParameter('sonata.media.resizer.simple.adapter.mode', $config['resizer']['simple']['mode']); |
||
| 153 | $container->setParameter('sonata.media.resizer.square.adapter.mode', $config['resizer']['square']['mode']); |
||
| 154 | |||
| 155 | $this->configureParameterClass($container, $config); |
||
| 156 | $this->configureExtra($container, $config); |
||
| 157 | $this->configureBuzz($container, $config); |
||
| 158 | $this->configureProviders($container, $config); |
||
| 159 | $this->configureAdapters($container, $config); |
||
| 160 | $this->configureResizers($container, $config); |
||
| 161 | $this->configureClassesToCompile(); |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param ContainerBuilder $container |
||
| 166 | * @param array $config |
||
| 167 | */ |
||
| 168 | public function configureProviders(ContainerBuilder $container, array $config) |
||
| 169 | { |
||
| 170 | $container->getDefinition('sonata.media.provider.image') |
||
| 171 | ->replaceArgument(5, array_map('strtolower', $config['providers']['image']['allowed_extensions'])) |
||
| 172 | ->replaceArgument(6, $config['providers']['image']['allowed_mime_types']) |
||
| 173 | ->replaceArgument(7, new Reference($config['providers']['image']['adapter'])) |
||
| 174 | ; |
||
| 175 | |||
| 176 | $container->getDefinition('sonata.media.provider.file') |
||
| 177 | ->replaceArgument(5, $config['providers']['file']['allowed_extensions']) |
||
| 178 | ->replaceArgument(6, $config['providers']['file']['allowed_mime_types']) |
||
| 179 | ; |
||
| 180 | |||
| 181 | $container->getDefinition('sonata.media.provider.youtube')->replaceArgument(7, $config['providers']['youtube']['html5']); |
||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @param ContainerBuilder $container |
||
| 186 | * @param array $config |
||
| 187 | */ |
||
| 188 | public function configureBuzz(ContainerBuilder $container, array $config) |
||
| 189 | { |
||
| 190 | $container->getDefinition('sonata.media.buzz.browser') |
||
| 191 | ->replaceArgument(0, new Reference($config['buzz']['connector'])); |
||
| 192 | |||
| 193 | foreach (array( |
||
| 194 | 'sonata.media.buzz.connector.curl', |
||
| 195 | 'sonata.media.buzz.connector.file_get_contents', |
||
| 196 | ) as $connector) { |
||
| 197 | $container->getDefinition($connector) |
||
| 198 | ->addMethodCall('setIgnoreErrors', array($config['buzz']['client']['ignore_errors'])) |
||
| 199 | ->addMethodCall('setMaxRedirects', array($config['buzz']['client']['max_redirects'])) |
||
| 200 | ->addMethodCall('setTimeout', array($config['buzz']['client']['timeout'])) |
||
| 201 | ->addMethodCall('setVerifyPeer', array($config['buzz']['client']['verify_peer'])) |
||
| 202 | ->addMethodCall('setProxy', array($config['buzz']['client']['proxy'])); |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @param ContainerBuilder $container |
||
| 208 | * @param array $config |
||
| 209 | */ |
||
| 210 | public function configureParameterClass(ContainerBuilder $container, array $config) |
||
| 211 | { |
||
| 212 | $container->setParameter('sonata.media.admin.media.entity', $config['class']['media']); |
||
| 213 | $container->setParameter('sonata.media.admin.gallery.entity', $config['class']['gallery']); |
||
| 214 | $container->setParameter('sonata.media.admin.gallery_item.entity', $config['class']['gallery_item']); |
||
| 215 | |||
| 216 | $container->setParameter('sonata.media.media.class', $config['class']['media']); |
||
| 217 | $container->setParameter('sonata.media.gallery.class', $config['class']['gallery']); |
||
| 218 | |||
| 219 | $container->getDefinition('sonata.media.form.type.media')->replaceArgument(1, $config['class']['media']); |
||
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @param array $config |
||
| 224 | */ |
||
| 225 | public function registerDoctrineMapping(array $config) |
||
| 226 | { |
||
| 227 | $collector = DoctrineCollector::getInstance(); |
||
| 228 | |||
| 229 | $collector->addAssociation($config['class']['media'], 'mapOneToMany', array( |
||
| 230 | 'fieldName' => 'galleryItems', |
||
| 231 | 'targetEntity' => $config['class']['gallery_item'], |
||
| 232 | 'cascade' => array( |
||
| 233 | 'persist', |
||
| 234 | ), |
||
| 235 | 'mappedBy' => 'media', |
||
| 236 | 'orphanRemoval' => false, |
||
| 237 | )); |
||
| 238 | |||
| 239 | $collector->addAssociation($config['class']['gallery_item'], 'mapManyToOne', array( |
||
| 240 | 'fieldName' => 'gallery', |
||
| 241 | 'targetEntity' => $config['class']['gallery'], |
||
| 242 | 'cascade' => array( |
||
| 243 | 'persist', |
||
| 244 | ), |
||
| 245 | 'mappedBy' => null, |
||
| 246 | 'inversedBy' => 'galleryItems', |
||
| 247 | 'joinColumns' => array( |
||
| 248 | array( |
||
| 249 | 'name' => 'gallery_id', |
||
| 250 | 'referencedColumnName' => 'id', |
||
| 251 | 'onDelete' => 'CASCADE', |
||
| 252 | ), |
||
| 253 | ), |
||
| 254 | 'orphanRemoval' => false, |
||
| 255 | )); |
||
| 256 | |||
| 257 | $collector->addAssociation($config['class']['gallery_item'], 'mapManyToOne', array( |
||
| 258 | 'fieldName' => 'media', |
||
| 259 | 'targetEntity' => $config['class']['media'], |
||
| 260 | 'cascade' => array( |
||
| 261 | 'persist', |
||
| 262 | ), |
||
| 263 | 'mappedBy' => null, |
||
| 264 | 'inversedBy' => 'galleryItems', |
||
| 265 | 'joinColumns' => array( |
||
| 266 | array( |
||
| 267 | 'name' => 'media_id', |
||
| 268 | 'referencedColumnName' => 'id', |
||
| 269 | 'onDelete' => 'CASCADE', |
||
| 270 | ), |
||
| 271 | ), |
||
| 272 | 'orphanRemoval' => false, |
||
| 273 | )); |
||
| 274 | |||
| 275 | $collector->addAssociation($config['class']['gallery'], 'mapOneToMany', array( |
||
| 276 | 'fieldName' => 'galleryItems', |
||
| 277 | 'targetEntity' => $config['class']['gallery_item'], |
||
| 278 | 'cascade' => array( |
||
| 279 | 'persist', |
||
| 280 | ), |
||
| 281 | 'mappedBy' => 'gallery', |
||
| 282 | 'orphanRemoval' => true, |
||
| 283 | 'orderBy' => array( |
||
| 284 | 'position' => 'ASC', |
||
| 285 | ), |
||
| 286 | )); |
||
| 287 | |||
| 288 | if ($this->isClassificationEnabled($config)) { |
||
| 289 | $collector->addAssociation($config['class']['media'], 'mapManyToOne', array( |
||
| 290 | 'fieldName' => 'category', |
||
| 291 | 'targetEntity' => $config['class']['category'], |
||
| 292 | 'cascade' => array( |
||
| 293 | 'persist', |
||
| 294 | ), |
||
| 295 | 'mappedBy' => null, |
||
| 296 | 'inversedBy' => null, |
||
| 297 | 'joinColumns' => array( |
||
| 298 | array( |
||
| 299 | 'name' => 'category_id', |
||
| 300 | 'referencedColumnName' => 'id', |
||
| 301 | 'onDelete' => 'SET NULL', |
||
| 302 | ), |
||
| 303 | ), |
||
| 304 | 'orphanRemoval' => false, |
||
| 305 | )); |
||
| 306 | } |
||
| 307 | } |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Inject CDN dependency to default provider. |
||
| 311 | * |
||
| 312 | * @param ContainerBuilder $container |
||
| 313 | * @param array $config |
||
| 314 | */ |
||
| 315 | public function configureCdnAdapter(ContainerBuilder $container, array $config) |
||
| 316 | { |
||
| 317 | // add the default configuration for the server cdn |
||
| 318 | if ($container->hasDefinition('sonata.media.cdn.server') && isset($config['cdn']['server'])) { |
||
| 319 | $container->getDefinition('sonata.media.cdn.server') |
||
| 320 | ->replaceArgument(0, $config['cdn']['server']['path']) |
||
| 321 | ; |
||
| 322 | } else { |
||
| 323 | $container->removeDefinition('sonata.media.cdn.server'); |
||
| 324 | } |
||
| 325 | |||
| 326 | if ($container->hasDefinition('sonata.media.cdn.panther') && isset($config['cdn']['panther'])) { |
||
| 327 | $container->getDefinition('sonata.media.cdn.panther') |
||
| 328 | ->replaceArgument(0, $config['cdn']['panther']['path']) |
||
| 329 | ->replaceArgument(1, $config['cdn']['panther']['username']) |
||
| 330 | ->replaceArgument(2, $config['cdn']['panther']['password']) |
||
| 331 | ->replaceArgument(3, $config['cdn']['panther']['site_id']) |
||
| 332 | ; |
||
| 333 | } else { |
||
| 334 | $container->removeDefinition('sonata.media.cdn.panther'); |
||
| 335 | } |
||
| 336 | |||
| 337 | if ($container->hasDefinition('sonata.media.cdn.cloudfront') && isset($config['cdn']['cloudfront'])) { |
||
| 338 | $container->getDefinition('sonata.media.cdn.cloudfront') |
||
| 339 | ->replaceArgument(0, $config['cdn']['cloudfront']['path']) |
||
| 340 | ->replaceArgument(1, $config['cdn']['cloudfront']['key']) |
||
| 341 | ->replaceArgument(2, $config['cdn']['cloudfront']['secret']) |
||
| 342 | ->replaceArgument(3, $config['cdn']['cloudfront']['distribution_id']) |
||
| 343 | ; |
||
| 344 | } else { |
||
| 345 | $container->removeDefinition('sonata.media.cdn.cloudfront'); |
||
| 346 | } |
||
| 347 | |||
| 348 | if ($container->hasDefinition('sonata.media.cdn.fallback') && isset($config['cdn']['fallback'])) { |
||
| 349 | $container->getDefinition('sonata.media.cdn.fallback') |
||
| 350 | ->replaceArgument(0, new Reference($config['cdn']['fallback']['master'])) |
||
| 351 | ->replaceArgument(1, new Reference($config['cdn']['fallback']['fallback'])) |
||
| 352 | ; |
||
| 353 | } else { |
||
| 354 | $container->removeDefinition('sonata.media.cdn.fallback'); |
||
| 355 | } |
||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Inject filesystem dependency to default provider. |
||
| 360 | * |
||
| 361 | * @param ContainerBuilder $container |
||
| 362 | * @param array $config |
||
| 363 | */ |
||
| 364 | public function configureFilesystemAdapter(ContainerBuilder $container, array $config) |
||
| 365 | { |
||
| 366 | // add the default configuration for the local filesystem |
||
| 367 | if ($container->hasDefinition('sonata.media.adapter.filesystem.local') && isset($config['filesystem']['local'])) { |
||
| 368 | $container->getDefinition('sonata.media.adapter.filesystem.local') |
||
| 369 | ->addArgument($config['filesystem']['local']['directory']) |
||
| 370 | ->addArgument($config['filesystem']['local']['create']) |
||
| 371 | ; |
||
| 372 | } else { |
||
| 373 | $container->removeDefinition('sonata.media.adapter.filesystem.local'); |
||
| 374 | } |
||
| 375 | |||
| 376 | // add the default configuration for the FTP filesystem |
||
| 377 | if ($container->hasDefinition('sonata.media.adapter.filesystem.ftp') && isset($config['filesystem']['ftp'])) { |
||
| 378 | $container->getDefinition('sonata.media.adapter.filesystem.ftp') |
||
| 379 | ->addArgument($config['filesystem']['ftp']['directory']) |
||
| 380 | ->addArgument($config['filesystem']['ftp']['host']) |
||
| 381 | ->addArgument(array( |
||
| 382 | 'port' => $config['filesystem']['ftp']['port'], |
||
| 383 | 'username' => $config['filesystem']['ftp']['username'], |
||
| 384 | 'password' => $config['filesystem']['ftp']['password'], |
||
| 385 | 'passive' => $config['filesystem']['ftp']['passive'], |
||
| 386 | 'create' => $config['filesystem']['ftp']['create'], |
||
| 387 | 'mode' => $config['filesystem']['ftp']['mode'], |
||
| 388 | )) |
||
| 389 | ; |
||
| 390 | } else { |
||
| 391 | $container->removeDefinition('sonata.media.adapter.filesystem.ftp'); |
||
| 392 | $container->removeDefinition('sonata.media.filesystem.ftp'); |
||
| 393 | } |
||
| 394 | |||
| 395 | // add the default configuration for the S3 filesystem |
||
| 396 | if ($container->hasDefinition('sonata.media.adapter.filesystem.s3') && isset($config['filesystem']['s3'])) { |
||
| 397 | $container->getDefinition('sonata.media.adapter.filesystem.s3') |
||
| 398 | ->replaceArgument(0, new Reference('sonata.media.adapter.service.s3')) |
||
| 399 | ->replaceArgument(1, $config['filesystem']['s3']['bucket']) |
||
| 400 | ->replaceArgument(2, array('create' => $config['filesystem']['s3']['create'], 'region' => $config['filesystem']['s3']['region'], 'directory' => $config['filesystem']['s3']['directory'], 'ACL' => $config['filesystem']['s3']['acl'])) |
||
| 401 | ; |
||
| 402 | |||
| 403 | $container->getDefinition('sonata.media.metadata.amazon') |
||
| 404 | ->addArgument(array( |
||
| 405 | 'acl' => $config['filesystem']['s3']['acl'], |
||
| 406 | 'storage' => $config['filesystem']['s3']['storage'], |
||
| 407 | 'encryption' => $config['filesystem']['s3']['encryption'], |
||
| 408 | 'meta' => $config['filesystem']['s3']['meta'], |
||
| 409 | 'cache_control' => $config['filesystem']['s3']['cache_control'], |
||
| 410 | )) |
||
| 411 | ; |
||
| 412 | |||
| 413 | if (3 === $config['filesystem']['s3']['sdk_version']) { |
||
| 414 | $container->getDefinition('sonata.media.adapter.service.s3') |
||
| 415 | ->replaceArgument(0, array( |
||
| 416 | 'credentials' => array( |
||
| 417 | 'secret' => $config['filesystem']['s3']['secretKey'], |
||
| 418 | 'key' => $config['filesystem']['s3']['accessKey'], |
||
| 419 | ), |
||
| 420 | 'region' => $config['filesystem']['s3']['region'], |
||
| 421 | 'version' => $config['filesystem']['s3']['version'], |
||
| 422 | )) |
||
| 423 | ; |
||
| 424 | } else { |
||
| 425 | $container->getDefinition('sonata.media.adapter.service.s3') |
||
| 426 | ->replaceArgument(0, array( |
||
| 427 | 'secret' => $config['filesystem']['s3']['secretKey'], |
||
| 428 | 'key' => $config['filesystem']['s3']['accessKey'], |
||
| 429 | )) |
||
| 430 | ; |
||
| 431 | } |
||
| 432 | } else { |
||
| 433 | $container->removeDefinition('sonata.media.adapter.filesystem.s3'); |
||
| 434 | $container->removeDefinition('sonata.media.filesystem.s3'); |
||
| 435 | } |
||
| 436 | |||
| 437 | if ($container->hasDefinition('sonata.media.adapter.filesystem.replicate') && isset($config['filesystem']['replicate'])) { |
||
| 438 | $container->getDefinition('sonata.media.adapter.filesystem.replicate') |
||
| 439 | ->replaceArgument(0, new Reference($config['filesystem']['replicate']['master'])) |
||
| 440 | ->replaceArgument(1, new Reference($config['filesystem']['replicate']['slave'])) |
||
| 441 | ; |
||
| 442 | } else { |
||
| 443 | $container->removeDefinition('sonata.media.adapter.filesystem.replicate'); |
||
| 444 | $container->removeDefinition('sonata.media.filesystem.replicate'); |
||
| 445 | } |
||
| 446 | |||
| 447 | if ($container->hasDefinition('sonata.media.adapter.filesystem.mogilefs') && isset($config['filesystem']['mogilefs'])) { |
||
| 448 | $container->getDefinition('sonata.media.adapter.filesystem.mogilefs') |
||
| 449 | ->replaceArgument(0, $config['filesystem']['mogilefs']['domain']) |
||
| 450 | ->replaceArgument(1, $config['filesystem']['mogilefs']['hosts']) |
||
| 451 | ; |
||
| 452 | } else { |
||
| 453 | $container->removeDefinition('sonata.media.adapter.filesystem.mogilefs'); |
||
| 454 | $container->removeDefinition('sonata.media.filesystem.mogilefs'); |
||
| 455 | } |
||
| 456 | |||
| 457 | if ($container->hasDefinition('sonata.media.adapter.filesystem.opencloud') && |
||
| 458 | (isset($config['filesystem']['openstack']) || isset($config['filesystem']['rackspace']))) { |
||
| 459 | if (isset($config['filesystem']['openstack'])) { |
||
| 460 | $container->setParameter('sonata.media.adapter.filesystem.opencloud.class', 'OpenCloud\OpenStack'); |
||
| 461 | $settings = 'openstack'; |
||
| 462 | } else { |
||
| 463 | $container->setParameter('sonata.media.adapter.filesystem.opencloud.class', 'OpenCloud\Rackspace'); |
||
| 464 | $settings = 'rackspace'; |
||
| 465 | } |
||
| 466 | $container->getDefinition('sonata.media.adapter.filesystem.opencloud.connection') |
||
| 467 | ->replaceArgument(0, $config['filesystem'][$settings]['url']) |
||
| 468 | ->replaceArgument(1, $config['filesystem'][$settings]['secret']) |
||
| 469 | ; |
||
| 470 | $container->getDefinition('sonata.media.adapter.filesystem.opencloud') |
||
| 471 | ->replaceArgument(1, $config['filesystem'][$settings]['containerName']) |
||
| 472 | ->replaceArgument(2, $config['filesystem'][$settings]['create_container']); |
||
| 473 | $container->getDefinition('sonata.media.adapter.filesystem.opencloud.objectstore') |
||
| 474 | ->replaceArgument(1, $config['filesystem'][$settings]['region']); |
||
| 475 | } else { |
||
| 476 | $container->removeDefinition('sonata.media.adapter.filesystem.opencloud'); |
||
| 477 | $container->removeDefinition('sonata.media.adapter.filesystem.opencloud.connection'); |
||
| 478 | $container->removeDefinition('sonata.media.adapter.filesystem.opencloud.objectstore'); |
||
| 479 | $container->removeDefinition('sonata.media.filesystem.opencloud'); |
||
| 480 | } |
||
| 481 | } |
||
| 482 | |||
| 483 | /** |
||
| 484 | * @param ContainerBuilder $container |
||
| 485 | * @param array $config |
||
| 486 | */ |
||
| 487 | public function configureExtra(ContainerBuilder $container, array $config) |
||
| 488 | { |
||
| 489 | if ($config['pixlr']['enabled']) { |
||
| 490 | $container->getDefinition('sonata.media.extra.pixlr') |
||
| 491 | ->replaceArgument(0, $config['pixlr']['referrer']) |
||
| 492 | ->replaceArgument(1, $config['pixlr']['secret']) |
||
| 493 | ; |
||
| 494 | } else { |
||
| 495 | $container->removeDefinition('sonata.media.extra.pixlr'); |
||
| 496 | } |
||
| 497 | } |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Add class to compile. |
||
| 501 | */ |
||
| 502 | public function configureClassesToCompile() |
||
| 503 | { |
||
| 504 | if (\PHP_VERSION_ID >= 70000) { |
||
| 505 | return; |
||
| 506 | } |
||
| 507 | |||
| 508 | $this->addClassesToCompile(array( |
||
|
|
|||
| 509 | 'Sonata\\MediaBundle\\CDN\\CDNInterface', |
||
| 510 | 'Sonata\\MediaBundle\\CDN\\CloudFront', |
||
| 511 | 'Sonata\\MediaBundle\\CDN\\Fallback', |
||
| 512 | 'Sonata\\MediaBundle\\CDN\\PantherPortal', |
||
| 513 | 'Sonata\\MediaBundle\\CDN\\Server', |
||
| 514 | 'Sonata\\MediaBundle\\Extra\\Pixlr', |
||
| 515 | 'Sonata\\MediaBundle\\Filesystem\\Local', |
||
| 516 | 'Sonata\\MediaBundle\\Filesystem\\Replicate', |
||
| 517 | 'Sonata\\MediaBundle\\Generator\\DefaultGenerator', |
||
| 518 | 'Sonata\\MediaBundle\\Generator\\GeneratorInterface', |
||
| 519 | 'Sonata\\MediaBundle\\Generator\\ODMGenerator', |
||
| 520 | 'Sonata\\MediaBundle\\Generator\\PHPCRGenerator', |
||
| 521 | 'Sonata\\MediaBundle\\Metadata\\AmazonMetadataBuilder', |
||
| 522 | 'Sonata\\MediaBundle\\Metadata\\MetadataBuilderInterface', |
||
| 523 | 'Sonata\\MediaBundle\\Metadata\\NoopMetadataBuilder', |
||
| 524 | 'Sonata\\MediaBundle\\Metadata\\ProxyMetadataBuilder', |
||
| 525 | 'Sonata\\MediaBundle\\Model\\Gallery', |
||
| 526 | 'Sonata\\MediaBundle\\Model\\GalleryItem', |
||
| 527 | 'Sonata\\MediaBundle\\Model\\GalleryItemInterface', |
||
| 528 | 'Sonata\\MediaBundle\\Model\\GalleryInterface', |
||
| 529 | 'Sonata\\MediaBundle\\Model\\GalleryManager', |
||
| 530 | 'Sonata\\MediaBundle\\Model\\GalleryManagerInterface', |
||
| 531 | 'Sonata\\MediaBundle\\Model\\Media', |
||
| 532 | 'Sonata\\MediaBundle\\Model\\MediaInterface', |
||
| 533 | 'Sonata\\MediaBundle\\Model\\MediaManagerInterface', |
||
| 534 | 'Sonata\\MediaBundle\\Provider\\BaseProvider', |
||
| 535 | 'Sonata\\MediaBundle\\Provider\\BaseVideoProvider', |
||
| 536 | 'Sonata\\MediaBundle\\Provider\\DailyMotionProvider', |
||
| 537 | 'Sonata\\MediaBundle\\Provider\\FileProvider', |
||
| 538 | 'Sonata\\MediaBundle\\Provider\\ImageProvider', |
||
| 539 | 'Sonata\\MediaBundle\\Provider\\MediaProviderInterface', |
||
| 540 | 'Sonata\\MediaBundle\\Provider\\Pool', |
||
| 541 | 'Sonata\\MediaBundle\\Provider\\VimeoProvider', |
||
| 542 | 'Sonata\\MediaBundle\\Provider\\YouTubeProvider', |
||
| 543 | 'Sonata\\MediaBundle\\Resizer\\ResizerInterface', |
||
| 544 | 'Sonata\\MediaBundle\\Resizer\\SimpleResizer', |
||
| 545 | 'Sonata\\MediaBundle\\Resizer\\SquareResizer', |
||
| 546 | 'Sonata\\MediaBundle\\Security\\DownloadStrategyInterface', |
||
| 547 | 'Sonata\\MediaBundle\\Security\\ForbiddenDownloadStrategy', |
||
| 548 | 'Sonata\\MediaBundle\\Security\\PublicDownloadStrategy', |
||
| 549 | 'Sonata\\MediaBundle\\Security\\RolesDownloadStrategy', |
||
| 550 | 'Sonata\\MediaBundle\\Security\\SessionDownloadStrategy', |
||
| 551 | 'Sonata\\MediaBundle\\Templating\\Helper\\MediaHelper', |
||
| 552 | 'Sonata\\MediaBundle\\Thumbnail\\ConsumerThumbnail', |
||
| 553 | 'Sonata\\MediaBundle\\Thumbnail\\FormatThumbnail', |
||
| 554 | 'Sonata\\MediaBundle\\Thumbnail\\ThumbnailInterface', |
||
| 555 | 'Sonata\\MediaBundle\\Twig\\Extension\\MediaExtension', |
||
| 556 | )); |
||
| 557 | } |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Allow an extension to prepend the extension configurations. |
||
| 561 | * |
||
| 562 | * @param ContainerBuilder $container |
||
| 563 | */ |
||
| 564 | public function prepend(ContainerBuilder $container) |
||
| 565 | { |
||
| 566 | $bundles = $container->getParameter('kernel.bundles'); |
||
| 567 | |||
| 568 | // Store SonataAdminBundle configuration for later use |
||
| 569 | if (isset($bundles['SonataAdminBundle'])) { |
||
| 570 | $this->bundleConfigs['SonataAdminBundle'] = current($container->getExtensionConfig('sonata_admin')); |
||
| 571 | } |
||
| 572 | } |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Checks if the classification of media is enabled. |
||
| 576 | * |
||
| 577 | * @param array $config |
||
| 578 | * |
||
| 579 | * @return bool |
||
| 580 | */ |
||
| 581 | private function isClassificationEnabled(array $config) |
||
| 582 | { |
||
| 583 | return interface_exists('Sonata\ClassificationBundle\Model\CategoryInterface') |
||
| 584 | && !$config['force_disable_category']; |
||
| 585 | } |
||
| 586 | |||
| 587 | /** |
||
| 588 | * @param ContainerBuilder $container |
||
| 589 | * @param array $config |
||
| 590 | */ |
||
| 591 | private function configureAdapters(ContainerBuilder $container, array $config) |
||
| 600 | |||
| 601 | /** |
||
| 602 | * @param ContainerBuilder $container |
||
| 603 | * @param array $config |
||
| 604 | */ |
||
| 605 | private function configureResizers(ContainerBuilder $container, array $config) |
||
| 629 | } |
||
| 630 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.