/** * 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; }
/** * Print a readable stacktrace. If no strace is provided, will generate a new one. * * Options may include: * - prefix: string to insert a the beginning of each lines, default to empty * - suffix: string to insert at the end of each lines, default to windows carriage return '\r\n' * - base: transform absolute path to relative * * @return * @param object $trace[optional] * @param object $options[optional] */ public static function traceAsString($trace=null,$options=array()){ if(is_null($trace)) $trace = PurLang::trace(); elseif(!is_array($trace)) throw new InvalidArgumentException('Trace must be an array or null: "'.self::toString($trace).'" provided'); $content = ''; foreach($trace as $k=>$v){ if(isset($v['file'])){ if(isset($options['prefix'])) $content .= $options['prefix']; $file = $v['file']; if(!empty($options['base'])){ $_file = PurPath::relative($options['base'],$file); if(strpos($_file,'../')!==0){ $file = $_file; } unset($_file); } $content .= $file.':'.$v['line']." "; $content .= (array_key_exists('class',$v)?$v['class']:'').(array_key_exists('type',$v)?$v['type']:'').$v['function'].'()'; $content .= (isset($options['suffix']))?$options['suffix']:"\r\n"; } } return $content; }