framework/console/CConsoleCommand.php
public function copyFiles($fileList,$overwriteAll=false)
	{
		foreach($fileList as $name=>$file)
		{
			$source=strtr($file['source'],'/\\',DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR);
			$target=strtr($file['target'],'/\\',DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR);
			$callback=isset($file['callback']) ? $file['callback'] : null;
			$params=isset($file['params']) ? $file['params'] : null;

			if(is_dir($source))
			{
				$this->ensureDirectory($target);
				continue;
			}

			if($callback!==null)
				$content=call_user_func($callback,$source,$params);
			else
				$content=file_get_contents($source);
			if(is_file($target))
			{
				if($content===file_get_contents($target))
				{
					echo "  unchanged $name\n";
					continue;
				}
				if($overwriteAll)
					echo "  overwrite $name\n";
				else
				{
					echo "      exist $name\n";
					echo "            ...overwrite? [Yes|No|All|Quit] ";
					$answer=trim(fgets(STDIN));
					if(!strncasecmp($answer,'q',1))
						return;
					elseif(!strncasecmp($answer,'y',1))
						echo "  overwrite $name\n";
					elseif(!strncasecmp($answer,'a',1))
					{
						echo "  overwrite $name\n";
						$overwriteAll=true;
					}
					else
					{
						echo "       skip $name\n";
						continue;
					}
				}
			}
			else
			{
				$this->ensureDirectory(dirname($target));
				echo "   generate $name\n";
			}
			file_put_contents($target,$content);
		}
	}
public function copyFiles($fileList,$overwriteAll=false)
	{
		foreach($fileList as $name=>$file)
		{
			$source=strtr($file['source'],'/\\',DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR);
			$target=strtr($file['target'],'/\\',DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR);
			$callback=isset($file['callback']) ? $file['callback'] : null;
			$params=isset($file['params']) ? $file['params'] : null;

			if(is_dir($source))
			{
				$this->ensureDirectory($target);
				continue;
			}

			if($callback!==null)
				$content=call_user_func($callback,$source,$params);
			else
				$content=file_get_contents($source);
			if(is_file($target))
			{
				if($content===file_get_contents($target))
				{
					echo "  unchanged $name\n";
					continue;
				}
				if($overwriteAll)
					echo "  overwrite $name\n";
				else
				{
					echo "      exist $name\n";
					echo "            ...overwrite? [Yes|No|All|Quit] ";
					$answer=trim(fgets(STDIN));
					if(!strncasecmp($answer,'q',1))
						return;
					elseif(!strncasecmp($answer,'y',1))
						echo "  overwrite $name\n";
					elseif(!strncasecmp($answer,'a',1))
					{
						echo "  overwrite $name\n";
						$overwriteAll=true;
					}
					else
					{
						echo "       skip $name\n";
						continue;
					}
				}
			}
			else
			{
				$this->ensureDirectory(dirname($target));
				echo "   generate $name\n";
			}
			file_put_contents($target,$content);
		}
	}
public function copyFiles ( $ fileList , $ overwriteAll = false ) { foreach ( $ fileList as $ name => $ file ) { $ source = strtr ( $ file [ 'source' ] , '/\\' , DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) ; $ target = strtr ( $ file [ 'target' ] , '/\\' , DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) ; $ callback = isset ( $ file [ 'callback' ] ) ? $ file [ 'callback' ] : null ; $ params = isset ( $ file [ 'params' ] ) ? $ file [ 'params' ] : null ; if ( is_dir ( $ source ) ) { $ this -> ensureDirectory ( $ target ) ; continue ; } if ( $ callback !== null ) $ content = call_user_func ( $ callback , $ source , $ params ) ; else $ content = file_get_contents ( $ source ) ; if ( is_file ( $ target ) ) { if ( $ content === file_get_contents ( $ target ) ) { echo "  unchanged $name\n" ; continue ; } if ( $ overwriteAll ) echo "  overwrite $name\n" ; else { echo "      exist $name\n" ; echo "            ...overwrite? [Yes|No|All|Quit] " ; $ answer = trim ( fgets ( STDIN ) ) ; if ( ! strncasecmp ( $ answer , 'q' , 1 ) ) return ; elseif ( ! strncasecmp ( $ answer , 'y' , 1 ) ) echo "  overwrite $name\n" ; elseif ( ! strncasecmp ( $ answer , 'a' , 1 ) ) { echo "  overwrite $name\n" ; $ overwriteAll = true ; } else { echo "       skip $name\n" ; continue ; } } } else { $ this -> ensureDirectory ( dirname ( $ target ) ) ; echo "   generate $name\n" ; } file_put_contents ( $ target , $ content ) ; } }
Copies a list of files from one place to another.
@param array $fileList the list of files to be copied (name=>spec).
The array keys are names displayed during the copy process, and array values are specifications
for files to be copied. Each array value must be an array of the following structure:
<ul>
<li>source: required, the full path of the file/directory to be copied from</li>
<li>target: required, the full path of the file/directory to be copied to</li>
<li>callback: optional, the callback to be invoked when copying a file. The callback function
should be declared as follows:
<pre>
function foo($source,$params)
</pre>
where $source parameter is the source file path, and the content returned
by the function will be saved into the target file.</li>
<li>params: optional, the parameters to be passed to the callback</li>
</ul>
@param boolean $overwriteAll whether to overwrite all files.
@see buildFileList
Copies a list of files from one place to another .