mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00

- Squashed Pull request #1730 - Squashed Pull request #1741 - Squashed Pull request #1742 - Squash merge branch 4.0 - Squashed Pull request #1744 - Squashed Pull request #1746 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed Pull request #1758 - Avoid using imagine/imagine alias as it is causing install issues - Squashed merge branch 4.0 - Squashed Pull request #1763 - Squashed merge branch 4.0 - Squash of 6 commits - Squashed merge branch 4.0 - This is a combination of 2 commits. - Squashed Pull request #1775 - Squashed Pull request #1777 - Squashed Pull request #1779 - Squashed Pull request #1780 - Squashed Pull request #1782 - Adds a Pull request template - Squased Pull request #1783 - Squash Pull request #1786 - Squashed Pull request #1796 - Squashed merge branch 4.0 - Squash Pull request #1791 - Squashed merge branch 4.0 - Squashed Pull request #1808 - Squashed Pull request #1811 - Squashed Pull request #1809
97 lines
1.9 KiB
PHP
97 lines
1.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2016 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Border\Attribute;
|
|
|
|
use Alchemy\Phrasea\Application;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
/**
|
|
* Phraseanet Border Story Attribute
|
|
*
|
|
* This attribute is used to store a destination story for a file, prior to
|
|
* their record creation
|
|
*/
|
|
class Story implements AttributeInterface
|
|
{
|
|
protected $story;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param \record_adapter $story The destination story
|
|
*/
|
|
public function __construct(\record_adapter $story)
|
|
{
|
|
if (!$story->isStory()) {
|
|
throw new \InvalidArgumentException('Unable to fetch a story from string');
|
|
}
|
|
|
|
$this->story = $story;
|
|
}
|
|
|
|
/**
|
|
* Destructor
|
|
*/
|
|
public function __destruct()
|
|
{
|
|
$this->story = null;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getName()
|
|
{
|
|
return self::NAME_STORY;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @return \record_adapter The story
|
|
*/
|
|
public function getValue()
|
|
{
|
|
return $this->story;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function asString()
|
|
{
|
|
return $this->story->getId();
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @return Story
|
|
*/
|
|
public static function loadFromString(Application $app, $string)
|
|
{
|
|
$ids = explode('_', $string);
|
|
|
|
try {
|
|
$story = new \record_adapter($app, $ids[0], $ids[1]);
|
|
} catch (NotFoundHttpException $e) {
|
|
throw new \InvalidArgumentException('Unable to fetch a story from string');
|
|
}
|
|
|
|
if (!$story->isStory()) {
|
|
throw new \InvalidArgumentException('Unable to fetch a story from string');
|
|
}
|
|
|
|
return new static($story);
|
|
}
|
|
}
|