当前位置: 首页>>代码示例>>PHP>>正文


PHP MediaInterface::getContext方法代码示例

本文整理汇总了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()];
 }
开发者ID:rmzamora,项目名称:SonataMediaBundle,代码行数:15,代码来源:MediaEventSubscriber.php

示例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();
 }
开发者ID:serialken,项目名称:BugTracker,代码行数:17,代码来源:PHPCRGenerator.php

示例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);
    }
开发者ID:ronnylt,项目名称:MediaBundle,代码行数:12,代码来源:DefaultGenerator.php

示例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()));
 }
开发者ID:ingeniorweb,项目名称:symfo3cv,代码行数:33,代码来源:SquareResizer.php

示例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);
 }
开发者ID:zapoyok,项目名称:core-bundle,代码行数:29,代码来源:ScaleCropResizer.php

示例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);
 }
开发者ID:symbio,项目名称:orangegate4-media-bundle,代码行数:11,代码来源:ImageProvider.php

示例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);
 }
开发者ID:helmer,项目名称:SonataMediaBundle,代码行数:21,代码来源:SimpleResizer.php

示例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);
 }
开发者ID:nicolasricci,项目名称:SonataMediaBundle,代码行数:17,代码来源:SimpleResizer.php

示例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;
 }
开发者ID:peruginni,项目名称:orangegate4-media-bundle,代码行数:17,代码来源:ImageProvider.php

示例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);
 }
开发者ID:NadirZenith,项目名称:NzSonataMediaBundle,代码行数:22,代码来源:FixCropResizer.php

示例11: getDownloadMode

 /**
  * @param \Sonata\MediaBundle\Model\MediaInterface $media
  *
  * @return string
  */
 public function getDownloadMode(MediaInterface $media)
 {
     $context = $this->getContext($media->getContext());
     return $context['download']['mode'];
 }
开发者ID:Infernosquad,项目名称:SonataMediaBundle,代码行数:10,代码来源:Pool.php

示例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;
 }
开发者ID:elvetemedve,项目名称:SonataMediaBundle,代码行数:17,代码来源:MediaBlockService.php

示例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));
 }
开发者ID:ipalo,项目名称:SonataMediaBundle,代码行数:8,代码来源:ODMGenerator.php


注:本文中的Sonata\MediaBundle\Model\MediaInterface::getContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。