/** * Process the payload of an object * * @param string $payload Payload * @return string Processed payload * @throws InvalidArgumentException If the payload is not a valid file * @throws RuntimeException If the payload resource cannot be imported */ public function processPayload($payload) { // If the payload is not a valid file if (!strlen($payload) || !is_file($payload)) { throw new InvalidArgumentException(sprintf('Invalid binary payload source "%s"', $payload), InvalidArgumentException::INVALID_BINARY_PAYLOAD_SOURCE); } $adapterStrategy = $this->object->getRepositoryLocator()->getRepository()->getAdapterStrategy(); $currentPayload = $this->object->getPayload(); $currentPayloadHash = strlen($currentPayload) ? $adapterStrategy->getResourceHash($currentPayload) : null; $payloadHash = File::hash($payload); // If there is no payload yet or if it's different from the current one if ($currentPayloadHash === null || $currentPayloadHash !== $payloadHash) { $payloadFileExt = pathinfo($payload, PATHINFO_EXTENSION); $currentPayload = $this->object->getId()->getId() . '.' . $payloadHash; $currentPayload .= strlen($payloadFileExt) ? '.' . $payloadFileExt : ''; // Register the resource in the persistence queue $this->persistQueue[$payload] = $currentPayload; } return $currentPayload; }
/** * Return an individual hash for a resource * * @param string $resourcePath Repository relative resource path * @return string|null Resource hash */ public function getResourceHash($resourcePath) { return $this->hasResource($this->root . $resourcePath) ? File::hash($this->root . $resourcePath) : null; }