diff --git a/Helper/LinkResolver.php b/Helper/LinkResolver.php
new file mode 100644
index 0000000..539c8f2
--- /dev/null
+++ b/Helper/LinkResolver.php
@@ -0,0 +1,31 @@
+maybeRef = $maybeRef;
+ }
+
+ /**
+ * @param string|null $maybeRef
+ */
+ public function setMaybeRef($maybeRef)
+ {
+ $this->maybeRef = $maybeRef;
+ }
+}
diff --git a/Helper/LocalLinkResolver.php b/Helper/LocalLinkResolver.php
index dd8c014..e96966c 100755
--- a/Helper/LocalLinkResolver.php
+++ b/Helper/LocalLinkResolver.php
@@ -6,35 +6,27 @@
use Prismic\Api;
use Prismic\Ref;
-use Prismic\LinkResolver;
use Prismic\Fragment\Link\DocumentLink;
class LocalLinkResolver extends LinkResolver
{
-
- private $router;
- private $api;
- private $maybeRef;
+ private $router;
/**
* @param RouterInterface $router
- * @param Api $api
- * @param string|null $maybeRef
*/
- public function __construct(RouterInterface $router, Api $api, $maybeRef = null)
+ public function __construct(RouterInterface $router)
{
$this->router = $router;
- $this->api = $api;
- $this->maybeRef = $maybeRef;
}
/**
* @param DocumentLink $link
* @return string
*/
- public function resolve($link)
+ public function resolve($link)
{
- return $this->router->generate('detail', array('id' => $link->getId(), 'slug' => $link->getSlug(), 'ref' => (string) $this->maybeRef));
+ return $this->router->generate('detail', array('id' => $link->getId(), 'slug' => $link->getSlug(), 'ref' => (string) $this->getMaybeRef()));
}
}
diff --git a/Helper/PrismicContext.php b/Helper/PrismicContext.php
index c7115b1..2baa811 100755
--- a/Helper/PrismicContext.php
+++ b/Helper/PrismicContext.php
@@ -2,8 +2,6 @@
namespace Prismic\Bundle\PrismicBundle\Helper;
-use Symfony\Component\Routing\RouterInterface;
-
use Prismic\api;
use Prismic\Ref;
use Prismic\Document;
@@ -12,7 +10,6 @@
class PrismicContext
{
private $prismic;
- private $router;
private $accessToken;
private $api;
@@ -23,12 +20,12 @@ class PrismicContext
/**
* @param PrismicHelper $prismic
- * @param RouterInterface $router
+ * @param LinkResolver $linkResolver
*/
- public function __construct(PrismicHelper $prismic, RouterInterface $router)
+ public function __construct(PrismicHelper $prismic, LinkResolver $linkResolver)
{
$this->prismic = $prismic;
- $this->router = $router;
+ $this->linkResolver = $linkResolver;
}
/**
@@ -38,7 +35,7 @@ public function setAccessToken($accessToken)
{
$this->accessToken = $accessToken;
- $this->api = $this->linkResolver = null;
+ $this->api = null;
}
/**
@@ -48,7 +45,7 @@ public function setRef($ref)
{
$this->ref = $ref;
- $this->maybeRef = $this->linkResolver = null;
+ $this->maybeRef = null;
}
/**
@@ -112,9 +109,7 @@ public function getMaybeRef()
*/
public function getLinkResolver()
{
- if (!$this->linkResolver) {
- $this->linkResolver = new LocalLinkResolver($this->router, $this->getApi(), $this->getMaybeRef());
- }
+ $this->linkResolver->setMaybeRef($this->getMaybeRef());
return $this->linkResolver;
}
@@ -136,7 +131,7 @@ public function resolveLink(Document $doc)
*
* @return Document|null
*/
- public function getDocument($id)
+ public function getDocument($id)
{
$docs = $this->getApi()->forms()->everything->ref($this->getRef())->query(
'[[:d = at(document.id, "'.$id.'")]]'
diff --git a/Resources/config/services.xml b/Resources/config/services.xml
index 6739a30..d7baa88 100755
--- a/Resources/config/services.xml
+++ b/Resources/config/services.xml
@@ -6,6 +6,7 @@
Prismic\Bundle\PrismicBundle\Helper\PrismicHelper
+ Prismic\Bundle\PrismicBundle\Helper\LocalLinkResolver
Prismic\Bundle\PrismicBundle\Helper\PrismicContext
@@ -17,9 +18,14 @@
%prismic.api.clientSecret%
+
+
+
+
+
service('request').get('ACCESS_TOKEN')
service('request').query.get('ref')