本文整理汇总了PHP中Sonata\MediaBundle\Model\MediaInterface::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP MediaInterface::getId方法的具体用法?PHP MediaInterface::getId怎么用?PHP MediaInterface::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\MediaBundle\Model\MediaInterface
的用法示例。
在下文中一共展示了MediaInterface::getId方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: save
/**
* Updates a media
*
* @param \Sonata\MediaBundle\Model\MediaInterface $media
* @param string $context
* @param string $providerName
* @return void
*/
public function save(MediaInterface $media, $context = null, $providerName = null)
{
if ($context) {
$media->setContext($context);
}
if ($providerName) {
$media->setProviderName($providerName);
}
$isNew = $media->getId() != null;
if ($isNew) {
$this->pool->getProvider($media->getProviderName())->prePersist($media);
} else {
$this->pool->getProvider($media->getProviderName())->preUpdate($media);
}
$this->dm->persist($media);
$this->dm->flush();
if ($isNew) {
$this->pool->getProvider($media->getProviderName())->postPersist($media);
} else {
$this->pool->getProvider($media->getProviderName())->postUpdate($media);
}
// just in case the pool alter the media
$this->dm->persist($media);
$this->dm->flush();
}
示例3: 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();
}
示例4: generate
/**
* {@inheritdoc}
*/
public function generate(MediaProviderInterface $provider, MediaInterface $media)
{
$backend = $this->backend;
$id = $this->id;
$publish = function () use($backend, $media, $id) {
$backend->createAndPublish('sonata.media.create_thumbnail', array('thumbnailId' => $id, 'mediaId' => $media->getId(), 'providerReference' => $media->getProviderReference()));
};
// BC compatibility for missing EventDispatcher
if (null === $this->dispatcher) {
trigger_error('Since version 2.3.3, passing an empty parameter in argument 4 for __construct() in ' . __CLASS__ . ' is deprecated and the workaround for it will be removed in 3.0.', E_USER_DEPRECATED);
$publish();
} else {
$this->dispatcher->addListener('kernel.finish_request', $publish);
}
}
示例5: flushCdn
/**
* @param MediaInterface $media
*/
public function flushCdn(MediaInterface $media)
{
if ($media->getId() && $this->requireThumbnails() && !$media->getCdnIsFlushable()) {
$flushPaths = array();
foreach ($this->getFormats() as $format => $settings) {
if ('admin' === $format || substr($format, 0, strlen($media->getContext())) === $media->getContext()) {
$flushPaths[] = $this->getFilesystem()->get($this->generatePrivateUrl($media, $format), true)->getKey();
}
}
if (!empty($flushPaths)) {
$cdnFlushIdentifier = $this->getCdn()->flushPaths($flushPaths);
$media->setCdnFlushIdentifier($cdnFlushIdentifier);
$media->setCdnIsFlushable(true);
$media->setCdnStatus(CDNInterface::STATUS_TO_FLUSH);
}
}
}
示例6: processMedia
/**
* @param MediaInterface $media
* @param MediaProviderInterface $provider
* @param string $context
* @param string $format
*
* @return bool
*/
protected function processMedia(MediaInterface $media, MediaProviderInterface $provider, $context, $format)
{
$this->log('Deleting thumbs for ' . $media->getName() . ' - ' . $media->getId());
try {
if ($format === $context . '_all') {
$format = null;
}
$provider->removeThumbnails($media, $format);
} catch (\Exception $e) {
$this->log(sprintf('<error>Unable to remove thumbnails, media: %s - %s </error>', $media->getId(), $e->getMessage()));
return false;
}
return true;
}
示例7: generateHash
/**
* @param MediaInterface $media
*
* @return string
*/
private function generateHash(MediaInterface $media)
{
return sha1($media->getId() . $media->getCreatedAt()->format('u') . $this->secret);
}
示例8: 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));
}
示例9: generate
/**
* {@inheritdoc}
*/
public function generate(MediaProviderInterface $provider, MediaInterface $media)
{
$this->backend->createAndPublish('sonata.media.create_thumbnail', array('thumbnailId' => $this->id, 'mediaId' => $media->getId(), 'providerReference' => $media->getProviderReference()));
}
示例10: generatePublicUrl
/**
* @param MediaInterface $media
* @param string $format
*
* @return string
* @internal param Router $router
*/
public function generatePublicUrl(MediaInterface $media, $format)
{
return $this->router->generate('ticket_get_big_img', ['format' => $format, 'id' => $media->getId()]);
}
示例11: processMedia
/**
* @param MediaInterface $media
* @param MediaProviderInterface $provider
*
* @return bool
*/
protected function processMedia($media, $provider)
{
$this->log('Generating thumbs for ' . $media->getName() . ' - ' . $media->getId());
try {
$provider->removeThumbnails($media);
} catch (\Exception $e) {
$this->log(sprintf('<error>Unable to remove old thumbnails, media: %s - %s </error>', $media->getId(), $e->getMessage()));
return false;
}
try {
$provider->generateThumbnails($media);
} catch (\Exception $e) {
$this->log(sprintf('<error>Unable to generate new thumbnails, media: %s - %s </error>', $media->getId(), $e->getMessage()));
return false;
}
return true;
}
示例12: generateThumbnails
public function generateThumbnails(MediaInterface $media)
{
$this->producer->produce(self::QUEUE_NAME, ['id' => $media->getId()]);
}