/** * backup single database table to file * * @param string $table * @param string $path */ public function backupTableToFile(string $table, string $path) { $sql = $this->getHeader(); $sql .= $this->backupTable($table); FileSystem::createDir($path); $path .= '/' . $table . '_' . date('Y-m-d_H-i-s') . '.sql'; FileSystem::write($path, $sql); }
private function createAndReturnTempDir() : string { $tempDir = sys_get_temp_dir() . '/php7_codesniffer'; FileSystem::delete($tempDir); FileSystem::createDir($tempDir); return $tempDir; }
public function loadConfiguration() { $builder = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); if (!$config['accounts']) { $config['accounts']['default'] = ['account' => $config['account'], 'token' => $config['token']]; } unset($config['account'], $config['token']); Utils\FileSystem::createDir($config['temp']); // AccountCollection $builder->addDefinition($this->prefix('accounts'))->setClass('h4kuna\\Fio\\Account\\AccountCollection')->setFactory('h4kuna\\Fio\\Account\\AccountCollectionFactory::create', [$config['accounts']]); // XMLFile - lazy $builder->addDefinition($this->prefix('xmlFile'))->setClass('h4kuna\\Fio\\Request\\Pay\\XMLFile')->setArguments([$config['temp']]); // Queue $queue = $builder->addDefinition($this->prefix('queue'))->setClass('h4kuna\\Fio\\Request\\Queue'); if ($config['downloadOptions']) { $setup = new \Nette\DI\Statement('?->setDownloadOptions(?)', [$queue, $config['downloadOptions']]); $queue->setSetup([$setup]); } // JsonTransactionFactory - lazy $builder->addDefinition($this->prefix('jsonTransactionFactory'))->setClass('h4kuna\\Fio\\Response\\Read\\JsonTransactionFactory')->setArguments([$config['transactionClass']]); // Reader - lazy $builder->addDefinition($this->prefix('reader'))->setClass('h4kuna\\Fio\\Request\\Read\\Files\\Json'); // FioFactory $builder->addDefinition($this->prefix('fioFactory'))->setClass('h4kuna\\Fio\\Nette\\FioFactory'); }
public function loadConfiguration() { $builder = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); if (!$config['token']) { throw new FioException('Token is required'); } if (!$config['account']) { throw new FioException('Account is required'); } Utils\FileSystem::createDir($config['temp']); // XMLFile $builder->addDefinition($this->prefix('xmlFile'))->setClass('h4kuna\\Fio\\Request\\Pay\\XMLFile')->setArguments(array($config['temp'])); // PaymentFactory $builder->addDefinition($this->prefix('paymentFactory'))->setClass('h4kuna\\Fio\\Request\\Pay\\PaymentFactory')->setArguments(array($config['account'])); // Queue $builder->addDefinition($this->prefix('queue'))->setClass('h4kuna\\Fio\\Request\\Queue')->setArguments(array($config['temp'])); // Context $builder->addDefinition($this->prefix('context'))->setClass('h4kuna\\Fio\\Utils\\Context')->setArguments(array($config['token'])); // StatementFactory $builder->addDefinition($this->prefix('statementFactory'))->setClass('h4kuna\\Fio\\Response\\Read\\JsonStatementFactory')->setArguments(array($config['transactionClass'])); // FioPay $builder->addDefinition($this->prefix('fioPay'))->setClass('h4kuna\\Fio\\FioPay'); // FioRead $builder->addDefinition($this->prefix('fioRead'))->setClass('h4kuna\\Fio\\FioRead')->setArguments(array($this->prefix('@context'))); }
public function loadConfiguration() { parent::loadConfiguration(); $builder = $this->getContainerBuilder(); $cacheDir = $builder->parameters[self::CACHE_DIR]; $imagesDir = $builder->parameters[self::IMAGES_DIR]; $servicesCacheDir = $cacheDir . "services"; $moduleCacheDir = $servicesCacheDir . "/" . $this->getModuleName(); if (!file_exists($servicesCacheDir)) { try { FileSystem::createDir($servicesCacheDir); } catch (Nette\IOException $ex) { throw new Exceptions\InsufficientPermissionException("Permission denied while creating {$servicesCacheDir} directory"); } } if (!file_exists($moduleCacheDir)) { try { FileSystem::createDir($moduleCacheDir); } catch (Nette\IOException $ex) { throw new Exceptions\InsufficientPermissionException("Permission denied while creating {$moduleCacheDir} directory"); } } if (!file_exists($imagesDir)) { try { FileSystem::createDir($imagesDir); } catch (Nette\IOException $ex) { throw new Exceptions\InsufficientPermissionException("Permission denied while creating {$imagesDir} directory"); } } }
/** * @param string $directory */ public function __construct($directory) { Nette\Utils\SafeStream::register(); $directory = rtrim($directory, DIRECTORY_SEPARATOR); FileSystem::createDir($directory); $this->directory = $directory; }
/** * @inheritdoc */ protected function copyToBinFolder($binDir) { FileSystem::createDir($binDir); $source = $this->targetDir . '/bin/casperjs'; $target = $binDir . '/casperjs'; Cli::makeSymbolicLink($source, $target); }
/** * @param string $root * @return $this */ public function setRoot($root) { if (!file_exists($root)) { Nette\Utils\FileSystem::createDir($root); } $this->root = realpath($root); return $this; }
/** * @param $directory * @return $this */ public function setOutputDirectory($directory) { $this->outputDir = $directory; if (!file_exists($this->outputDir)) { Nette\Utils\FileSystem::createDir($this->outputDir, 0766); } return $this; }
/** * @param string $cacheStoragePath * @return Cache */ protected function create($cacheStoragePath) { if (!file_exists($cacheStoragePath)) { FileSystem::createDir($cacheStoragePath); } $journal = new SQLiteJournal($this->storagePath . '/cached-pdfs-journal'); $fileStorage = new FileStorage($cacheStoragePath, $journal); return new Cache($fileStorage, 'cached-pdfs'); }
/** * @return Magic provides fluent interface */ public function cast() { Nette\Utils\FileSystem::createDir($this->fullPath); if (!file_exists($this->fullPath . '/copied')) { Nette\Utils\FileSystem::copy(__DIR__ . '/resources', $this->fullPath); } $this->useMagic = TRUE; return $this; }
/** * @param $idGallery * @param FileUpload[] $images */ public function uploadImages($idGallery, $lang, array $images) { FileSystem::createDir(galleryPath . $idGallery . '_' . $lang); if (!empty($images)) { foreach ($images as $image) { $this->gallery->upload($idGallery, $lang, $image); } } }
/** * @param Nette\Application\UI\Form $form * @param $values */ public function createFormSubmitted(Nette\Application\UI\Form $form, $values) { if ($this->fileManager->isFeatureEnabled('createDir') && $form->submitted === $form['create']) { $dir = self::getPath($this, $values->name); Nette\Utils\FileSystem::createDir($dir, $this->createDirPermissions); $this->onDirCreate($dir); $this->flashMessage('fileManager.alert.dirCreated', 'success'); } $this->directoryList->go('this', ['view' => 'Default']); }
protected function processImageUpload(Nette\Http\FileUpload $upload, $targetDir, $id) { $dir = 'upload' . DIRECTORY_SEPARATOR . $targetDir . DIRECTORY_SEPARATOR . $id; if (!file_exists($this->rootDir . DIRECTORY_SEPARATOR . $dir)) { Nette\Utils\FileSystem::createDir($this->rootDir . DIRECTORY_SEPARATOR . $dir); } $path = $dir . DIRECTORY_SEPARATOR . $upload->getSanitizedName(); $upload->move($this->rootDir . DIRECTORY_SEPARATOR . $path); return $path; }
/** * @param Photoset $photoset * @param boolean $noSlug * @param boolean $dryRun * @param string $dir * @param boolean $cleanDir * @return string */ private function managePhotosetDir(Photoset $photoset, $noSlug, $dryRun, $dir, $cleanDir) { $dirName = $this->dirnameCreator->create($photoset, $dir, $noSlug); if ($cleanDir && is_dir($dirName) && !$dryRun) { \Nette\Utils\FileSystem::delete($dirName); } if (!is_dir($dirName) && !$dryRun) { \Nette\Utils\FileSystem::createDir($dirName); } return $dirName; }
/** * @param $path * @return string * @throws IOException */ private function prepareStoragePath($path) { if (!file_exists($path) and is_dir($path)) { try { FileSystem::createDir($path); } catch (IOException $e) { $this->logger->addCritical(sprintf('DIR creation failure: %s', $e)); throw $e; } } return $path; }
/** * PdfGenerator constructor. * * @param $documentStorage * @param $tempDir */ public function __construct($documentStorage, $tempDir) { define("_MPDF_TEMP_PATH", $tempDir . "/cache/mPdf/tmp/"); define('_MPDF_TTFONTDATAPATH', $tempDir . "/cache/mPdf/ttfontdata/"); $this->documentStorage = $documentStorage; if (!file_exists(_MPDF_TEMP_PATH)) { FileSystem::createDir(_MPDF_TEMP_PATH); } if (!file_exists(_MPDF_TTFONTDATAPATH)) { FileSystem::createDir(_MPDF_TTFONTDATAPATH); } }
/** * @param Utils\Image|string $sourceFile * @param string $name * @param string $resolution * @param int $method * @return ImagePath */ public function saveFile($sourceFile, $name, $resolution, $method) { $filename = $this->path->getFilesystem($name, $resolution, $method); Utils\FileSystem::createDir(dirname($filename)); if ($sourceFile instanceof Utils\Image) { $resolutionArray = explode('x', $resolution); $sourceFile->resize($resolutionArray[0], $resolutionArray[1], (int) $method)->save($filename); } elseif (!$this->download->save($sourceFile, $filename)) { throw new ImageManager\RemoteFileDoesNotExistsException($sourceFile); } return new ImagePath($this->getPathUrl($name, $resolution, $method), $filename); }
/** * @param string $srcPath * @param string $destPath * @param array $options * @return array */ protected function createImage($srcPath, $destPath, array $options = []) { if (!$options) { $options = $this->config; } try { $imagick = new Imagick(); Nette\Utils\FileSystem::createDir(dirname($destPath)); $imagick->readImage($srcPath); $mimetype = $imagick->getImageMimeType(); if ($imagick->getImageWidth() > $options['width'] || $imagick->getImageHeight() > $options['height']) { $imagick->resizeImage($options['width'], $options['height'], Imagick::FILTER_BESSEL, 0.7, TRUE); } if ($options['square']) { $squareColor = 'gray97'; if ($mimetype === image_type_to_mime_type(IMAGETYPE_PNG) && $imagick->getImageAlphaChannel() === Imagick::ALPHACHANNEL_TRANSPARENT) { $squareColor = 'transparent'; } $blank = new Imagick(); $squareWidth = $options['width']; $squareHeight = $options['height']; if ($imagick->getImageWidth() < $squareWidth && $imagick->getImageHeight() < $squareHeight) { $squareWidth = $imagick->getImageWidth(); $squareHeight = $imagick->getImageHeight(); } if ($imagick->getImageColorspace() === Imagick::COLORSPACE_CMYK) { $imagick->negateImage(FALSE); } $blank->newImage($squareWidth, $squareHeight, $squareColor); $blank->setImageFormat('png'); $blank->compositeImage($imagick, Imagick::COMPOSITE_OVER, $squareWidth / 2 - $imagick->getImageWidth() / 2, $squareHeight / 2 - $imagick->getImageHeight() / 2); $imagick = $blank; } if ($options['compression']) { switch ($mimetype) { case image_type_to_mime_type(IMAGETYPE_JPEG): $imagick->setImageCompression(Imagick::COMPRESSION_JPEG); $imagick->setImageCompressionQuality($options['compression']); break; case image_type_to_mime_type(IMAGETYPE_PNG): case image_type_to_mime_type(IMAGETYPE_GIF): $imagick->setCompressionQuality($options['compression']); break; } } $imagick->writeImage($destPath); return [$imagick->getImageWidth(), $imagick->getImageHeight()]; } catch (\ImagickException $e) { trigger_error($e, E_USER_WARNING); return []; } }
/** * @param Utils\Image $image * @param string $path * @param string $extension * @return Image */ public function saveImage(Utils\Image $image, $path, $extension) { do { $relativePath = self::addSlashPath($path) . md5(microtime()) . '.' . strtolower($extension); $filename = $this->path->getSourceDir($relativePath); } while (is_file($filename)); if ($this->maxSize) { $image->resize($this->maxSize['width'], $this->maxSize['height'], Utils\Image::SHRINK_ONLY); } Utils\FileSystem::createDir(dirname($filename)); $image->save($filename); return new Image($this->path->getSourceDir(''), $relativePath); }
/** * Setting templating system. * @return Engine */ private function createLatteEngine() { // Create directory. $temp = $this->temp . '/_Latte.TemplateCache'; if (!is_dir($temp)) { FileSystem::createDir($temp); } $latte = new Engine(); $latte->setTempDirectory($temp); // Macro for forms. $latte->onCompile[] = function ($latte) { FormMacros::install($latte->getCompiler()); }; return $latte; }
/** * Copies the SlimerJS binary to the bin folder * * @param string $binDir * @throws \Canterville\RuntimeException */ protected function copyToBinFolder($binDir) { FileSystem::createDir($binDir); $os = Helpers::getOS(); if ($os === Helpers::OS_WINDOWS) { $source = $this->targetDir . '/slimerjs.bat'; $target = $binDir . '/slimerjs.bat'; } elseif (isset($os)) { $source = $this->targetDir . '/slimerjs'; $target = $binDir . '/slimerjs'; } else { throw new RuntimeException('Cannot copy binary file of SlimerJS. OS not detect.'); } Cli::makeSymbolicLink($source, $target); }
/** * @param \FlickrDownloadr\Photo\Photo $photo * @param string $filename * @param string $dirname * @return int Number of bytes that were written to the file, or FALSE on failure */ public function download(Photo $photo, $filename, $dirname) { $url = $photo->getUrl(); if ($this->dryRun) { return 0; } \Nette\Utils\FileSystem::createDir($dirname . '/' . dirname($filename)); $this->setupProgressBar(); $ctx = stream_context_create(); stream_context_set_params($ctx, array("notification" => $this->getNotificationCallback($filename))); $bytes = file_put_contents($dirname . '/' . $filename, fopen($url, 'r', FALSE, $ctx)); if ($bytes === FALSE) { $this->progress->setMessage('<error>Error!</error>', 'final_report'); } else { list($time, $size, $speed) = $this->getFinalStats($this->progress->getMaxSteps(), $this->progress->getStartTime()); $this->progress->setMessage('<comment>[' . $size . ' in ' . $time . ' (' . $speed . ')]</comment>', 'final_report'); $this->progress->setFormat('%message% %final_report%' . "\n"); } $this->progress->finish(); $this->output->writeln(''); return $bytes; }
public function save($sourceFile, $originalName, $path, $thumbs = array()) { if (!file_exists($this->root)) { throw new \Nette\IOException("FileBackend root doesn't exists '{$this->root}'"); } if (!file_exists($sourceFile)) { throw new \Nette\IOException("Source file '{$sourceFile}' doesn't exists "); } FileSystem::createDir($this->root . $path); $originalName = Strings::toAscii($originalName); $targetFile = $path . DIRECTORY_SEPARATOR . $originalName; $targetFullPath = $this->root . $targetFile; FileSystem::copy($sourceFile, $targetFullPath); foreach ($thumbs as $thumb => $thumbPath) { if (!file_exists($thumbPath)) { throw new \Nette\IOException("Thumb doesn't exists '{$thumbPath}'"); } $targetThumbPath = $this->root . $path . DIRECTORY_SEPARATOR . $thumb . '_' . $originalName; FileSystem::copy($thumbPath, $targetThumbPath); } return $path . DIRECTORY_SEPARATOR . $originalName; }
/** * @param string $file * @param int $width * @param int $height * @param string $fileType * @param int $quality on percentage scale from 0 to 100 (only for JPEG and PNG) * * @return string Thumbnail image path */ public static function thumbnalize($file, $width = null, $height = null, $fileType = self::TYPE_PNG, $quality = self::QUALITY_MEDIUM) { $file = static::$wwwDir . '/' . $file; if (!is_file($file)) { return; } switch ($fileType) { case self::TYPE_JPEG: $type = Image::JPEG; break; case self::TYPE_PNG: $type = Image::PNG; break; case self::TYPE_GIF: $type = Image::GIF; break; default: $type = Image::PNG; break; } $fileName = self::getFileName($file, $fileType); $destinationDir = $width . '_' . $height . '/' . $fileType . '/' . $quality; $thumbDir = static::$wwwDir . static::$thumbDir; if (file_exists($thumbDir . '/' . $destinationDir . '/' . $fileName)) { return static::$thumbDir . '/' . $destinationDir . '/' . $fileName; } static::$image = Image::fromFile($file); if (static::isWidthSet($width) && static::isHeightSet($height)) { static::resizeImageExactly($width, $height); } elseif (static::isWidthSet($width)) { static::resizeImageProportionally($width, $height); } else { static::resizeImageProportionally(static::$image->getWidth(), $height); } FileSystem::createDir($thumbDir . '/' . $destinationDir); static::$image->save($thumbDir . '/' . $destinationDir . '/' . $fileName, $quality, $type); return static::$thumbDir . '/' . $destinationDir . '/' . $fileName; }
function showMyTemplates() { $customer = $this->add('xepan\\commerce\\Model_Customer'); $customer->loadLoggedIn(); $template_grid = $this->add('xepan\\base\\Grid', null, 'my_template', ['view\\tool\\mytemplate']); $template_grid->setModel('xepan\\epanservices\\Model_MyTemplates'); $template_grid->addHook('formatRow', function ($g) { $item = $this->add('xepan\\commerce\\Model_Item')->load($g->model->id); $g->current_row_html['preview_image'] = $item['first_image']; $g->current_row_html['preview_url'] = 'http://' . $item['sku'] . '.epan.in'; }); $vp = $this->add('VirtualPage'); $vp->set(function ($p) { $item_id = $this->app->stickyGET('item_id'); $item = $p->add('xepan\\commerce\\Model_Item')->load($item_id); $template_name = $item['sku']; if (!file_exists(realpath($this->app->pathfinder->base_location->base_path . '/websites/' . $template_name))) { throw new \Exception('Template not found: Folder do not exist in websites.'); } $customer = $p->add('xepan\\commerce\\Model_Customer'); $customer->loadLoggedIn(); $epan = $p->add('xepan\\epanservices\\Model_Epan'); $epan->addCondition('created_by_id', $customer->id); $form = $p->add('Form'); $form->addField('xepan\\commerce\\DropDown', 'epan')->setModel($epan); if ($form->isSubmitted()) { $model_epan = $p->add('xepan\\epanservices\\Model_Epan')->load($form['epan']); $folder_name = $model_epan['name']; if (!$model_epan->loaded()) { throw new \Exception("Epan model not loaded"); } // NUMBER OF TEMPLATES (NUMBER OF THIS TEMPLATE PURCHASED?) $epan_template = $this->add('xepan\\epanservices\\Model_MyTemplates'); $epan_template->addCondition('id', $item_id); $template_count = $epan_template->count()->getOne(); // NUMBER OF EPANS ON WHICH THIS TEMPLATE IS APPLIED $applied_count_epan = $this->add('xepan\\epanservices\\Model_Epan'); $applied_count_epan->addCondition('created_by_id', $customer->id); $applied_count_epan->addCondition('xepan_template_id', $item_id); $epan_count = $applied_count_epan->count()->getOne(); // NO MORE TEMPLATES LEFT TO APPLY if ($epan_count == $template_count) { return $form->error('epan', 'You have already applied this template. Please buy or use any other template'); } if (file_exists(realpath($this->app->pathfinder->base_location->base_path . '/websites/' . $folder_name . '/www'))) { $fs = \Nette\Utils\FileSystem::delete('./websites/' . $folder_name . '/www'); } $fs = \Nette\Utils\FileSystem::createDir('./websites/' . $folder_name . '/www'); $fs = \Nette\Utils\FileSystem::copy('./websites/' . $template_name, './websites/' . $folder_name . '/www', true); $model_epan['xepan_template_id'] = $item_id; $model_epan->save(); return $form->js()->univ()->successMessage('Template Applied')->execute(); } }); $template_grid->on('click', '.xepan-change-template', function ($js, $data) use($vp) { return $js->univ()->dialogURL("APPLY NEW TEMPLATE", $this->api->url($vp->getURL(), ['item_id' => $data['id']])); }); }
/** * Sets directory with thumbnails * * @param string $thumbnailsDirectory * @throws \Imager\NotExistsException * @throws \Imager\BadPermissionException */ private function setThumbnailsDirectory($thumbnailsDirectory) { $thumbnailsDirectory = Strings::trim($thumbnailsDirectory); $thumbnailsDirectory = rtrim($thumbnailsDirectory, DIRECTORY_SEPARATOR); if (!is_dir($thumbnailsDirectory)) { try { FileSystem::createDir($thumbnailsDirectory); } catch (Nette\IOException $e) { $msg = sprintf('Directory "%s" with thumbnails not exists and cannot be create.', $thumbnailsDirectory); throw new NotExistsException($msg, 0, $e); } } if (!is_writable($thumbnailsDirectory)) { $msg = sprintf('Directory "%s" with thumbnails is not writable.', $thumbnailsDirectory); throw new BadPermissionException($msg); } $this->thumbnailsDirectory = $thumbnailsDirectory . DIRECTORY_SEPARATOR; }
/** * gets image cache on https domain * * @param string $url absolute url * @param bool $allowFailure return source url on failure? * @return string thumb url, FALSE on failure if $allowFailure set to TRUE */ public function cachedImage($url, $allowFailure = TRUE) { FileSystem::createDir($this->cacheDir); $a = explode('.', $url); $ext = strtolower(array_pop($a)); $name = md5($url) . ".{$ext}"; $thumbPath = $this->cacheDir . '/' . $name; $thumbUrl = $this->cacheDirUrl . '/' . $name; // thumb already exits if (is_file($thumbPath)) { return $thumbUrl; } try { if (class_exists('Imagick')) { $image = new Imagick($url); $image->writeImage($thumbPath); $image->destroy(); } else { $image = Image::fromFile($url); $image->alphaBlending(FALSE); $image->saveAlpha(TRUE); $image->save($thumbPath); } return $thumbUrl; } catch (\Exception $e) { return $allowFailure ? $url : FALSE; } }
/** * @param string $tempDir * @param Sender $sender */ public function __construct($tempDir, Sender $sender) { $this->tempDir = $tempDir; $this->sender = $sender; FileSystem::createDir($this->tempDir); }
/** * @param $name */ private function createLayerDir($name) { FileSystem::createDir($this->target . "/{$name}"); }