/** * Tests File::getFilename */ public function testGetFilename() { $spl = $this->getFileInfo(); $file = new File($spl); $filename = $file->getFilename(); $this->assertEquals($spl->getFilename(), $filename); }
protected function getCacheFile(File $file) { if (!$GLOBALS['phorkie']['cfg']['cachedir'] || !is_dir($GLOBALS['phorkie']['cfg']['cachedir'])) { return null; } return $GLOBALS['phorkie']['cfg']['cachedir'] . '/' . $file->repo->id . '-' . $file->repo->hash . '-' . str_replace('/', '-', $file->getFilename()) . '.html'; }
function execute() { $file_or_folder = $this->file_or_folder; if (self::$dummy_mode) { echo "Adding : " . $file_or_folder . "<br />"; return; } $root_dir_path = self::$root_dir->getPath(); $file_or_folder = str_replace("\\", "/", $file_or_folder); $file_list = array(); //se finisce con lo slash è una directory if (substr($file_or_folder, strlen($file_or_folder) - 1, 1) == "/") { //creo la cartella $target_dir = new Dir(DS . $root_dir_path . $file_or_folder); $target_dir->touch(); $source_dir = new Dir($this->module_dir->getPath() . $file_or_folder); foreach ($source_dir->listFiles() as $elem) { if ($elem->isDir()) { $file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getName() . DS)); } else { $file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getFilename())); } } } else { $source_file = new File($this->module_dir->getPath() . $file_or_folder); $target_file = new File($root_dir_path . $file_or_folder); $target_dir = $target_file->getDirectory(); $target_dir->touch(); $source_file->copy($target_dir); $file_list[] = $target_dir->newFile($source_file->getFilename())->getPath(); } return $file_list; }
function testFilename() { $f_txt = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/test_file.txt"); $this->assertEqual("test_file.txt", $f_txt->getFilename()); $f_css = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/css_test.css"); $this->assertEqual("css_test.css", $f_css->getFilename()); $f_plug_txt = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/ext_test.plug.txt"); $this->assertEqual("ext_test.plug.txt", $f_plug_txt->getFilename()); }
/** * @param File $f * @throws Exception */ public function put(File $f) { $fp = fopen($f->getFullPath(), 'r'); if (!$fp) { throw new Exception("Unable to open file: " . $f->getFilename()); } $headers = array(); if (!empty($this->config[self::FORCE_DL])) { $headers['Content-Disposition'] = 'attachment; filename=' . ($f->hasMethod('getFriendlyName') ? $f->getFriendlyName() : $f->Name); } $this->getContainer()->uploadObject($this->getRelativeLinkFor($f), $fp, $headers); }
/** * @param File $f * @throws Exception */ public function put(File $f) { $fp = fopen($f->getFullPath(), 'r'); if (!$fp) { throw new Exception('Unable to open file: ' . $f->getFilename()); } $uploader = UploadBuilder::newInstance()->setClient($this->client)->setSource($f->getFullPath())->setBucket($this->containerName)->setKey($this->getRelativeLinkFor($f))->build(); try { $uploader->upload(); } catch (MultipartUploadException $e) { $uploader->abort(); } }
/** * @param File $f * @throws Exception */ public function put(File $f) { $fp = fopen($f->getFullPath(), 'r'); if (!$fp) { throw new Exception('Unable to open file: ' . $f->getFilename()); } $uploader = new MultipartUploader($this->client, $f->getFullPath(), array('bucket' => $this->containerName, 'key' => $this->getRelativeLinkFor($f))); try { $uploader->upload(); } catch (MultipartUploadException $e) { // warning: below exception gets silently swallowed! error_log('S3Bucket: failed to put file: ' . $e->getPrevious()->getMessage()); throw new Exception('S3Bucket: failed to put file: ' . $e->getPrevious()->getMessage(), 0, $e); } }
/** * Migrate a single file * * @param string $base Absolute base path (parent of assets folder) * @param File $file * @param type $legacyFilename * @return bool True if this file is imported successfully */ protected function migrateFile($base, File $file, $legacyFilename) { // Make sure this legacy file actually exists $path = $base . '/' . $legacyFilename; if (!file_exists($path)) { return false; } // Copy local file into this filesystem $filename = $file->getFilename(); $result = $file->setFromLocalFile($path, $filename, null, null, array('conflict' => AssetStore::CONFLICT_OVERWRITE)); // Move file if the APL changes filename value if ($result['Filename'] !== $filename) { $this->setFilename($result['Filename']); } // Save $file->write(); return true; }
/** * Performs two functions: * 1. Wraps this object in CloudFile (etc) by changing the classname if it should be and is not * 2. Uploads the file to the cloud storage if it doesn't contain the placeholder * * @return File */ public function updateCloudStatus() { if ($this->inUpdate) { return; } $this->inUpdate = true; $cloud = CloudAssets::inst(); // does this file fall under a cloud bucket? $bucket = $cloud->map($this->owner->getFilename()); if ($bucket) { // does this file need to be wrapped? $wrapClass = $cloud->getWrapperClass($this->owner->ClassName); if (!empty($wrapClass)) { if ($wrapClass != $this->owner->ClassName) { $cloud->getLogger()->debug("CloudAssets: wrapping {$this->owner->ClassName} to {$wrapClass}. ID={$this->owner->ID}"); $this->owner->ClassName = $wrapClass; $this->owner->write(); $wrapped = DataObject::get($wrapClass)->byID($this->owner->ID); if ($wrapped->hasMethod('onAfterCloudWrap')) { $wrapped->onAfterCloudWrap(); } } else { $wrapped = $this->owner; } // does this file need to be uploaded to storage? if ($wrapped->canBeInCloud() && $wrapped->isCloudPutNeeded() && !Config::inst()->get('CloudAssets', 'uploads_disabled')) { try { if ($wrapped->hasMethod('onBeforeCloudPut')) { $wrapped->onBeforeCloudPut(); } $cloud->getLogger()->debug("CloudAssets: uploading file " . $wrapped->getFilename()); $bucket->put($wrapped); $wrapped->setCloudMeta('LastPut', time()); $wrapped->CloudStatus = 'Live'; $wrapped->CloudSize = filesize($this->owner->getFullPath()); $wrapped->write(); $wrapped->convertToPlaceholder(); if ($wrapped->hasMethod('onAfterCloudPut')) { $wrapped->onAfterCloudPut(); } } catch (Exception $e) { $wrapped->CloudStatus = 'Error'; $wrapped->write(); $cloud->getLogger()->error("CloudAssets: Failed bucket upload: " . $e->getMessage() . " for " . $wrapped->getFullPath()); // Fail silently for now. This will cause the local copy to be served. } } elseif ($wrapped->CloudStatus !== 'Live' && $wrapped->containsPlaceholder()) { // If this is a duplicate file, update the status // This shouldn't happen ever and won't happen often but when it does this will be helpful $dup = File::get()->filter(array('Filename' => $wrapped->Filename, 'CloudStatus' => 'Live'))->first(); if ($dup && $dup->exists()) { $cloud->getLogger()->warn("CloudAssets: fixing status for duplicate file: {$wrapped->ID} and {$dup->ID}"); $wrapped->CloudStatus = $dup->CloudStatus; $wrapped->CloudSize = $dup->CloudSize; $wrapped->CloudMetaJson = $dup->CloudMetaJson; $wrapped->write(); } } $this->inUpdate = false; return $wrapped; } } $this->inUpdate = false; return $this->owner; }
public function getFilename() { return parent::getFilename() . '/'; }
/** * @param File $file * * @return string */ private function getPharDestination(File $file) { return $this->pharDirectory . DIRECTORY_SEPARATOR . $file->getFilename(); }
public function testFilename() { $filename = new Filename('foo.phar'); $file = new File($filename, 'bar'); $this->assertSame($filename, $file->getFilename()); }
/** * @param File $file * @return string */ protected function getThumbnailURLForFile(File $file) { if ($file && $file->exists() && file_exists(Director::baseFolder() . '/' . $file->getFilename())) { if ($file->hasMethod('getThumbnail')) { return $file->getThumbnail($this->getConfig('previewMaxWidth'), $this->getConfig('previewMaxHeight'))->getURL(); } elseif ($file->hasMethod('getThumbnailURL')) { return $file->getThumbnailURL($this->getConfig('previewMaxWidth'), $this->getConfig('previewMaxHeight')); } elseif ($file->hasMethod('SetRatioSize')) { return $file->SetRatioSize($this->getConfig('previewMaxWidth'), $this->getConfig('previewMaxHeight'))->getURL(); } else { return $file->Icon(); } } return false; }
/** * Converts the code to HTML * * @param File $file File to render * @param Tool_Result $res Tool result to integrate * * @return string HTML */ public function toHtml(File $file, Tool_Result $res = null) { return '<div class="image">' . '<img' . ' src="' . htmlspecialchars($file->getLink('raw')) . '"' . ' alt="' . htmlspecialchars($file->getFilename()) . '"' . '/>' . '</div>'; }
/** * @param File $phar * @param string $destination */ private function link(File $phar, $destination) { $this->output->writeInfo(sprintf('Symlinking %s to %s', $phar->getFilename(), $destination)); symlink($this->pharDirectory . DIRECTORY_SEPARATOR . $phar->getFilename(), $destination); }
/** * @param File|string $f * @return \Guzzle\Http\EntityBody */ protected function getFileObjectFor($f) { try { $result = $this->client->getObject(array('Bucket' => $this->containerName, 'Key' => $f->getFilename())); return $result; } catch (\Aws\S3\Exception\NoSuchKeyException $e) { return -1; } }
/** * @depends testGetFilename * @covers Versionable\Prospect\Response\File::setFilename * @covers Versionable\Prospect\Response\File::getFilename */ public function testSetFilename() { $filename = 'test'; $this->object->setFilename($filename); $this->assertEquals($filename, $this->object->getFilename()); }
static function delete_image_thumbnails($path) { if ($path instanceof File) { $image_file = $path; } else { $image_file = new File($path); } $image_dir = $image_file->getDirectory(); $full_cache_dir = new Dir(self::THUMBNAILS_DIR . $image_dir->getPath()); $folders = $full_cache_dir->listFolders(); foreach ($folders as $f) { $image_thumb = $f->newFile($image_file->getFilename()); if ($image_thumb->exists()) { $image_thumb->delete(); } if ($f->isEmpty()) { $f->delete(); } } if ($full_cache_dir->isEmpty()) { $full_cache_dir->delete(); } }
/** * @param File $file * @return string */ protected function getThumbnailURLForFile(File $file) { if ($file->exists() && file_exists(Director::baseFolder() . '/' . $file->getFilename())) { $width = $this->getPreviewMaxWidth(); $height = $this->getPreviewMaxHeight(); if ($file->hasMethod('getThumbnail')) { return $file->getThumbnail($width, $height)->getURL(); } elseif ($file->hasMethod('getThumbnailURL')) { return $file->getThumbnailURL($width, $height); } elseif ($file->hasMethod('SetRatioSize')) { return $file->SetRatioSize($width, $height)->getURL(); } else { return $file->Icon(); } } return false; }
public function testAddingAFilename() { $file = new File(); $file->setFilename('test'); $this->assertSame('test', $file->getFilename()); }
public function testConstructorSetsFilename() { $this->assertEquals('test.tys', $this->file->getFilename()); }
/** * * @param int $iconId * @return array */ public static function getIcon($iconId) { return parent::getFilename($iconId); }