/** * {@inheritdoc} */ public function getObjectByContainer(OpenCloudContainer $container, array $objectData) { $object = $container->dataObject(); $object->setName($objectData['name']); if (isset($objectData['content_type'])) { $object->setContentType($objectData['content_type']); } return $object; }
public function uploadFontFiles(Container $container, $fileType, $output) { $output->writeln(sprintf("<info> Uploading </info><comment> %s </comment><info> Files </info>", $fileType)); $finder = new Finder(); $finder->files()->in($this->getContainer()->getParameter("kernel.root_dir") . "/../web/bundles")->name(sprintf("*.%s", $fileType)); $contentType = $this->getContentType($fileType); foreach ($finder as $file) { $uploaded = false; $tryes = 0; while (!$uploaded && $tryes < 5) { try { $tryes++; /** @var SplFileInfo $file */ $container->uploadObject(sprintf("bundles/%s", $file->getRelativePathname()), file_get_contents($file->getRealPath()), ["Access-Control-Allow-Origin" => "*", "Content-Type" => $contentType]); $uploaded = true; $output->writeln(sprintf("<info> Uploaded </info><comment> %s </comment><info> File </info>", $file->getRelativePathname())); } catch (\Exception $e) { if ($tryes >= 5) { $output->writeln(sprintf("<error>Guzzle Returned ServerErrorResponseException - Cancelled Upload </error>")); throw $e; } $output->writeln(sprintf("<error>Guzzle ServerErrorResponseException We will try again in 5 seconds</error>")); sleep(5); } } } }
/** * Get a file's metadata * * @param string $path * @return array file metadata */ public function listContents($directory = '', $recursive = false) { $response = $this->container->objectList(array('prefix' => $directory)); $response = iterator_to_array($response); $contents = array_map(array($this, 'normalizeObject'), $response); return Util::emulateDirectories($contents); }
public function filetype($path) { $path = $this->normalizePath($path); if ($this->doesObjectExist($path)) { $object = $this->container->getPartialObject($path); return $this->getFileType($object); } }
/** * @param $key * @return \OpenCloud\ObjectStore\Resource\DataObject */ protected function tryGetObject($key) { try { return $this->container->DataObject($key); } catch (ObjFetchError $objFetchError) { return false; } }
public function test_Transfer() { // collection $response1 = new Response(200, array('Content-Type' => 'application/json'), '[{"name":"test_obj_1","hash":"4281c348eaf83e70ddce0e07221c3d28","bytes":14,"content_type":"application\\/octet-stream","last_modified":"2009-02-03T05:26:32.612278"}]'); $this->addMockSubscriber($response1); // individual GETs $response2 = new Response(200, array('Content-Type' => 'application/json'), ''); $this->addMockSubscriber($response2); // individual PUTs $response3 = new Response(201); $this->addMockSubscriber($response3); $container = new Container($this->service); $container->setName('foo'); $response = $this->service->migrateContainer($container, $container); $this->assertInternalType('array', $response); $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $response[0]); }
/** * {@inheritdoc} */ public function listContents($directory = '', $recursive = false) { $location = $this->applyPathPrefix($directory); $response = $this->container->objectList(['prefix' => $location]); $response = iterator_to_array($response); $contents = array_map([$this, 'normalizeObject'], $response); return Util::emulateDirectories($contents); }
/** * @param string $key * * @return \OpenCloud\ObjectStore\Resource\DataObject|false */ protected function tryGetObject($key) { try { return $this->container->getObject($key); } catch (ObjectNotFoundException $objFetchError) { return false; } }
public function writeBack($tmpFile) { if (!isset(self::$tmpFiles[$tmpFile])) { return false; } $fileData = fopen($tmpFile, 'r'); $this->container->uploadObject(self::$tmpFiles[$tmpFile], $fileData); unlink($tmpFile); }
/** * Create a tailored PUT request for each file * * @param Response $response * @return \Guzzle\Http\Message\EntityEnclosingRequestInterface */ protected function createPutRequest(Response $response) { $segments = Url::factory($response->getEffectiveUrl())->getPathSegments(); $name = end($segments); // Retrieve content and metadata $file = $this->newContainer->dataObject()->setName($name); $file->setMetadata($response->getHeaders(), true); return $this->getClient()->put($file->getUrl(), $file::stockHeaders($file->getMetadata()->toArray()), $response->getBody()); }
/** * Create a container for this service. * * @param $name The name of the container * @param array $metadata Additional (optional) metadata to associate with the container * @return bool|static */ public function createContainer($name, array $metadata = array()) { $this->checkContainerName($name); $containerHeaders = Container::stockHeaders($metadata); $response = $this->getClient()->put($this->getUrl($name), $containerHeaders)->send(); if ($response->getStatusCode() == 201) { return Container::fromResponse($response, $this); } return false; }
public function filetype($path) { $path = $this->normalizePath($path); if ($this->doesObjectExist($path)) { $object = $this->container->getPartialObject($path); if ($object->getContentType() == 'application/directory') { return 'dir'; } elseif ($object->getContentType() == 'httpd/unix-directory') { return 'dir'; } else { return 'file'; } } }
/** * {@inheritdoc} */ public function listContents($directory = '', $recursive = false) { $response = []; $marker = null; $location = $this->applyPathPrefix($directory); while (true) { $objectList = $this->container->objectList(['prefix' => $location, 'marker' => $marker]); if ($objectList->count() === 0) { break; } $response = array_merge($response, iterator_to_array($objectList)); $marker = end($response)->getName(); } return Util::emulateDirectories(array_map([$this, 'normalizeObject'], $response)); }
/** * @param string $type * @return bool|Url */ public function getPublicUrl($type = UrlType::CDN) { $cdn = $this->container->getCdn(); switch ($type) { case UrlType::CDN: $uri = $cdn->getCdnUri(); break; case UrlType::SSL: $uri = $cdn->getCdnSslUri(); break; case UrlType::STREAMING: $uri = $cdn->getCdnStreamingUri(); break; case UrlType::IOS_STREAMING: $uri = $cdn->getIosStreamingUri(); break; } return isset($uri) ? Url::factory($uri)->addPath($this->name) : false; }
public function deleteContainer($recursive = false) { $this->init(); $this->container->delete($recursive); }
/** * @param BaseContainer $container Parent container * @param $name Name of object */ public function __construct(RendererInterface $renderer, BaseContainer $container, $name) { $this->renderer = $renderer; $this->dataObject = $container->getPartialObject($name); }