本文整理汇总了PHP中Sonata\MediaBundle\Model\MediaInterface::getProviderName方法的典型用法代码示例。如果您正苦于以下问题:PHP MediaInterface::getProviderName方法的具体用法?PHP MediaInterface::getProviderName怎么用?PHP MediaInterface::getProviderName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\MediaBundle\Model\MediaInterface
的用法示例。
在下文中一共展示了MediaInterface::getProviderName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resize
/**
* {@inheritdoc}
*/
public function resize(MediaInterface $media, File $in, File $out, $format, array $settings)
{
if (!isset($settings['width'])) {
throw new \RuntimeException(sprintf('Width parameter is missing in context "%s" for provider "%s"', $media->getContext(), $media->getProviderName()));
}
$image = $this->adapter->load($in->getContent());
$size = $media->getBox();
if (null != $settings['height']) {
if ($size->getHeight() > $size->getWidth()) {
$higher = $size->getHeight();
$lower = $size->getWidth();
} else {
$higher = $size->getWidth();
$lower = $size->getHeight();
}
$crop = $higher - $lower;
if ($crop > 0) {
$point = $higher == $size->getHeight() ? new Point(0, 0) : new Point($crop / 2, 0);
$image->crop($point, new Box($lower, $lower));
$size = $image->getSize();
}
}
$settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth());
if ($settings['height'] < $size->getHeight() && $settings['width'] < $size->getWidth()) {
$content = $image->thumbnail(new Box($settings['width'], $settings['height']), $this->mode)->get($format, array('quality' => $settings['quality']));
} else {
$content = $image->get($format, array('quality' => $settings['quality']));
}
$out->setContent($content, $this->metadata->get($media, $out->getName()));
}
示例2: getBox
/**
* {@inheritdoc}
*/
public function getBox(MediaInterface $media, array $settings)
{
$size = $media->getBox();
$skipBox = false;
$constraint = array_key_exists('constraint', $settings) && $settings['constraint'] === false;
if ($constraint && $size->getHeight() > $size->getWidth()) {
$settings['width'] = $settings['height'];
$this->mode = ImageInterface::THUMBNAIL_INSET;
$skipBox = true;
}
$hasWidth = array_key_exists('width', $settings) && $settings['width'] > 0;
$hasHeight = array_key_exists('height', $settings) && $settings['height'] > 0;
if (!$hasWidth && !$hasHeight) {
throw new \RuntimeException(sprintf('Width/Height parameter is missing in context "%s" for provider "%s". Please add at least one parameter.', $media->getContext(), $media->getProviderName()));
}
if ($hasWidth && $hasHeight && !$skipBox) {
return new Box($settings['width'], $settings['height']);
}
if (!$hasHeight) {
$settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth());
}
if (!$hasWidth) {
$settings['width'] = (int) ($settings['height'] * $size->getWidth() / $size->getHeight());
}
return $this->computeBox($size, $settings);
}
示例3: getBox
/**
* {@inheritdoc}
*/
public function getBox(MediaInterface $media, array $settings)
{
$size = $media->getBox();
if ($settings['width'] == null && $settings['height'] == null) {
throw new \RuntimeException(sprintf('Width/Height parameter is missing in context "%s" for provider "%s". Please add at least one parameter.', $media->getContext(), $media->getProviderName()));
}
if ($settings['height'] == null) {
$settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth());
}
if ($settings['width'] == null) {
$settings['width'] = (int) ($settings['height'] * $size->getWidth() / $size->getHeight());
}
return $this->computeBox($media, $settings);
}
示例4: getAmazonBuilder
/**
* @param MediaInterface $metadata
* @param string $filename
*
* @return array
*/
protected function getAmazonBuilder(MediaInterface $media, $filename)
{
$adapter = $this->container->get($media->getProviderName())->getFilesystem()->getAdapter();
//handle special Replicate adapter
if ($adapter instanceof Replicate) {
$adapterClassNames = $adapter->getAdapterClassNames();
} else {
$adapterClassNames = array(get_class($adapter));
}
//for amazon s3
if (!in_array('Gaufrette\\Adapter\\AmazonS3', $adapterClassNames) || !$this->container->has('sonata.media.metadata.amazon')) {
return false;
}
return $this->container->get('sonata.media.metadata.amazon')->get($media, $filename);
}
示例5: getBox
/**
* {@inheritdoc}
*/
public function getBox(MediaInterface $media, array $settings)
{
$size = $media->getBox();
$hasWidth = isset($settings['width']) && $settings['width'];
$hasHeight = isset($settings['height']) && $settings['height'];
if (!$hasWidth && !$hasHeight) {
throw new \RuntimeException(sprintf('Width/Height parameter is missing in context "%s" for provider "%s". Please add at least one parameter.', $media->getContext(), $media->getProviderName()));
}
if ($hasWidth && $hasHeight) {
return new Box($settings['width'], $settings['height']);
}
if (!$hasHeight) {
$settings['height'] = intval($settings['width'] * $size->getHeight() / $size->getWidth());
}
if (!$hasWidth) {
$settings['width'] = intval($settings['height'] * $size->getWidth() / $size->getHeight());
}
return $this->computeBox($media, $settings);
}
示例6: getProvider
/**
* @param MediaInterface $media
*
* @return MediaProviderInterface
*/
private function getProvider(MediaInterface $media)
{
return $this->pool->getProvider($media->getProviderName());
}
示例7: getProvider
/**
* @param MediaInterface $media
*
* @return MediaProviderInterface
*/
public function getProvider(MediaInterface $media)
{
return $this->get('sonata.media.pool')->getProvider($media->getProviderName());
}
示例8: validate
/**
* @param \Sonata\CoreBundle\Validator\ErrorElement $errorElement
* @param \Sonata\MediaBundle\Model\MediaInterface $media
*/
public function validate(ErrorElement $errorElement, MediaInterface $media)
{
if (!$media->getProviderName()) {
return;
}
$provider = $this->getProvider($media->getProviderName());
$provider->validate($errorElement, $media);
}
示例9: addImageInfo
/**
* @param MediaInterface $image
* @param SeoPageInterface $seoPage
*/
protected function addImageInfo(MediaInterface $image, SeoPageInterface $seoPage)
{
$provider = $this->mediaPool->getProvider($image->getProviderName());
$seoPage->addMeta('property', 'og:image', $provider->generatePublicUrl($image, $this->mediaFormat))->addMeta('property', 'og:image:width', $image->getWidth())->addMeta('property', 'og:image:height', $image->getHeight())->addMeta('property', 'og:image:type', $image->getContentType());
}
示例10: path
/**
* @param \Sonata\MediaBundle\Model\MediaInterface $media
* @param string $format
* @return string
*/
public function path(MediaInterface $media = null, $format)
{
if (!$media) {
return '';
}
$provider = $this->getMediaService()
->getProvider($media->getProviderName());
return $provider->generatePublicUrl($media, $format);
}