/** * @param Sport $sport * @param array $data */ protected function postSave(Sport $sport, array $data) { // upload picture if (isset($data['meta']) && isset($data['meta']['filename']) && !empty($data['meta']['filename'])) { $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary'); // ensure directory $dir = new Directory($module->getSportPath($sport)); if (!$dir->exists()) { $dir->make(); } $destpath = $module->getSkillPreviewPath($sport); $dest = new File($destpath); if ($dest->exists()) { $dest->delete(); } $file = new File($module->getUploadPath()->append($data['meta']['filename'])); $imagine = new Imagine(); $image = $imagine->open($file->toPath()->toString()); $image->save($dest->toPath()->toString()); $file->delete(); $sport->setSkillPictureUrl($module->getSkillPreviewUrl($sport)); $sport->save(); } // delete picture if (isset($data['meta']) && isset($data['meta']['skill_picture_delete']) && $data['meta']['skill_picture_delete'] == 1) { $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary'); $path = $module->getSkillPreviewPath($sport); $file = new File($path); $file->delete(); $sport->setSkillPictureUrl(null); $sport->save(); } }
/** * @param Skill $skill * @param mixed $data */ protected function postSave(Skill $skill, $data) { SkillQuery::disableVersioning(); // calculate $calculator = new Calculator(); $calculator->calculate($skill); $calculator->getModifiedGenerationSkills()->each(function (Skill $skill) { LineageQuery::create()->filterBySkillId($skill->getId())->delete(); }); $calculator->getModifiedSkills()->each(function (Skill $skill) { $skill->save(); }); // set sequence picture if (isset($data['meta']) && isset($data['meta']['filename'])) { $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary'); $destpath = $module->getSequencePath($skill); $dest = new File($destpath); if ($dest->exists()) { $dest->delete(); } $file = new File($module->getUploadPath()->append($data['meta']['filename'])); $file->move($destpath); $skill->setSequencePictureUrl($module->getSequenceUrl($skill)); $skill->save(); } SkillQuery::enableVersioning(); // activity $user = $this->getServiceContainer()->getAuthManager()->getUser(); $user->newActivity(array('verb' => $this->isNew ? Activity::VERB_CREATE : Activity::VERB_AUTHOR, 'object' => $skill, 'target' => $skill->getSport())); }
/** * @param Picture $picture * @param array $data */ protected function postSave(Picture $picture, array $data) { if (isset($data['meta']) && isset($data['meta']['filename'])) { $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary'); $file = new File($module->getUploadPath()->append($data['meta']['filename'])); $slugifier = new Slugify(); $filename = sprintf('%s-%u.%s', $slugifier->slugify($picture->getAthlete()), $picture->getId(), $file->getExtension()); $filepath = $module->getPicturesPath($picture->getSkill())->append($filename); $file->move($filepath); // create thumb folder $thumbspath = $module->getPicturesPath($picture->getSkill())->append('thumbs'); $dir = new Directory($thumbspath); if (!$dir->exists()) { $dir->make(); } // create thumb $imagine = new Imagine(); $image = $imagine->open($filepath->toString()); $max = max($image->getSize()->getWidth(), $image->getSize()->getHeight()); $width = $image->getSize()->getWidth() / $max * self::THUMB_MAX_SIZE; $height = $image->getSize()->getHeight() / $max * self::THUMB_MAX_SIZE; $size = new Box($width, $height); $thumbpath = $thumbspath->append($filename); $image->thumbnail($size)->save($thumbpath->toString()); // save to picture $picture->setUrl($module->getPicturesUrl($picture->getSkill()) . '/' . $filename); $picture->setThumbUrl($module->getPicturesUrl($picture->getSkill()) . '/thumbs/' . $filename); $picture->save(); } // activity $user = $this->getServiceContainer()->getAuthManager()->getUser(); $user->newActivity(array('verb' => $this->isNew ? Activity::VERB_UPLOAD : Activity::VERB_EDIT, 'object' => $picture, 'target' => $picture->getSkill())); }
private function fileToArray($filename) { $file = new File($filename); if (!$file->exists()) { throw new FileNotFoundException(sprintf('File not found at: %s', $filename)); } return Json::decode($file->read()); }
/** * * @param string $filename * @throws FileNotFoundException * @throws JsonException * @return static */ public static function fromFile($filename) { $file = new File($filename); if (!$file->exists()) { throw new FileNotFoundException(sprintf('File not found at: %s', $filename)); } $json = Json::decode($file->read()); return new static($json); }
/** * Automatically generated run method * * @param Request $request * @return Response */ public function run(Request $request) { $fileName = $this->getParam('filename'); $file = new File($this->getModule()->getUploadPath()->append($fileName)); if (!$file->exists()) { throw new ResourceNotFoundException(sprintf('File %s does not exist', $fileName)); } $file->delete(); return $this->responder->run($request, new Success()); }
/** * @throws FileNotFoundException * @return AbstractPhpStruct */ public function parse() { $file = new File($this->filename); if (!$file->exists()) { throw new FileNotFoundException(sprintf('File (%s) does not exist.', $this->filename)); } $parser = $this->getParser(); $traverser = new NodeTraverser(); $traverser->addVisitor($this); $traverser->traverse($parser->parse($file->read())); }
/** * * @param AbstractPhpStructVisitor $visitor * @param string $filename * @throws FileNotFoundException * @return AbstractPhpStruct */ public function parse(AbstractPhpStructVisitor $visitor, $filename) { $file = new File($filename); if (!$file->exists()) { throw new FileNotFoundException(sprintf('File (%s) does not exist.', $filename)); } $parser = new Parser(new Emulative()); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $traverser->traverse($parser->parse($file->read())); return $visitor->getStruct(); }
public function testNames() { $file = new File($this->root->url() . '/dir/composer.json'); $this->assertEquals('composer.json', $file->getFilename()); $this->assertEquals($this->root->url() . '/dir', $file->getDirname()); $this->assertEquals($this->root->url() . '/dir/composer.json', $file->getPathname()); $this->assertEquals($this->root->url() . '/dir/composer.json', '' . $file); $this->assertEquals('json', $file->getExtension()); $dir = new Directory($this->root->url() . '/dir'); $this->assertEquals($this->root->url() . '/dir', '' . $dir); $desc = new FileDescriptor($this->root->url() . '/dir/composer.json'); $this->assertEquals($this->root->url() . '/dir/composer.json', '' . $desc); }
/** * @param Video $video * @param array $data */ protected function postSave(Video $video, array $data) { if (isset($data['meta']) && isset($data['meta']['filename']) && !empty($data['meta']['filename'])) { $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary'); $file = new File($module->getUploadPath()->append($data['meta']['filename'])); $filename = $video->getFilename(); $filepath = $module->getVideosPath($video->getSkill())->append($filename); $file->move($filepath); $video->setUrl($module->getVideosUrl($video->getSkill()) . '/' . $filename); $video->save(); } if ($video->getReference()) { $video->getReference()->addSkill($video->getSkill()); $video->save(); } // activity $user = $this->getServiceContainer()->getAuthManager()->getUser(); $user->newActivity(array('verb' => $this->isNew ? Activity::VERB_UPLOAD : Activity::VERB_EDIT, 'object' => $video, 'target' => $video->getSkill())); }
/** * @expectedException phootwork\file\exception\FileException */ public function testDeleteWithFailure() { $dir = new Directory($this->root->url() . '/dir'); $dir->make(); $file = new File($this->root->url() . '/dir/composer.json'); $file->touch(); $this->assertTrue($file->exists()); $dir->setMode(0555); $file->delete(); $this->assertFalse($file->exists()); }