예제 #1
0
 /**
  * Creates a resource
  *
  * @param Resource $resource
  * @param string $path
  */
 public function create(Resource $resource, $path)
 {
     $event = new ResourceEvent($resource);
     $this->eventDispatcher->dispatch(Events::RESOURCE_BEFORE_CREATE, $event);
     $resource->setUuid(Uuid::uuid4()->toString());
     $this->backend->createResource($resource);
     // @todo: this has to be correctly robustified.
     try {
         $this->storage->store($resource, $path);
     } catch (\Exception $e) {
         $this->backend->deleteResource($resource);
         throw $e;
     }
     $event = new ResourceEvent($resource);
     $this->eventDispatcher->dispatch(Events::RESOURCE_AFTER_CREATE, $event);
     return $resource;
 }