芝麻web文件管理V1.00
编辑当前文件:/home4/randall/public_html/sl/wp-content/plugins/loco-translate/src/fs/Locations.php
add( $path ); } } /** * @param string $path normalized absolute path * @return Loco_fs_Locations */ public function add( $path ){ foreach( $this->expand($path) as $path ){ // path must have trailing slash, otherwise "/plugins/foobar" would match "/plugins/foo/" $this->offsetSet( $path, strlen($path) ); } return $this; } /** * Check if a given path begins with any of the registered ones * @param string $path absolute path * @return bool whether path matched */ public function check( $path ){ foreach( $this->expand($path) as $path ){ foreach( $this as $prefix => $length ){ if( $prefix === $path || substr($path,0,$length) === $prefix ){ return true; } } } return false; } /** * Match location and return the relative subpath. * Note that exact match is returned as "." indicating self * @param string $path * @return string | null */ public function rel( $path ){ foreach( $this->expand($path) as $path ){ foreach( $this as $prefix => $length ){ if( $prefix === $path ){ return '.'; } if( substr($path,0,$length) === $prefix ){ return untrailingslashit( substr($path,$length) ); } } } return null; } /** * Like rel() but returns base directory also * @return string[] */ public function split( $path ){ foreach( $this->expand($path) as $path ){ foreach( $this as $prefix => $length ){ if( $prefix === $path ){ return [$prefix,'.']; } if( substr($path,0,$length) === $prefix ){ return [ $prefix, untrailingslashit( substr($path,$length) ) ]; } } } return null; } /* * Opposite of rel, takes a relative path and constructs the first full path that exists * public function abs( $rel ){ foreach( $this as $prefix => $length ){ $path = realpath( $prefix.$rel ); if( $path ){ return $path; } } return null; }*/ /** * @param string $rel * @return string[] */ public function expand( $rel ){ if( '' === $rel ){ //Loco_error_AdminNotices::debug('Expanding empty path to empty array'); return []; } $path = Loco_fs_File::abs($rel); if( '' === $path ){ //throw new InvalidArgumentException('Failed on abs('.var_export($rel,true).')'); return []; } $paths = [ trailingslashit($path) ]; // add real path if differs $real = realpath($path); if( $real && $real !== $path ){ $paths[] = trailingslashit($real); } return $paths; } /** * @return string[] */ public function apply( $suffix = '' ){ $paths = []; foreach( $this->getArrayCopy() as $prefix => $length ){ $paths[] = $prefix.$suffix; } return $paths; } }