本文整理汇总了PHP中Sonata\MediaBundle\Model\MediaInterface::getContext方法的典型用法代码示例。如果您正苦于以下问题:PHP MediaInterface::getContext方法的具体用法?PHP MediaInterface::getContext怎么用?PHP MediaInterface::getContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\MediaBundle\Model\MediaInterface
的用法示例。
在下文中一共展示了MediaInterface::getContext方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRootCategory
/**
* @param MediaInterface $media
*
* @return mixed
*/
protected function getRootCategory(MediaInterface $media)
{
if (!$this->rootCategories) {
$this->rootCategories = $this->container->get('sonata.classification.manager.category')->getRootCategories(false);
}
if (!array_key_exists($media->getContext(), $this->rootCategories)) {
throw new \RuntimeException(sprintf('There is no main category related to context: %s', $media->getContext()));
}
return $this->rootCategories[$media->getContext()];
}
示例2: generatePath
/**
* @param \Sonata\MediaBundle\Model\MediaInterface $media
*
* @return string
*/
public function generatePath(MediaInterface $media)
{
$segments = preg_split('#/#', $media->getId(), null, PREG_SPLIT_NO_EMPTY);
if (count($segments) > 1) {
// remove last part from id
array_pop($segments);
$path = join($segments, '/');
} else {
$path = '';
}
return $path ? sprintf('%s/%s', $media->getContext(), $path) : $media->getContext();
}
示例3: generatePath
/**
* @abstract
* @param \Sonata\MediaBundle\Model\MediaInterface $media
* @return string
*/
public function generatePath(MediaInterface $media)
{
$rep_first_level = (int) ($media->getId() / $this->firstLevel);
$rep_second_level = (int) (($media->getId() - ($rep_first_level * $this->firstLevel)) / $this->secondLevel);
return sprintf('%s/%04s/%02s', $media->getContext(), $rep_first_level + 1, $rep_second_level + 1);
}
示例4: 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()));
}
示例5: 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);
}
示例6: getFormatName
public function getFormatName(MediaInterface $media, $format)
{
if (in_array($format, array('admin', 'reference', 'orangegate'))) {
return $format;
}
$baseName = $media->getContext() . '_';
if (substr($format, 0, strlen($baseName)) == $baseName) {
return $format;
}
return $baseName . str_replace('-', '_', $format);
}
示例7: resize
/**
* @param \Sonata\MediaBundle\Model\MediaInterface $media
* @param \Gaufrette\File $in
* @param \Gaufrette\File $out
* @param string $format
* @param array $settings
* @return void
*/
public function resize(MediaInterface $media, File $in, File $out, $format, $settings)
{
if (!isset($settings['width'])) {
throw new \RuntimeException(sprintf('Width parameter is missing in context "%s" for provider "%s"', $media->getContext(), $media->getProviderClass()));
}
$image = $this->getAdapter()->load($in->getContent());
if ($settings['height'] == null) {
$size = $image->getSize();
$settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth());
}
$content = $image->thumbnail(new Box($settings['width'], $settings['height']), $this->getMode())->get($format);
$out->setContent($content);
}
示例8: 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);
}
示例9: getFormatName
public function getFormatName(MediaInterface $media, $format)
{
if ($format == 'admin') {
return 'admin';
}
if ($format == 'reference') {
return 'reference';
}
if ($format == 'orangegate') {
return 'orangegate';
}
$baseName = $media->getContext() . '_';
if (substr($format, 0, strlen($baseName)) == $baseName) {
return $format;
}
return $baseName . $format;
}
示例10: 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);
}
示例11: getDownloadMode
/**
* @param \Sonata\MediaBundle\Model\MediaInterface $media
*
* @return string
*/
public function getDownloadMode(MediaInterface $media)
{
$context = $this->getContext($media->getContext());
return $context['download']['mode'];
}
示例12: getFormatChoices
/**
* @param MediaInterface|null $media
*
* @return array
*/
protected function getFormatChoices(MediaInterface $media = null)
{
$formatChoices = array();
if (!$media instanceof MediaInterface) {
return $formatChoices;
}
$formats = $this->getMediaPool()->getFormatNamesByContext($media->getContext());
foreach ($formats as $code => $format) {
$formatChoices[$code] = $code;
}
return $formatChoices;
}
示例13: generatePath
/**
* {@inheritdoc}
*/
public function generatePath(MediaInterface $media)
{
$id = $media->getId();
return sprintf('%s/%04s/%02s', $media->getContext(), substr($id, 0, 4), substr($id, 4, 2));
}