-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Added resolve events to cache manager #388
Changes from 1 commit
a628969
258bf9f
a913fd3
5542b0f
d3046a2
1c86ebe
ee09bc4
1a01770
6c7a4f5
25effc0
4606a93
e5f94fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
namespace Liip\ImagineBundle\Events; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; | ||
|
||
class PostResolveEvent extends Event | ||
{ | ||
protected $resolver; | ||
|
||
protected $path; | ||
|
||
protected $filter; | ||
|
||
protected $url; | ||
|
||
public function __construct(ResolverInterface $resolver, $path, $filter, $url) | ||
{ | ||
$this->resolver = $resolver; | ||
$this->path = $path; | ||
$this->filter = $filter; | ||
$this->url = $url; | ||
} | ||
|
||
public function getResolver() | ||
{ | ||
return $this->path; | ||
} | ||
|
||
public function getPath() | ||
{ | ||
return $this->path; | ||
} | ||
|
||
public function getFilter() | ||
{ | ||
return $this->filter; | ||
} | ||
|
||
public function getUrl() | ||
{ | ||
return $this->url; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
namespace Liip\ImagineBundle\Events; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; | ||
|
||
class PreResolveEvent extends Event | ||
{ | ||
protected $resolver; | ||
|
||
protected $path; | ||
|
||
protected $filter; | ||
|
||
public function __construct(ResolverInterface $resolver, $path, $filter) | ||
{ | ||
$this->path = $path; | ||
$this->filter = $filter; | ||
} | ||
|
||
public function getResolver() | ||
{ | ||
return $this->path; | ||
} | ||
|
||
public function getPath() | ||
{ | ||
return $this->path; | ||
} | ||
|
||
public function getFilter() | ||
{ | ||
return $this->filter; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,11 @@ | |
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\HttpKernel\UriSigner; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\EventDispatcher\Event; | ||
use Liip\ImagineBundle\ImagineEvents; | ||
use Liip\ImagineBundle\Events\PreResolveEvent; | ||
use Liip\ImagineBundle\Events\PostResolveEvent; | ||
|
||
class CacheManager | ||
{ | ||
|
@@ -31,6 +36,8 @@ class CacheManager | |
*/ | ||
protected $uriSigner; | ||
|
||
protected $dispatcher; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add docblock here please |
||
|
||
/** | ||
* @var string | ||
*/ | ||
|
@@ -44,11 +51,17 @@ class CacheManager | |
* @param UriSigner $uriSigner | ||
* @param string $defaultResolver | ||
*/ | ||
public function __construct(FilterConfiguration $filterConfig, RouterInterface $router, UriSigner $uriSigner, $defaultResolver = null) | ||
{ | ||
public function __construct( | ||
FilterConfiguration $filterConfig, | ||
RouterInterface $router, | ||
UriSigner $uriSigner, | ||
EventDispatcherInterface $dispatcher, | ||
$defaultResolver = null | ||
) { | ||
$this->filterConfig = $filterConfig; | ||
$this->router = $router; | ||
$this->uriSigner = $uriSigner; | ||
$this->dispatcher = $dispatcher; | ||
$this->defaultResolver = $defaultResolver ?: 'default'; | ||
} | ||
|
||
|
@@ -176,7 +189,15 @@ public function resolve($path, $filter) | |
throw new NotFoundHttpException(sprintf("Source image was searched with '%s' outside of the defined root path", $path)); | ||
} | ||
|
||
return $this->getResolver($filter)->resolve($path, $filter); | ||
$resolver = $this->getResolver($filter); | ||
|
||
$this->dispatcher->dispatch(ImagineEvents::PRE_RESOLVE, new PreResolveEvent($resolver, $path, $filter)); | ||
|
||
$url = $resolver->resolve($path, $filter); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolver, path, amd filter has to be taken from the event |
||
|
||
$this->dispatcher->dispatch(ImagineEvents::POST_RESOLVE, new PostResolveEvent($resolver, $path, $filter, $url)); | ||
|
||
return $url; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace Liip\ImagineBundle; | ||
|
||
|
||
final class ImagineEvents | ||
{ | ||
const PRE_RESOLVE = 'imagine.pre_resolve'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. liip_imagine.xxx |
||
|
||
const POST_RESOLVE = 'imagine.post_resolve'; | ||
|
||
protected function __construct() | ||
{ | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can have only one event class, let's say CacheResolveEvent. In pre event the url will be null of cource.
You should add setters too to allow modify params in the event.