本文整理汇总了PHP中Sonata\MediaBundle\Model\MediaInterface::setBinaryContent方法的典型用法代码示例。如果您正苦于以下问题:PHP MediaInterface::setBinaryContent方法的具体用法?PHP MediaInterface::setBinaryContent怎么用?PHP MediaInterface::setBinaryContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\MediaBundle\Model\MediaInterface
的用法示例。
在下文中一共展示了MediaInterface::setBinaryContent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fixBinaryContent
/**
* {@inheritdoc}
*/
protected function fixBinaryContent(MediaInterface $media)
{
if (!$media->getBinaryContent()) {
return;
}
if (preg_match("/vimeo\\.com\\/(\\d+)/", $media->getBinaryContent(), $matches)) {
$media->setBinaryContent($matches[1]);
}
}
示例2: fixBinaryContent
/**
* {@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: fixBinaryContent
/**
* {@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]);
}
}
示例4: fixBinaryContent
/**
* {@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]);
}
}
示例5: fixBinaryContent
/**
* {@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);
}
}
示例6: generateBinaryFromRequest
/**
* 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);
}
示例7: fixBinaryContent
/**
* @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);
}
}