public function testCopy() { // setup SpoonDirectory::create($this->path . '/copy_org'); // copy SpoonDirectory::copy($this->path . '/copy_org', $this->path . '/copy_dest'); // check if both folders exists $var = (bool) (SpoonDirectory::exists($this->path . '/copy_org') && SpoonDirectory::exists($this->path . '/copy_dest')); // assert $this->assertTrue($var); // cleanup SpoonDirectory::delete($this->path . '/copy_org'); SpoonDirectory::delete($this->path . '/copy_dest'); }
/** * Generates the Backend files (module.js, sequence.php) */ protected function generateBackendFiles() { // generate module.js file if ($this->record['multipleImages']) { $this->variables['multiJs'] = BackendModuleMakerGenerator::generateSnippet('Backend/Js/Snippets/Multifiles.base.js', $this->variables); } else { $this->variables['multiJs'] = ''; } $this->variables['do_meta'] = BackendModuleMakerGenerator::generateSnippet('Backend/Js/Snippets/DoMeta.base.js', $this->record['fields'][$this->record['metaField']]); BackendModuleMakerGenerator::generateFile('Backend/Js/Javascript.base.js', $this->variables, $this->backendPath . 'Js/' . $this->record['camel_case_name'] . '.js'); // classes needed to register module specific services BackendModuleMakerGenerator::generateFile('Backend/DependencyInjection/ModuleExtension.base.php', $this->variables, $this->backendPath . 'DependencyInjection/' . $this->record['camel_case_name'] . 'Extension.php'); BackendModuleMakerGenerator::generateFile('Backend/Resources/config/services.base.yml', $this->variables, $this->backendPath . 'Resources/config/services.yml'); unset($this->variables['multiJs'], $this->variables['do_meta']); // add a sequence Ajax action if necessary if ($this->record['useSequence']) { BackendModuleMakerGenerator::generateFile('Backend/Ajax/Sequence.base.php', $this->variables, $this->backendPath . 'Ajax/Sequence.php'); } // add a sequence categories Ajax action if necessary if ($this->record['useCategories']) { BackendModuleMakerGenerator::generateFile('Backend/Ajax/SequenceCategories.base.php', $this->variables, $this->backendPath . 'Ajax/SequenceCategories.php'); } // add an upload Ajax action if necessary if ($this->record['multipleImages']) { BackendModuleMakerGenerator::generateFile('Backend/Ajax/Upload.base.php', $this->variables, $this->backendPath . 'Ajax/Upload.php'); } // if we use the fineuploader, we should copy the needed js and css files if ($this->record['multipleImages']) { \SpoonDirectory::copy(BACKEND_MODULES_PATH . '/ModuleMaker/Layout/Templates/Backend/Js/fineuploader', $this->backendPath . 'Js/fineuploader'); BackendModuleMakerGenerator::generateFile('Backend/Layout/Css/fineuploader.css', null, $this->backendPath . 'Layout/Css/fineuploader.css'); } }
/** * Saves the image to a file (quality is only used for jpg images). * * @return bool True if the image was saved, false if not. * @param string $filename The path where the image should be saved. * @param int[optional] $quality The quality to use (only applies on jpg-images). * @param int[optional] $chmod Mode that should be applied on the file. */ public function parseToFile($filename, $quality = 100, $chmod = 0666) { // redefine vars $filename = (string) $filename; $quality = (int) $quality; // if (@is_writable(dirname($filename)) !== true) { // does the folder exist? if not, try to create if (!SpoonDirectory::create(dirname($filename))) { if ($this->strict) { throw new SpoonThumbnailException('The destination-path should be writable.'); } return false; } } // get extension $extension = SpoonFile::getExtension($filename); // invalid quality if (!SpoonFilter::isBetween(1, 100, $quality)) { // strict? if ($this->strict) { throw new SpoonThumbnailException('The quality should be between 1 - 100'); } return false; } // invalid extension if (SpoonFilter::getValue($extension, array('gif', 'jpeg', 'jpg', 'png'), '') == '') { if ($this->strict) { throw new SpoonThumbnailException('Only gif, jpeg, jpg or png are allowed types.'); } return false; } // get current dimensions $imageProperties = @getimagesize($this->filename); // validate imageProperties if ($imageProperties === false) { // strict? if ($this->strict) { throw new SpoonThumbnailException('The sourcefile "' . $this->filename . '" could not be found.'); } return false; } // set current dimensions $currentWidth = (int) $imageProperties[0]; $currentHeight = (int) $imageProperties[1]; $currentType = (int) $imageProperties[2]; $currentMime = (string) $imageProperties['mime']; // file is the same? if ($currentType == IMAGETYPE_GIF && $extension == 'gif' || $currentType == IMAGETYPE_JPEG && in_array($extension, array('jpg', 'jpeg')) || $currentType == IMAGETYPE_PNG && $extension == 'png') { if ($currentWidth == $this->width && $currentHeight == $this->height) { return SpoonDirectory::copy($this->filename, $filename, true, true, $chmod); } } // resize image $this->resizeImage($currentWidth, $currentHeight, $currentType, $currentMime); // output to file switch (strtolower($extension)) { case 'gif': $return = @imagegif($this->image, $filename); break; case 'jpeg': case 'jpg': $return = @imagejpeg($this->image, $filename, $quality); break; case 'png': $return = @imagepng($this->image, $filename); break; } // chmod @chmod($filename, $chmod); // cleanup memory @imagedestroy($this->image); // return success return (bool) $return; }