Esempio n. 1
0
 public function testSessionRegistry()
 {
     $factory = new Factory();
     $repository = $this->getRepositoryMock();
     $transport = $this->getTransportStub();
     $transport->expects($this->any())->method('getNamespaces')->will($this->returnValue(array()));
     $s = new Session($factory, $repository, 'workspaceName', new SimpleCredentials('foo', 'bar'), $transport);
     $this->assertSame(Session::getSessionFromRegistry($s->getRegistryKey()), $s);
     $s->logout();
     $this->assertNull(Session::getSessionFromRegistry($s->getRegistryKey()));
 }
Esempio n. 2
0
 public function testSessionRegistry()
 {
     $factory = new Factory();
     $repository = $this->getMock('Jackalope\\Repository', array(), array($factory), '', false);
     $transport = $this->getMockBuilder('Jackalope\\Transport\\TransportInterface')->disableOriginalConstructor()->getMock(array('login', 'logout', 'getRepositoryDescriptors', 'getNamespaces'), array($factory, 'http://example.com'));
     $transport->expects($this->any())->method('getNamespaces')->will($this->returnValue(array()));
     $s = new Session($factory, $repository, 'workspaceName', new SimpleCredentials('foo', 'bar'), $transport);
     $this->assertSame(Session::getSessionFromRegistry($s->getRegistryKey()), $s);
     $s->logout();
     $this->assertNull(Session::getSessionFromRegistry($s->getRegistryKey()));
 }
Esempio n. 3
0
 /**
  * Check whether stream was already loaded, otherwise fetch from backend
  * and cache it.
  *
  * Multivalued properties have a special handling since the backend returns
  * all streams in a single call.
  *
  * Always checks if the current session is still alive.
  *
  * @throws LogicException when trying to use a stream from a closed session
  *      and on trying to access a nonexisting multivalue id.
  *
  * @return void
  */
 private function init_stream()
 {
     if (null === $this->stream) {
         if ($this->session && !$this->session->isLive()) {
             throw new LogicException("Trying to read a stream from a closed transport.");
         }
         $url = parse_url($this->path);
         $this->session = Session::getSessionFromRegistry($url['host']);
         $property_path = $url['path'];
         $token = isset($url['user']) ? $url['user'] : null;
         if (null === $token) {
             $this->stream = $this->session->getObjectManager()->getBinaryStream($property_path);
         } else {
             // check if streams have been loaded for multivalued properties
             if (!isset(self::$multiValueMap[$token])) {
                 self::$multiValueMap[$token] = $this->session->getObjectManager()->getBinaryStream($property_path);
             }
             $index = isset($url['port']) ? $url['port'] - 1 : 0;
             if (!isset(self::$multiValueMap[$token][$index])) {
                 throw new LogicException("Trying to read a stream from a non existant token '{$token}' or token index '{$index}'.");
             }
             $this->stream = self::$multiValueMap[$token][$index];
         }
     }
 }