classes/Builder.php
static function convertPropertyFileToYamlFile( $infile, $outfile='', $transform = array(), $prepend='' )
    {
        if ( $outfile == '' )
        {
            $outfile = self::getOptionsDir() . '/options.yaml';
        }
        $current = array();
        $out = array();
        foreach ( file( $infile ) as $line )
        {
            $line = trim( $line );
            if ( $line == '' )
            {
                $out[] = '';
            }
            else if ( strpos( $line, '<!--' ) === 0 )
            {
                $out[] .= preg_replace( '/^<!-- *(.*) *-->$/', '# $1', $line );
            }
            else if ( strpos( $line, '=' ) != 0 )
            {
                $line = explode( '=', $line, 2 );
                $path = explode( '.', trim( $line[0] ) );
                foreach( $transform as $src => $dst )
                {
                    foreach( $path as $i => $element )
                    {
                        if ( $element == $src )
                        {
                            if ( $dst == '' )
                            {
                                unset( $path[$i] );
                            }
                            else if ( is_array( $dst ) )
                            {
                                array_splice( $path, $i-1, 1, $dst );
                            }
                            else
                            {
                                $path[$i] = $dst;
                            }
                        }
                    }
                }
                // elements index can have holes here, cannot trust them => reorder
                $path = array_values( $path );

                $value = $line[1];
                $token = array_pop( $path );

                if ( $path != $current )
                {
                    $skip = 0;
                    foreach( $path as $j => $element )
                    {
                        if ( $element == @$current[$j] )
                        {
                            $skip++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    for( $j = $skip; $j < count( $path ); $j++ )
                        //foreach( $path as $j => $element )
                    {
                        $line = '';
                        for ( $i = 0; $i < $j; $i++ )
                        {
                            $line .= '    ';
                        }
                        $line .= $path[$j] . ':';
                        $out[] = $line;
                    }
                }
                $line = '';
                for ( $i = 0; $i < count( $path ); $i++ )
                {
                    $line .= '    ';
                }
                $line .= $token . ': ' . $value;
                $out[] = $line;
                $current = $path;
            }
            else
            {
                /// @todo log warning?
            }
        }
        pake_mkdirs( 'pake' );
        // ask confirmation if file exists
        $ok = !file_exists( $outfile ) || ( pake_input( "Destionation file $outfile exists. Overwrite? [y/n]", 'n' ) == 'y' );
        if ( $ok )
        {
            file_put_contents( $outfile, $prepend . implode( $out, "\n" ) );
            pake_echo_action( 'file+', $outfile );
        }
    }
static function convertPropertyFileToYamlFile( $infile, $outfile='', $transform = array(), $prepend='' )
    {
        if ( $outfile == '' )
        {
            $outfile = self::getOptionsDir() . '/options.yaml';
        }
        $current = array();
        $out = array();
        foreach ( file( $infile ) as $line )
        {
            $line = trim( $line );
            if ( $line == '' )
            {
                $out[] = '';
            }
            else if ( strpos( $line, '<!--' ) === 0 )
            {
                $out[] .= preg_replace( '/^<!-- *(.*) *-->$/', '# $1', $line );
            }
            else if ( strpos( $line, '=' ) != 0 )
            {
                $line = explode( '=', $line, 2 );
                $path = explode( '.', trim( $line[0] ) );
                foreach( $transform as $src => $dst )
                {
                    foreach( $path as $i => $element )
                    {
                        if ( $element == $src )
                        {
                            if ( $dst == '' )
                            {
                                unset( $path[$i] );
                            }
                            else if ( is_array( $dst ) )
                            {
                                array_splice( $path, $i-1, 1, $dst );
                            }
                            else
                            {
                                $path[$i] = $dst;
                            }
                        }
                    }
                }
                // elements index can have holes here, cannot trust them => reorder
                $path = array_values( $path );

                $value = $line[1];
                $token = array_pop( $path );

                if ( $path != $current )
                {
                    $skip = 0;
                    foreach( $path as $j => $element )
                    {
                        if ( $element == @$current[$j] )
                        {
                            $skip++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    for( $j = $skip; $j < count( $path ); $j++ )
                        //foreach( $path as $j => $element )
                    {
                        $line = '';
                        for ( $i = 0; $i < $j; $i++ )
                        {
                            $line .= '    ';
                        }
                        $line .= $path[$j] . ':';
                        $out[] = $line;
                    }
                }
                $line = '';
                for ( $i = 0; $i < count( $path ); $i++ )
                {
                    $line .= '    ';
                }
                $line .= $token . ': ' . $value;
                $out[] = $line;
                $current = $path;
            }
            else
            {
                /// @todo log warning?
            }
        }
        pake_mkdirs( 'pake' );
        // ask confirmation if file exists
        $ok = !file_exists( $outfile ) || ( pake_input( "Destionation file $outfile exists. Overwrite? [y/n]", 'n' ) == 'y' );
        if ( $ok )
        {
            file_put_contents( $outfile, $prepend . implode( $out, "\n" ) );
            pake_echo_action( 'file+', $outfile );
        }
    }
static function convertPropertyFileToYamlFile ( $ infile , $ outfile = '' , $ transform = array ( ) , $ prepend = '' ) { if ( $ outfile == '' ) { $ outfile = self :: getOptionsDir ( ) . '/options.yaml' ; } $ current = array ( ) ; $ out = array ( ) ; foreach ( file ( $ infile ) as $ line ) { $ line = trim ( $ line ) ; if ( $ line == '' ) { $ out [ ] = '' ; } else if ( strpos ( $ line , '<!--' ) === 0 ) { $ out [ ] .= preg_replace ( '/^<!-- *(.*) *-->$/' , '# $1' , $ line ) ; } else if ( strpos ( $ line , '=' ) != 0 ) { $ line = explode ( '=' , $ line , 2 ) ; $ path = explode ( '.' , trim ( $ line [ 0 ] ) ) ; foreach ( $ transform as $ src => $ dst ) { foreach ( $ path as $ i => $ element ) { if ( $ element == $ src ) { if ( $ dst == '' ) { unset ( $ path [ $ i ] ) ; } else if ( is_array ( $ dst ) ) { array_splice ( $ path , $ i - 1 , 1 , $ dst ) ; } else { $ path [ $ i ] = $ dst ; } } } } // elements index can have holes here, cannot trust them => reorder
 $ path = array_values ( $ path ) ; $ value = $ line [ 1 ] ; $ token = array_pop ( $ path ) ; if ( $ path != $ current ) { $ skip = 0 ; foreach ( $ path as $ j => $ element ) { if ( $ element == @ $ current [ $ j ] ) { $ skip ++ ; } else { break ; } } for ( $ j = $ skip ; $ j < count ( $ path ) ; $ j ++ ) //foreach( $path as $j => $element )
 { $ line = '' ; for ( $ i = 0 ; $ i < $ j ; $ i ++ ) { $ line .= '    ' ; } $ line .= $ path [ $ j ] . ':' ; $ out [ ] = $ line ; } } $ line = '' ; for ( $ i = 0 ; $ i < count ( $ path ) ; $ i ++ ) { $ line .= '    ' ; } $ line .= $ token . ': ' . $ value ; $ out [ ] = $ line ; $ current = $ path ; } else { /// @todo log warning?
 } } pake_mkdirs ( 'pake' ) ; // ask confirmation if file exists
 $ ok = ! file_exists ( $ outfile ) || ( pake_input ( "Destionation file $outfile exists. Overwrite? [y/n]" , 'n' ) == 'y' ) ; if ( $ ok ) { file_put_contents ( $ outfile , $ prepend . implode ( $ out , "\n" ) ) ; pake_echo_action ( 'file+' , $ outfile ) ; } }
Converts a property file into a yaml file
@param array $transform an array of transformation rules such as eg. 'sourcetag' => 'desttag' (desttag can be empty for tag removal or an array for tag expansion)
@todo move to a separate class to slim down base class?
@todo make it capable to remove complete $ext.version.alias property
Converts a property file into a yaml file