예제 #1
0
파일: AudioTest.php 프로젝트: zfury/cmf
 /**
  * Tests path generator from public
  * @throws \Exception
  */
 public function testPrepareDir()
 {
     $audioPath = $this->audioService->audioPath($this->audioId, $this->audioEntityData['extension']);
     $this->assertTrue($this->audioService->prepareDir($audioPath));
 }
예제 #2
0
파일: File.php 프로젝트: zfury/cmf
 /**
  * @param int $thumbSize
  * @return null|string
  * @throws \Exception
  */
 public function getThumb($thumbSize = Image::SMALL_THUMB)
 {
     switch ($this->type) {
         case self::IMAGE_FILETYPE:
             $ext = $this->getExtension();
             $imageId = $this->getId();
             $urlPart = Image::imgPath($thumbSize, $imageId, $ext, FileService::FROM_PUBLIC);
             if (!file_exists($urlPart)) {
                 $originalLocation = $this->getLocation();
                 $image = new \Imagick($originalLocation);
                 $size = Image::sizeByType($thumbSize);
                 $image->cropThumbnailImage($size['width'], $size['height']);
                 FileService::prepareDir(FileService::PUBLIC_PATH . $urlPart);
                 $image->writeimage(FileService::PUBLIC_PATH . $urlPart);
             }
             return $urlPart;
         case self::AUDIO_FILETYPE:
             return Audio::audioPath($this->id, $this->getExtension(), FileService::FROM_PUBLIC);
         case self::VIDEO_FILETYPE:
             return Video::videoPath($this->id, $this->getExtension(), FileService::FROM_PUBLIC);
         default:
     }
     return null;
 }
예제 #3
0
파일: File.php 프로젝트: zfury/cmf
 /**
  * Writes file to a DB and moves it to an appropriate path
  *
  * @param FileUpload $form
  * @return FileEntity
  * @throws \Exception
  */
 public function writeFile(FileUpload $form)
 {
     $ext = $this->getExt($form->getData()[$form->getFileType()]['name']);
     $type = $form->getFileType();
     //Creating new image to get ID for building its path
     $file = new FileEntity();
     $file->setExtension($ext);
     $file->setType($type);
     $this->sm->get('doctrine.entitymanager.orm_default')->persist($file);
     $this->sm->get('doctrine.entitymanager.orm_default')->flush();
     //Building path and creating directory. Then - moving
     $destination = null;
     switch ($type) {
         case FileEntity::AUDIO_FILETYPE:
             $destination = Audio::audioPath($file->getId(), $ext);
             break;
         case FileEntity::VIDEO_FILETYPE:
             $destination = Video::videoPath($file->getId(), $ext);
             break;
         case FileEntity::IMAGE_FILETYPE:
             $destination = Image::imgPath(Image::ORIGINAL, $file->getId(), $ext);
             break;
         default:
     }
     $this->prepareDir($destination);
     $this->moveFile($destination, $form->getData()[$type]);
     return $file;
 }