| Server IP : 104.21.28.229 / Your IP : 216.73.216.142 Web Server : Apache/2 System : Linux hosting8537.lvs 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : mienphi ( 1014) PHP Version : 8.2.14 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/mienphi/domains/mienphi.org/public_html/wp-content/plugins/loco-translate/src/fs/ |
Upload File : |
<?php
/**
* Collection of unique file references
*
* @method Loco_fs_File[] getArrayCopy
*/
class Loco_fs_FileList extends ArrayIterator implements Loco_fs_FileListInterface {
/**
* Hash map for ensuring files only added once
* @var array
*/
private $unique = [];
/**
* Construct with initial list if files
* @param Loco_fs_File[] $a
*/
public function __construct( $a = [] ){
parent::__construct();
foreach( $a as $file ){
$this->add( $file );
}
}
/**
* Use instead of clone because that does weird things to ArrayIterator instances.
* Note that this does NOT clone individual file members.
* @return Loco_fs_FileList
*/
public function copy(){
return new Loco_fs_FileList( $this->getArrayCopy() );
}
/**
* Like getArrayCopy, but exports string paths
* @return array
*/
public function export(){
$a = [];
foreach( $this as $file ){
$a[] = (string) $file;
}
return $a;
}
/**
* @internal
* @return string
*/
public function __toString(){
return implode( "\n", $this->getArrayCopy() );
}
/**
* Generate a unique key for file
* @param Loco_fs_File $file
* @return string
*/
private function hash( Loco_fs_File $file ){
return $file->getRealPath() ?: $file->normalize();
}
/**
* {@inheritDoc}
*/
#[ReturnTypeWillChange]
public function offsetSet( $key, $value ){
throw new Exception('Use Loco_fs_FileList::add');
}
/**
* {@inheritDoc}
*/
public function add( Loco_fs_File $file ){
$hash = $this->hash( $file );
if( isset($this->unique[$hash]) ){
return false;
}
$this->unique[$hash] = true;
parent::offsetSet( null, $file );
return true;
}
/**
* Check if given file is already in list
* @param Loco_fs_File $file
* @return bool
*/
public function has( Loco_fs_File $file ){
$hash = $this->hash( $file );
return isset($this->unique[$hash]);
}
/**
* Get a copy of list with only files not contained in passed list
* @param self $not_in
* @return self
*/
public function diff( Loco_fs_FileList $not_in ){
$list = new Loco_fs_FileList;
foreach( $this as $file ){
$not_in->has($file) || $list->add( $file );
}
return $list;
}
/**
* Merge another list of the SAME TYPE uniquely on top of current one
* @param self $list
* @return self
*/
public function augment( loco_fs_FileList $list ){
foreach( $list as $file ){
$this->add( $file );
}
return $this;
}
}