Example #1
0
 /**
  * Construct a new EventJournal by extracting the $data that comes from the server.
  *
  * The journal does also receive the filter criteria so that if the server didn't filter the events,
  * there is still a chance to do so here. This class will consider that the journal was already
  * filtered by the server if it gets null in all the criterion parameter, that is if $eventTypes,
  * $absPath, $isDeep, $uuid and $nodeTypeName are all equal to null.
  *
  * We need the session in the event journal because if the backend didn't do any filtering on the
  * events, it's up to the EventJournal to do it. And some filter criteria require to access the parent
  * nodes which can only be done with the session.
  *
  * @param \Jackalope\FactoryInterface $factory
  * @param \PHPCR\SessionInterface $session
  * @param \DOMDocument $data The DOM data received from the DAVEX call to the server (might be already filtered or not)
  * @param int $eventTypes
  * @param string $absPath
  * @param boolean $isDeep
  * @param array $uuid
  * @param array $nodeTypeName
  * @param string $workspaceRootUri The prefix to extract the path from the event href attribute
  * @return \Jackalope\Observation\EventJournal
  *
  */
 public function __construct(FactoryInterface $factory, SessionInterface $session, \DOMDocument $data, $eventTypes = null, $absPath = null, $isDeep = null, array $uuid = null, array $nodeTypeName = null, $workspaceRootUri = '')
 {
     $this->factory = $factory;
     $this->session = $session;
     $this->workspaceRootUri = $workspaceRootUri;
     $this->eventTypesCriterion = $eventTypes;
     $this->absPathCriterion = $absPath;
     $this->isDeepCriterion = $isDeep;
     $this->uuidCriterion = $uuid;
     $this->nodeTypeNameCriterion = $nodeTypeName;
     // Construct the journal with the transport response
     $events = $this->constructEventJournal($data);
     // Filter the events if required
     if ($eventTypes !== null || $absPath !== null || $isDeep !== null || $uuid !== null || $nodeTypeName !== null) {
         $filter = EventFilterChain::constructFilterChain($this->session, $eventTypes, $absPath, $isDeep, $uuid, $nodeTypeName);
         $events = $this->filterEvents($filter, $events);
     }
     parent::__construct($events);
 }
 public function testFactory()
 {
     $session = $this->getSessionMock(array('getNodes', 'getNodesByIdentifier'));
     $session->expects($this->any())->method('getNodes')->will($this->returnValue(null));
     $session->expects($this->any())->method('getNodesByIdentifier')->will($this->returnValue(array()));
     $eventTypeFilter = new Filter\EventTypeEventFilter(123);
     $pathFilter = new Filter\PathEventFilter('/somepath', true);
     $uuidFilter = new Filter\UuidEventFilter($session, array('1', '2', '3'));
     $nodeTypeFilter = new Filter\NodeTypeEventFilter($session, array('nodeType'));
     $filter = EventFilterChain::constructFilterChain($session);
     $this->assertEquals(array(), $this->getAttributeValue($filter, 'filters'));
     $filter = EventFilterChain::constructFilterChain($session, 123);
     $this->assertEquals(array($eventTypeFilter), $this->getAttributeValue($filter, 'filters'));
     $filter = EventFilterChain::constructFilterChain($session, null, '/somepath', true);
     $this->assertEquals(array($pathFilter), $this->getAttributeValue($filter, 'filters'));
     $filter = EventFilterChain::constructFilterChain($session, null, null, null, array('1', '2', '3'));
     $this->assertEquals(array($uuidFilter), $this->getAttributeValue($filter, 'filters'));
     $filter = EventFilterChain::constructFilterChain($session, null, null, null, null, array('nodeType'));
     $this->assertEquals(array($nodeTypeFilter), $this->getAttributeValue($filter, 'filters'));
     $filter = EventFilterChain::constructFilterChain($session, 123, '/somepath', true, array('1', '2', '3'), array('nodeType'));
     $this->assertEquals(array($eventTypeFilter, $pathFilter, $uuidFilter, $nodeTypeFilter), $this->getAttributeValue($filter, 'filters'));
 }
Example #3
0
 /**
  * Factory method to construct a EventFilterChain from the parameters given to ObservationManager::getJournal
  *
  * @static
  * @param \PHPCR\SessionInterface $session
  * @param int|null $eventTypes
  * @param string|null $absPath
  * @param boolean|null $isDeep
  * @param array|null $uuid
  * @param array|null $nodeTypeName
  * @return EventFilterChain
  */
 public static function constructFilterChain(\PHPCR\SessionInterface $session, $eventTypes = null, $absPath = null, $isDeep = null, array $uuid = null, array $nodeTypeName = null)
 {
     $filter = new EventFilterChain();
     if (!is_null($eventTypes)) {
         $filter->addFilter(new EventTypeEventFilter($eventTypes));
     }
     if (!is_null($absPath)) {
         $filter->addFilter(new PathEventFilter($absPath, $isDeep));
     }
     if (!is_null($uuid)) {
         $filter->addFilter(new UuidEventFilter($session, $uuid));
     }
     if (!is_null($nodeTypeName)) {
         $filter->addFilter(new NodeTypeEventFilter($session, $nodeTypeName));
     }
     return $filter;
 }