コード例 #1
0
ファイル: PurGit.php プロジェクト: rintaun/himawari
	/**
	 * Return an array representation of the git status command.
	 * 
	 * Options may include:
	 * -   *absolute* Return absolute paths
	 * -   *cwd* Directory from from where the status must be run
	 * -   *bin* Path to the Git command
	 * -   *relative* Relative to the Git project root directory
	 * 
	 * Structure of the returned array:
	 * -   changed_to_be_committed
	 * -   changed_but_not_updated
	 * -   untracked_files
	 * 
	 * @return array Decomposed status
	 * 
	 * @param array $options required Options used to alter the method behavior
	 * @return array Decomposed status
	 * 
	 * @param string $cwd required Path to the directory to initialize
	 * @return array Decomposed status
	 */
	public static function status(){
		$args = func_get_args();
		switch(count($args)){
			case 0:
				$options = array();
				break;
			case 1:
				if(is_string($args[0])){
					$options = array(
						'cwd' => $args[0]);
				}else if(is_array($args[0])){
					$options = $args[0];
				}else{
					throw new InvalidArgumentException('Invalid Arguments: "'.PurLang::toString($args).'"');
				}
				break;
			default:
				throw new InvalidArgumentException('Invalid Arguments Count: '.PurLang::toString($args));
		}
		unset($args);
		$options['return_message'] = 1;
		if(empty($options['bin'])){
			$options['bin'] = self::$bin;
		}
		$command = $options['bin'];
		$command .= ' status';
		$out = PurCli::exec($command,$options);
		$status = array(
			'changed_to_be_committed'=>array(),
			'changed_but_not_updated'=>array(),
			'untracked_files'=>array());
		$type = null;
		foreach($out as $line){
			if($line=='# Changes to be committed:'){
				$type = 'changed_to_be_committed';
			}else if($line=='# Changed but not updated:'){
				$type = 'changed_but_not_updated';
			}else if($line=='# Untracked files:'){
				$type = 'untracked_files';
			}else{
				if(preg_match('/^#\t((new file|modified|deleted): +)?(.*)/',$line,$matches)){
//					if(isset($options['cwd'])){
//						$matches[3] = PurPath::relative($options['cwd'],getcwd().'/'.$matches[3]);
//					}
					if(!empty($options['absolute'])){
						$matches[3] = PurPath::clean($options['cwd'].'/'.$matches[3]);
					}else if(!empty($options['relative'])){
						$matches[3] = PurPath::relative(self::dir($options),$options['cwd'].'/'.$matches[3]);
					}
					if(empty($matches[2])){
						$status[$type][] = $matches[3];
					}else{
						$status[$type][$matches[2]][] = $matches[3];
					}
				}
			} 
		}
		while(list($k,$v) = each($status)){
			if(empty($v)){
				unset($status[$k]);
			}
		}
		reset($status);
		return $status;
	}
コード例 #2
0
ファイル: PurFile.php プロジェクト: rintaun/himawari
	/**
	 * Extract a source achive into a destination file or directory.
	 * 
	 * Options may include:
	 * -   *format*
	 *     The method used to compress the source. If not provided as an option, 
	 *     format is derived from the destination extension name.
	 * 
	 */
	public static function extract($source,$destination,array $options=array()){
		if(empty($options['format'])){
			$options['format'] = PurPath::extension($source);
		}
		switch($options['format']){
			case 'zip';
				PurFile::mkdir($destination);
				// u: update existing files and create new ones if needed.
				PurCli::exec('unzip -u '.escapeshellarg($source).' -d '.escapeshellarg($destination));
				break;
			default:
				throw new Exception('Unsupported format: "'.$options['format'].'"');
		}
	}