1111
1212use Symfony \Component \DependencyInjection \ContainerInterface ;
1313use Symfony \Component \HttpFoundation \Request ;
14- use Webfactory \HttpCacheBundle \NotModified \VoterInterface ;
14+ use Webfactory \HttpCacheBundle \NotModified \LastModifiedDeterminator ;
1515
1616/**
17- * This Annotation determines the last modified date over all of its parameterised voters . This date is used by the
18- * \Webfactory\HttpCacheBundle\NotModified\EventListener to possibly replace the execution of a controller with
17+ * This Annotation determines the latest last modified date over all of its LastModifiedDeterminators . This date is used
18+ * by the \Webfactory\HttpCacheBundle\NotModified\EventListener to possibly replace the execution of a controller with
1919 * sending a Not Modified HTTP response.
2020 *
2121 * @Annotation
@@ -25,8 +25,8 @@ final class ReplaceWithNotModifiedResponse
2525 /** @var array */
2626 private $ parameters ;
2727
28- /** @var VoterInterface [] */
29- private $ voters ;
28+ /** @var LastModifiedDeterminator [] */
29+ private $ lastModifiedDeterminators ;
3030
3131 /** @var ContainerInterface */
3232 private $ container ;
@@ -48,12 +48,12 @@ public function __construct(array $parameters)
4848 */
4949 public function determineLastModified (Request $ request )
5050 {
51- $ this ->initialiseVoters ();
51+ $ this ->initialiseLastModifiedDeterminators ();
5252
53- foreach ($ this ->voters as $ voter ) {
54- $ lastModifiedOfCurrentVoter = $ voter ->getLastModified ($ request );
55- if ($ this ->lastModified === null || $ this ->lastModified < $ lastModifiedOfCurrentVoter ) {
56- $ this ->lastModified = $ lastModifiedOfCurrentVoter ;
53+ foreach ($ this ->lastModifiedDeterminators as $ lastModifiedDeterminator ) {
54+ $ lastModifiedOfCurrentDeterminator = $ lastModifiedDeterminator ->getLastModified ($ request );
55+ if ($ this ->lastModified === null || $ this ->lastModified < $ lastModifiedOfCurrentDeterminator ) {
56+ $ this ->lastModified = $ lastModifiedOfCurrentDeterminator ;
5757 }
5858 }
5959
@@ -68,36 +68,36 @@ public function setContainer(ContainerInterface $container)
6868 $ this ->container = $ container ;
6969 }
7070
71- private function initialiseVoters ()
71+ private function initialiseLastModifiedDeterminators ()
7272 {
73- if (! array_key_exists ( ' voters ' , $ this -> parameters ) || count ($ this ->parameters ['voters ' ]) === 0 ) {
74- throw new \RuntimeException ('The annotation ' . get_class ($ this ) . ' has to be parametrised with voters . ' );
73+ if (count ($ this ->parameters ['value ' ]) === 0 ) {
74+ throw new \RuntimeException ('The annotation ' . get_class ($ this ) . ' has to be parametrised with LastModifiedDeterminators . ' );
7575 }
7676
77- foreach ($ this ->parameters ['voters ' ] as $ voterDescription ) {
78- $ voter = null ;
77+ foreach ($ this ->parameters ['value ' ] as $ lastModifiedDeterminatorDescription ) {
78+ $ lastModifiedDeterminator = null ;
7979
80- if (is_string ($ voterDescription )) {
81- if ($ voterDescription [0 ] === '@ ' ) {
82- $ voter = $ this ->container ->get ($ voterDescription );
80+ if (is_string ($ lastModifiedDeterminatorDescription )) {
81+ if ($ lastModifiedDeterminatorDescription [0 ] === '@ ' ) {
82+ $ lastModifiedDeterminator = $ this ->container ->get ($ lastModifiedDeterminatorDescription );
8383 } else {
84- $ voter = new $ voterDescription ;
84+ $ lastModifiedDeterminator = new $ lastModifiedDeterminatorDescription ;
8585 }
8686 }
8787
88- if (is_array ($ voterDescription )) {
89- $ voterClass = key ($ voterDescription );
90- $ voterParameter = current ($ voterDescription );
91- $ voter = new $ voterClass ( $ voterParameter );
88+ if (is_array ($ lastModifiedDeterminatorDescription )) {
89+ $ lastModifiedDeterminatorClass = key ($ lastModifiedDeterminatorDescription );
90+ $ lastModifiedDeterminatorParameter = current ($ lastModifiedDeterminatorDescription );
91+ $ lastModifiedDeterminator = new $ lastModifiedDeterminatorClass ( $ lastModifiedDeterminatorParameter );
9292 }
9393
94- if (!($ voter instanceof VoterInterface )) {
94+ if (!($ lastModifiedDeterminator instanceof LastModifiedDeterminator )) {
9595 throw new \RuntimeException (
96- 'The voter class " ' . get_class ($ voter ) . '" does not implement ' . VoterInterface ::class . '. '
96+ 'The class " ' . get_class ($ lastModifiedDeterminator ) . '" does not implement ' . LastModifiedDeterminator ::class . '. '
9797 );
9898 }
9999
100- $ this ->voters [] = $ voter ;
100+ $ this ->lastModifiedDeterminators [] = $ lastModifiedDeterminator ;
101101 }
102102 }
103103}
0 commit comments