/**
  * {@inheritdoc}
  */
 public function searchResultToAsset($result, $catalog_id)
 {
     /** @var EntityStorageInterface $storage */
     $storage = $this->entityTypeManager->getStorage('embridge_asset_entity');
     if ($asset = $this->loadFromAssetId($result['id'], $storage)) {
         return $asset;
     }
     $values = ['asset_id' => $result['id'], 'source_path' => $result['sourcepath'], 'filename' => $result['name'], 'filesize' => $result['filesize'], 'filemime' => $this->mimeGuesser->guess($result['name']), 'catalog_id' => $catalog_id];
     /** @var EmbridgeAssetEntityInterface $asset */
     $asset = $storage->create($values);
     $asset->setTemporary();
     $asset->save();
     return $asset;
 }
Example #2
0
 /**
  * @covers ::registerWithSymfonyGuesser
  *
  * @see Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser
  */
 public function testSymfonyGuesserRegistration()
 {
     // Make the guessers property accessible on Symfony's MimeTypeGuesser.
     $symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
     // Test that the Drupal mime type guess is not being used before the
     // override method is called. It is possible that the test environment does
     // not support the default guessers.
     $guessers = $this->readAttribute($symfony_guesser, 'guessers');
     if (count($guessers)) {
         $this->assertNotInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]);
     }
     $container = new ContainerBuilder();
     $container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager()));
     MimeTypeGuesser::registerWithSymfonyGuesser($container);
     $symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
     $guessers = $this->readAttribute($symfony_guesser, 'guessers');
     $this->assertSame($container->get('file.mime_type.guesser'), $guessers[0]);
     $this->assertInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]);
     $count = count($guessers);
     $container = new ContainerBuilder();
     $container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager()));
     MimeTypeGuesser::registerWithSymfonyGuesser($container);
     $symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
     $guessers = $this->readAttribute($symfony_guesser, 'guessers');
     $this->assertSame($container->get('file.mime_type.guesser'), $guessers[0]);
     $this->assertInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]);
     $new_count = count($guessers);
     $this->assertEquals($count, $new_count, 'The count of mime type guessers remains the same after container re-init.');
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function preHandle(Request $request)
 {
     $this->loadLegacyIncludes();
     // Load all enabled modules.
     $this->container->get('module_handler')->loadAll();
     // Register stream wrappers.
     $this->container->get('stream_wrapper_manager')->register();
     // Initialize legacy request globals.
     $this->initializeRequestGlobals($request);
     // Put the request on the stack.
     $this->container->get('request_stack')->push($request);
     // Set the allowed protocols once we have the config available.
     $allowed_protocols = $this->container->get('config.factory')->get('system.filter')->get('protocols');
     if (!isset($allowed_protocols)) {
         // \Drupal\Component\Utility\UrlHelper::filterBadProtocol() is called by
         // the installer and update.php, in which case the configuration may not
         // exist (yet). Provide a minimal default set of allowed protocols for
         // these cases.
         $allowed_protocols = array('http', 'https');
     }
     UrlHelper::setAllowedProtocols($allowed_protocols);
     // Override of Symfony's mime type guesser singleton.
     MimeTypeGuesser::registerWithSymfonyGuesser($this->container);
     $this->prepared = TRUE;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function preHandle(Request $request)
 {
     $this->loadLegacyIncludes();
     // Load all enabled modules.
     $this->container->get('module_handler')->loadAll();
     // Register stream wrappers.
     $this->container->get('stream_wrapper_manager')->register();
     // Initialize legacy request globals.
     $this->initializeRequestGlobals($request);
     // Put the request on the stack.
     $this->container->get('request_stack')->push($request);
     // Set the allowed protocols.
     UrlHelper::setAllowedProtocols($this->container->getParameter('filter_protocols'));
     // Override of Symfony's MIME type guesser singleton.
     MimeTypeGuesser::registerWithSymfonyGuesser($this->container);
     $this->prepared = TRUE;
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public static function registerWithSymfonyGuesser(\Symfony\Component\DependencyInjection\ContainerInterface $container)
 {
     \Drupal\Core\File\MimeType\MimeTypeGuesser::registerWithSymfonyGuesser($container);
 }