Neos\ContentRepository\Eel\FlowQueryOperations\CacheLifetimeOperation::evaluate PHP Method

evaluate() public method

public evaluate ( FlowQuery $flowQuery, array $arguments ) : integer
$flowQuery Neos\Eel\FlowQuery\FlowQuery The FlowQuery object
$arguments array None
return integer The cache lifetime in seconds or NULL if either no content collection was given or no child node had a "hiddenBeforeDateTime" or "hiddenAfterDateTime" property set
    public function evaluate(FlowQuery $flowQuery, array $arguments)
    {
        $minimumDateTime = null;
        foreach ($flowQuery->getContext() as $contextNode) {
            $hiddenBeforeDateTime = $contextNode->getHiddenBeforeDateTime();
            if ($hiddenBeforeDateTime !== null && $hiddenBeforeDateTime > $this->now && ($minimumDateTime === null || $hiddenBeforeDateTime < $minimumDateTime)) {
                $minimumDateTime = $hiddenBeforeDateTime;
            }
            $hiddenAfterDateTime = $contextNode->getHiddenAfterDateTime();
            if ($hiddenAfterDateTime !== null && $hiddenAfterDateTime > $this->now && ($minimumDateTime === null || $hiddenAfterDateTime < $minimumDateTime)) {
                $minimumDateTime = $hiddenAfterDateTime;
            }
        }
        if ($minimumDateTime !== null) {
            $maximumLifetime = $minimumDateTime->getTimestamp() - $this->now->getTimestamp();
            if ($maximumLifetime > 0) {
                return $maximumLifetime;
            }
        }
        return null;
    }

Usage Example

 /**
  * @test
  * @dataProvider nodePropertiesAndLifetime
  */
 public function evaluateReturnsMinimumOfFutureHiddenDates($nodes, $expectedLifetime)
 {
     $mockFlowQuery = $this->buildFlowQueryWithNodesInContext($nodes);
     $lifetime = $this->operation->evaluate($mockFlowQuery, array());
     if ($expectedLifetime === null) {
         $this->assertNull($lifetime);
     } else {
         $this->assertEquals($expectedLifetime, $lifetime, 'Lifetime did not match expected value +/- 1', 1);
     }
 }
CacheLifetimeOperation