/** * {@inheritdoc} */ public function submitPrintJob(Printer $printer, FileInterface $file) { $title = 'file-' . $file->getId(); $parameters = ['printerid' => $printer->getVendorId(), 'title' => $title, 'ticket' => '{ "version": "1.0", "print": {} }', 'content' => new PostFile('content', fopen($file->getLocalPath(), 'r'))]; $response = $this->postRequest('submit', $parameters); $setAt = new \DateTime(); $setAt->setTimestamp(substr($response['job']['createTime'], 0, 10)); $job = new Job(); $job->setFile($file)->setJobId($response['job']['id'])->setMetadata($response['job'])->setPrinter($printer)->setSentAt($setAt)->setStatus($response['job']['status'])->setTitle($response['job']['title']); return $job; }
public function writeContent(FileInterface $file, $content) { if (@is_file($content)) { $content = file_get_contents($content); } if (!($key = $file->getKey())) { throw new \Exception('A key must be set for the File'); } if (!($identifier = $file->getFilesystem())) { $file->setFilesystem($this->defaultFilesystem); $identifier = $this->defaultFilesystem; } $this->filesystems[$identifier]->write($file->getKey(), $content); }
/** * @param \SplFileInfo|FileInterface $file * @throws \InvalidArgumentException */ public function copyContentFromFile($file) { if ($file instanceof \SplFileInfo) { $this->setFileContentFromFilesystem($file->getPathname()); } elseif ($file instanceof BinaryInterface) { $this->setContentFromStream($file->getContentAsStream()); } elseif ($file instanceof FileSystemInterface) { $this->setFileContentFromFilesystem($file->getFileSystemPath()); } elseif ($file instanceof FileInterface) { $this->setContentFromString($file->getContentAsString()); } else { $type = is_object($file) ? get_class($file) : gettype($file); throw new \InvalidArgumentException(sprintf('File is not a valid type, "%s" given.', $type)); } }
/** * Set default values for a new file or directory * * @param string $path Path of the file * @param FileInterface $file * @param DirectoryInterface $parent Parent directory of the file */ protected function setFileDefaults($path, FileInterface $file, DirectoryInterface $parent = null) { $setIdentifier = $this->identifier ? 'set' . ucfirst($this->identifier) : false; $name = $this->getBaseName($path); if ($setIdentifier) { $file->{$setIdentifier}($name); } $file->setName($name); if ($file instanceof HierarchyInterface && $parent && $parent instanceof DirectoryInterface) { $file->setParent($parent); } }