Best VfsStream code snippet using has.resolvePath
layer.io.php
Source:layer.io.php
...26 * read ()27 * Read a file28 */29 public function read ($path) {30 if (function_exists ("resolvePath")) $path = resolvePath ($path);31 32 /**33 * Check if $path is an URL, in which case we will use readDistant instead.34 */35 if (preg_match ('@^(?:http://)@i', $path))36 return Net::get ($path);37 38 if (!file_exists ($path)) return NULL; 39 $fr = fopen ($path, 'r');40 $data = fread ($fr, filesize ($path));41 fclose ($fr);42 43 return $data;44 }45 46 /**47 * write ()48 * Write a file49 */50 public function write ($filename, $content) {51 // if (function_exists ("resolvePath")) $filename = resolvePath ($filename);52 53 if (($fw = fopen ($filename, "w+")) === FALSE) {54 return false;55 }56 fwrite ($fw, $content, strlen ($content));57 fclose ($fw);58 59 return true;60 }61 62 /**63 * move ()64 * Move a file65 */66 public function move ($orig_name, $target_name) {67 if (function_exists ("resolvePath")) $orig_name = resolvePath ($orig_name);68 if (function_exists ("resolvePath")) $target_name = resolvePath ($target_name);69 70 chmod ($target_name, '777');71 72 return move_uploaded_file ($orig_name, $target_name);73 }74 75 /**76 * mod_time ()77 * Get the last mod time of a file78 * @param {String} path79 * @return {String} the date, NULL if the file is not found80 */81 public function mod_time ($path) {82 if (function_exists ("resolvePath")) $path = resolvePath ($path);8384 if (file_exists ($path))85 return filemtime ($path);86 else87 return NULL;88 }89 90 /**91 * copy ()92 * Copy a file to another location93 * @param {String} source : the source path94 * @param {String} dest : the dest path. If this is a dir, we'll use the same filename.95 * @return {Boolean} if success or failed96 */97 public function copy ($source, $dest) {98 if (function_exists ("resolvePath")) $source = resolvePath ($source);99 if (function_exists ("resolvePath")) $dest = resolvePath ($dest);100 if (!file_exists ($source)) return false;101 102 /**103 * Get the file's content104 */105 if (($file_content = self::read ($source)) === NULL) {106 echo "Copy: Failed reading source file content<br>";107 return false;108 }109 110 /**111 * Now get the type of copy. If we have a filename for dest file, we'll use it. If not, we'll use the same name112 */113 if (is_dir ($dest)) {114 $dest .= basename ($source);115 }116 117 /**118 * Now write the file to this folder119 */120 if (!self::write ($dest, $file_content)) return false;121 122 return true;123 }124 125 /**126 * CACHE *****************************************************127 */128 129 /**130 * cache ()131 * Write a file into the cache.132 * It can be use to cache a file by doing a copy, or to cache some content so a new file will be created133 * @param {String} path : the path of the file to be cached134 * @param {String} file_content [] : if set, this content will be written into a file named with the given path135 * @return {Boolean} true if success, false if failed caching136 * 137 * @ToDo : on devrait checker si la version en cache (si il y a) n'est pas déjà la dernière version138 */139 public function cache ($path, $file_content=NULL) {140 if (function_exists ("resolvePath")) $path = resolvePath ($path);141 142 /**143 * Create the cache filename144 */145 $cached_path = self::createCachedPath ($path); 146 147 /**148 * If file_content is not set, we'll make an exact copy of the given file in cache149 */150 if (!$file_content) {151 if (!file_exists ($path)) return false;152 153 /**154 * Copy the file155 */156 return self::copy ($path, $cached_path);157 158 /**159 * If this is a content copy, we'll create a new file160 */161 } else {162 return self::write ($cached_path, $file_content);163 }164 } 165 166 /**167 * createCachedPath ()168 * Create a valid cache path169 */170 public function createCachedPath ($path) {171 return CACHE_DIR.basename ($path).".cache";172 }173 174 /**175 * cacheUpToDate ()176 * Check if a file is up to date in the cache.177 * This will check the mod_time of the original file and the mod_time of the file we have178 * in our db179 */ 180 public function cacheUpToDate ($path) {181 if (function_exists ("resolvePath")) $path = resolvePath ($path);182 if (!file_exists ($path)) return false;183 184 if (self::mod_time ($path) < self::getCacheTime ($path)) return true;185 else return false;186 }187 188 /**189 * getCachePath ()190 * get the path in cache of a file that have been cached, from its original path191 */192 public function getCachePath ($path) {193 return self::createCachedPath ($path);194 }195
...
FilesystemStorage.php
Source:FilesystemStorage.php
...61 * @return bool62 */63 public function checkBlobExists(Blob $blob)64 {65 $path = $this->resolvePath($blob->getPath());66 $exists = is_file($path);67 $this->logger->logInfo("[FilesystemStorage] (checkBlobExists) $path " . ($exists ? 'exists' : 'no exist'));68 return $exists;69 }70 /**71 * @param \Application\DeskPRO\BlobStorage\Blob $blob72 * @return bool73 */74 public function deleteBlob(Blob $blob)75 {76 $path = $this->resolvePath($blob->getPath());77 if (!file_exists($path)) {78 $this->logger->logInfo("[FilesystemStorage] (deleteBlob) Path does not exist, nothing to delete: $path");79 return true;80 }81 $res = @unlink($path);82 if ($res) {83 $this->logger->logInfo("[FilesystemStorage] (deleteBlob) Deleted path: $path");84 } else {85 $this->logger->logInfo("[FilesystemStorage] (deleteBlob) Failed to delete path: $path");86 }87 return $res;88 }89 /**90 * @param \Application\DeskPRO\BlobStorage\Blob $blob91 * @param $data92 * @return int93 */94 public function writeBlobString(Blob $blob, $data)95 {96 $fp = $this->getBlobWriteStream($blob);97 $ret = @fwrite($fp, $data);98 @fclose($fp);99 $this->logger->logInfo("[FilesystemStorage] (writeBlobString) Wrote " . Numbers::filesizeDisplay($ret) . " from string to " . $this->resolvePath($blob->getPath()));100 return $ret;101 }102 /**103 * @param \Application\DeskPRO\BlobStorage\Blob $blob104 * @param string $source_path105 * @return int106 */107 public function writeBlobFromFile(Blob $blob, $source_path)108 {109 $fp_source = @fopen($source_path, 'r');110 if (!$fp_source) {111 @fclose($fp_source);112 $this->logger->logError("[FilesystemStorage] (writeBlobFromFile) Could not open $source_path for reading");113 throw new \RuntimeException("Could not open source_path for reading: $source_path");114 }115 try {116 $ret = $this->writeBlobFromStream($blob, $fp_source);117 } catch (\Exception $e) {118 @fclose($fp_source);119 throw $e;120 }121 @fclose($fp_source);122 $this->logger->logInfo("[FilesystemStorage] (writeBlobFromFile) Wrote " . Numbers::filesizeDisplay($ret) . " from $source_path to " . $this->resolvePath($blob->getPath()));123 return $ret;124 }125 /**126 * @param \Application\DeskPRO\BlobStorage\Blob $blob127 * @param resource $data128 * @return int129 */130 public function writeBlobFromStream(Blob $blob, $fp_source)131 {132 $fp = $this->getBlobWriteStream($blob);133 $ret = $this->_copyStream($fp_source, $fp);134 @fclose($fp);135 $this->logger->logInfo("[FilesystemStorage] (writeBlobFromStream) Wrote " . Numbers::filesizeDisplay($ret) . " from stream to " . $this->resolvePath($blob->getPath()));136 $path = $this->resolvePath($blob->getPath());137 if (file_exists($path)) {138 $this->_chmod($path, $this->file_mode);139 }140 return $ret;141 }142 /**143 * Loads the entire blob into a string144 *145 * @param \Application\DeskPRO\BlobStorage\Blob $blob146 * @return string147 */148 public function readBlobString(Blob $blob)149 {150 $fp = $this->getBlobReadStream($blob);151 $str = '';152 while (!feof($fp)) {153 $str .= @fread($fp, 1000);154 }155 @fclose($fp);156 $this->logger->logInfo("[FilesystemStorage] (readBlobString) Read " . Numbers::filesizeDisplay(strlen($str)) . " from " . $this->resolvePath($blob->getPath()));157 return $str;158 }159 /**160 * @param \Application\DeskPRO\BlobStorage\Blob $blob161 * @param string $target_path162 * @return int163 */164 public function readBlobToFile(Blob $blob, $target_path)165 {166 $fp_target = @fopen($target_path, 'w');167 if (!$fp_target) {168 @fclose($fp_target);169 $this->logger->logError("[FilesystemStorage] (readBlobToFile) Could not open $target_path for writing");170 throw new \RuntimeException("Could not open target_path for writing: $target_path");171 }172 try {173 $ret = $this->readBlobToStream($blob, $fp_target);174 } catch (\Exception $e) {175 @fclose($fp_target);176 throw $e;177 }178 $this->logger->logInfo("[FilesystemStorage] (readBlobToFile) Read " . Numbers::filesizeDisplay($ret) . " to $target_path from " . $this->resolvePath($blob->getPath()));179 return $ret;180 }181 /**182 * @param \Application\DeskPRO\BlobStorage\Blob $blob183 * @param resource $fp_target184 * @return int185 */186 public function readBlobToStream(Blob $blob, $fp_target)187 {188 $fp = $this->getBlobReadStream($blob);189 $ret = $this->_copyStream($fp, $fp_target);190 fclose($fp);191 $this->logger->logInfo("[FilesystemStorage] (readBlobToStream) Read " . Numbers::filesizeDisplay($ret) . " to stream from " . $this->resolvePath($blob->getPath()));192 return $ret;193 }194 /**195 * @return resource196 */197 public function getBlobWriteStream(Blob $blob)198 {199 $path = $this->resolvePath($blob->getPath());200 $dir = dirname($path);201 if (!is_dir($dir)) {202 @mkdir($dir, 0777, true);203 $this->_chmod($dir, $this->dir_mode);204 }205 $fp = @fopen($path, 'w');206 if (!$fp) {207 $this->logger->logError("[FilesystemStorage] (getBlobWriteStream) Failed to open path for writing: $path");208 throw new \RuntimeException("Could not open blob for writing: $path");209 }210 return $fp;211 }212 /**213 * @return resource214 */215 public function getBlobReadStream(Blob $blob)216 {217 $path = $this->resolvePath($blob->getPath());218 $fp = @fopen($path, 'r');219 if (!$fp) {220 $this->logger->logError("[FilesystemStorage] (getBlobReadStream) Failed to open path for reading: $path");221 throw new \RuntimeException("Could not open blob for reading: $path");222 }223 return $fp;224 }225 /**226 * Get the full path from a path string227 *228 * @param string $path229 * @return string230 */231 public function resolvePath($path)232 {233 $path = trim($path, '/\\');234 return $this->base_path . DIRECTORY_SEPARATOR . $path;235 }236 /**237 * @param $fp_from238 * @param $fp_to239 * @return int240 */241 protected function _copyStream($fp_from, $fp_to)242 {243 $size = 0;244 while (!feof($fp_from)) {245 $size += @fwrite($fp_to, fread($fp_from, 8192));...
Spaces.php
Source:Spaces.php
1<?php2namespace App\Mutators\Storage;3use Storage;4trait Spaces{5 function resolvePath($filename){6 $path=property_exists($this,"_storagePath")?trim(preg_replace('/[^\da-z\/]/i', '_',$this->_storagePath),' /'):"";7 return trim(sprintf('%s/%s',$path,$filename),"/");8 }9 function saveFile($filename,$data){10 return Storage::disk('do_spaces')->put($this->resolvePath($filename),$data);11 }12 function prependFile($filename,$data){13 return Storage::disk('do_spaces')->prepend($this->resolvePath($filename),$data);14 }15 function appendFile($filename,$data){16 return Storage::disk('do_spaces')->append($this->resolvePath($filename),$data);17 }18 function getFile($filename){19 return Storage::disk('do_spaces')->get($this->resolvePath($filename));20 }21 function listFiles($directoryname='/'){22 return Storage::disk('do_spaces')->files($this->resolvePath($directoryname));23 }24 function listAllFiles($directoryname='/'){25 return Storage::disk('do_spaces')->allFiles($this->resolvePath($directoryname));26 }27 function listFolders($directoryname='/'){28 return Storage::disk('do_spaces')->directories($this->resolvePath($directoryname));29 }30 function listAllFolders($directoryname='/'){31 return Storage::disk('do_spaces')->allDirectories($this->resolvePath($directoryname));32 }33 function createFolder($directoryname){34 return Storage::disk('do_spaces')->makeDirectory($this->resolvePath($directoryname));35 }36 function deleteFolder($directoryname){37 return Storage::disk('do_spaces')->deleteDirectory($this->resolvePath($directoryname));38 }39 function deleteFile($filename){40 return Storage::disk('do_spaces')->delete($this->resolvePath($filename));41 }42 function getFileSize($filename){43 return Storage::disk('do_spaces')->size($this->resolvePath($filename));44 }45 function getFileLastModified($filename){46 return Storage::disk('do_spaces')->lastModified($this->resolvePath($filename));47 }48 function fileExists($filename){49 return Storage::disk('do_spaces')->has($this->resolvePath($filename));50 }51 function copyFile($filename,$destination){52 return Storage::disk('do_spaces')->copy($this->resolvePath($filename),$destination);53 }54 function moveFile($filename,$destination){55 return Storage::disk('do_spaces')->move($this->resolvePath($filename),$destination);56 }57 function temporaryUrl($filename,$time=5){58 return Storage::disk('do_spaces')->temporaryUrl($this->resolvePath($filename), now()->addMinutes($time));59 }60}...
resolvePath
Using AI Code Generation
1$has = new Has();2$has->resolvePath("2.php");3$has = new Has();4$has->resolvePath("1.php");5$has = new Has();6$has->resolvePath("1.php");7$has = new Has();8$has->resolvePath("2.php");9$has = new Has();10$has->resolvePath("3.php");11$has = new Has();12$has->resolvePath("4.php");13$has = new Has();14$has->resolvePath("5.php");15$has = new Has();16$has->resolvePath("6.php");17$has = new Has();18$has->resolvePath("7.php");19$has = new Has();20$has->resolvePath("8.php");21$has = new Has();22$has->resolvePath("9.php");23$has = new Has();24$has->resolvePath("10.php");25$has = new Has();26$has->resolvePath("11.php");27$has = new Has();28$has->resolvePath("12.php");29$has = new Has();30$has->resolvePath("13.php");
resolvePath
Using AI Code Generation
1$has = new Has('1.php');2echo $has->resolvePath('2.php');3$has = new Has('2.php');4echo $has->resolvePath('1.php');5$has = new Has('1.php');6echo $has->resolvePath('1.php');7$has = new Has('2.php');8echo $has->resolvePath('2.php');9$has = new Has('1.php');10echo $has->resolvePath('2.php');11$has = new Has('2.php');12echo $has->resolvePath('1.php');13$has = new Has('1.php');14echo $has->resolvePath('1.php');15$has = new Has('2.php');16echo $has->resolvePath('2.php');17$has = new Has('1.php');18echo $has->resolvePath('2.php');19$has = new Has('2.php');20echo $has->resolvePath('1.php');21$has = new Has('1.php');22echo $has->resolvePath('1.php');23$has = new Has('2.php');24echo $has->resolvePath('2.php');25$has = new Has('1.php');26echo $has->resolvePath('2.php');27$has = new Has('2.php');28echo $has->resolvePath('1
resolvePath
Using AI Code Generation
1require_once 'has.php';2$has = new Has();3$has->resolvePath('2.php');4require_once 'has.php';5$has = new Has();6$has->resolvePath('1.php');7require_once 'has.php';8$has = new Has();9$has->resolvePath('3.php');10require_once 'has.php';11$has = new Has();12$has->resolvePath('2.php');13require_once 'has.php';14$has = new Has();15$has->resolvePath('1.php');16require_once 'has.php';17$has = new Has();18$has->resolvePath('3.php');19require_once 'has.php';20$has = new Has();21$has->resolvePath('2.php');22require_once 'has.php';23$has = new Has();24$has->resolvePath('1.php');25require_once 'has.php';26$has = new Has();27$has->resolvePath('3.php');28require_once 'has.php';29$has = new Has();30$has->resolvePath('2.php');31require_once 'has.php';32$has = new Has();33$has->resolvePath('1.php');34require_once 'has.php';35$has = new Has();36$has->resolvePath('3.php');37require_once 'has.php';38$has = new Has();39$has->resolvePath('2.php');
resolvePath
Using AI Code Generation
1echo Has::resolvePath('2.php', __DIR__);2echo Has::resolvePath('/var/www/html/1.php', __DIR__);3echo Has::resolvePath('2.php', __DIR__);4echo Has::resolvePath('/var/www/html/2.php', __DIR__);5echo Has::resolvePath('/var/www/html/2.php', __DIR__);6echo Has::resolvePath('/var/www/html/2.php', __DIR__);7echo Has::resolvePath('/var/www/html/2.php', __DIR__);8echo Has::resolvePath('/var/www/html/2.php', __DIR__);9echo Has::resolvePath('/var/www/html/2.php', __DIR__);10echo Has::resolvePath('/var/www/html/2.php', __DIR__);11echo Has::resolvePath('/var/www/html/2.php', __DIR__);12echo Has::resolvePath('/var/www/html/2.php', __DIR__);13echo Has::resolvePath('/var/www/html/2.php', __DIR__);14echo Has::resolvePath('/var/www/html/2.php', __DIR__);
resolvePath
Using AI Code Generation
1$has = new Has();2$has->resolvePath('/a/b/c/d', '../x');3$has->resolvePath('/a/b/c/d', '../../x');4$has->resolvePath('/a/b/c/d', '/x');5$has->resolvePath('/a/b/c/d', '/a/b/c/d/e/f/g');6$has->resolvePath('/a/b/c/d', 'e/f/g');7$has = new Has();8$has->resolvePath('/a/b/c/d', '../x');9$has->resolvePath('/a/b/c/d', '../../x');10$has->resolvePath('/a/b/c/d', '/x');11$has->resolvePath('/a/b/c/d', '/a/b/c/d/e/f/g');12$has->resolvePath('/a/b/c/d', 'e/f/g');13$has = new Has();14$has->resolvePath('/a/b/c/d', '../x');15$has->resolvePath('/a/b/c/d', '../../x');16$has->resolvePath('/a/b/c/d', '/x');17$has->resolvePath('/a/b/c/d', '/a/b/c/d/e/f/g');18$has->resolvePath('/a/b/c/d', 'e/f/g');19$has = new Has();20$has->resolvePath('/a/b/c/d', '../x');21$has->resolvePath('/a/b/c/d', '../../x');
resolvePath
Using AI Code Generation
1include_once 'has.php';2$has = new Has();3$has->resolvePath();4PHP | getcwd() Function to Get Current Working Directory5PHP | get_include_path() Function to Get Include Path6PHP | getmygid() Function to Get Current Process Group ID7PHP | getmyinode() Function to Get Current Process Inode8PHP | getmypid() Function to Get Current Process ID9PHP | getmyuid() Function to Get Current Process User ID10PHP | get_current_user() Function to Get Current User11PHP | gethostbyaddr() Function to Get Hostname by IP Address12PHP | gethostbyname() Function to Get IP Address by Hostname13PHP | gethostbynamel() Function to Get List of IP Addresses for a Host14PHP | gethostname() Function to Get Hostname15PHP | getprotobyname() Function to Get Protocol Number by Name16PHP | getprotobynumber() Function to Get Protocol Name by Number17PHP | getservbyname() Function to Get Service Port by Name18PHP | getservbyport() Function to Get Service Name by Port19PHP | get_browser() Function to Get Browser Information20PHP | get_cfg_var() Function to Get Configuration Value21PHP | get_class_vars() Function to Get Class Variables22PHP | get_class() Function to Get Class Name23PHP | get_called_class() Function to Get Name of Calling Class
resolvePath
Using AI Code Generation
1include "has.php";2include "path.php";3$has=new has();4$has->resolvePath("2.php");5$path=new path();6$path->resolvePath("2.php");7include "has.php";8include "path.php";9$has=new has();10$has->resolvePath("3.php");11$path=new path();12$path->resolvePath("3.php");13include "has.php";14include "path.php";15$has=new has();16$has->resolvePath("4.php");17$path=new path();18$path->resolvePath("4.php");19include "has.php";20include "path.php";21$has=new has();22$has->resolvePath("5.php");23$path=new path();24$path->resolvePath("5.php");25include "has.php";26include "path.php";27$has=new has();28$has->resolvePath("6.php");29$path=new path();30$path->resolvePath("6.php");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with resolvePath on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!