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); } }