コード例 #1
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (preg_match("/vimeo\\.com\\/(\\d+)/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[1]);
     }
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (preg_match("/(?<=v(\\=|\\/))([-a-zA-Z0-9_]+)|(?<=youtu\\.be\\/)([-a-zA-Z0-9_]+)/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[2]);
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (preg_match("/www.dailymotion.com\\/video\\/([0-9a-zA-Z]*)_/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[1]);
     }
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (strlen($media->getBinaryContent()) === 11) {
         return;
     }
     if (preg_match("/^(?:http(?:s)?:\\/\\/)?(?:www\\.)?(?:youtu\\.be\\/|youtube\\.com\\/(?:(?:watch)?\\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\\/))([^\\#\\?&\"'>]+)/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[1]);
     }
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (strlen($media->getBinaryContent()) === 11) {
         return;
     }
     if (preg_match("/videos\\.sapo\\.pt\\/([A-Za-z0-9]+)(\\/mov\\/)?/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[1]);
     }
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (strpos($media->getBinaryContent(), '|') !== FALSE) {
         return;
     }
     if (preg_match('/(?:config\\.|player\\.)?playwire.com\\/(\\d+)\\/videos\\/v2\\/(\\d+)\\//', $media->getBinaryContent(), $matches)) {
         $binary = sprintf('%d|%d', $matches[1], $matches[2]);
         $media->setBinaryContent($binary);
     }
 }
コード例 #7
0
 /**
  * Set media binary content according to request content.
  *
  * @param MediaInterface $media
  */
 protected function generateBinaryFromRequest(MediaInterface $media)
 {
     if (php_sapi_name() === 'cli') {
         throw new \RuntimeException('The current process cannot be executed in cli environment');
     }
     if (!$media->getContentType()) {
         throw new \RuntimeException('You must provide the content type value for your media before setting the binary content');
     }
     $request = $media->getBinaryContent();
     if (!$request instanceof Request) {
         throw new \RuntimeException('Expected Request in binary content');
     }
     $content = $request->getContent();
     // create unique id for media reference
     $guesser = ExtensionGuesser::getInstance();
     $extension = $guesser->guess($media->getContentType());
     if (!$extension) {
         throw new \RuntimeException(sprintf('Unable to guess extension for content type %s', $media->getContentType()));
     }
     $handle = tmpfile();
     fwrite($handle, $content);
     $file = new ApiMediaFile($handle);
     $file->setExtension($extension);
     $file->setMimetype($media->getContentType());
     $media->setBinaryContent($file);
 }
コード例 #8
0
ファイル: FileProvider.php プロジェクト: ingeniorweb/symfo3cv
 /**
  * @throws \RuntimeException
  *
  * @param \Sonata\MediaBundle\Model\MediaInterface $media
  *
  * @return
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if ($media->getBinaryContent() === null) {
         return;
     }
     // if the binary content is a filename => convert to a valid File
     if (!$media->getBinaryContent() instanceof File) {
         if (!is_file($media->getBinaryContent())) {
             throw new \RuntimeException('The file does not exist : ' . $media->getBinaryContent());
         }
         $binaryContent = new File($media->getBinaryContent());
         $media->setBinaryContent($binaryContent);
     }
 }