/**
  * @param Identifiable $identifiable
  * @return string
  * @throws RuntimeException
  */
 public function createKeyFromIdentifiable(Identifiable $identifiable)
 {
     if (!$identifiable->getId()) {
         throw new RuntimeException("Identifiable is missing an id");
     }
     return $this->createKeyFromParts($identifiable->getId(), get_class($identifiable));
 }
 /**
  * @test
  * @dataProvider provideData
  */
 public function deniedPermissionShouldDispatchEventAndThrowException($method, $expectedMethod, $expectedException, Identifiable $identifiable)
 {
     $this->adapter->expects($this->once())->method($expectedMethod)->will($this->returnValue(false));
     $class = $identifiable instanceof File ? 'file' : 'folder';
     $this->setExpectedException('Xi\\Filelib\\Authorization\\AccessDeniedException', "{$expectedException} access to {$class} #{$identifiable->getId()} was denied");
     $this->ed->expects($this->once())->method('dispatch')->with(Events::BEFORE_DENY_ACCESS, $this->isInstanceOf('Xi\\Filelib\\Event\\IdentifiableEvent'));
     $plugin = new AuthorizationPlugin($this->adapter);
     $plugin->attachTo($this->filelib);
     if ($identifiable instanceof File) {
         $event = new FileEvent($identifiable);
     } else {
         $event = new FolderEvent($identifiable);
     }
     $plugin->{$method}($event);
 }
Esempio n. 3
0
 /**
  * @test
  * @dataProvider provideIdentifiables
  */
 public function doesntFind(Identifiable $obj)
 {
     $cached = $this->cache->findById($obj->getId(), get_class($obj));
     $this->assertFalse($cached);
 }
Esempio n. 4
0
 /**
  * @param Identifiable $identifiable
  * @return FindByIdsRequest
  */
 public function found(Identifiable $identifiable)
 {
     $key = array_search($identifiable->getId(), $this->notFoundIds);
     if ($key !== null) {
         unset($this->notFoundIds[$key]);
         $this->foundIds[] = $identifiable->getId();
         $this->foundObjects[] = $identifiable;
         if ($this->isOrigin && $this->eventDispatcher) {
             $this->eventDispatcher->dispatch(Events::IDENTIFIABLE_INSTANTIATE, new IdentifiableEvent($identifiable));
         }
     }
     return $this;
 }