gwynne          Tue Aug  7 08:09:07 2007 UTC

  Removed files:               
    /phd/setup  HTTP.class.php SAPI.interface.php 

  Modified files:              
    /phd/setup  CLI.class.php Configurator.class.php 
                Option_Metadata.inc.php config.in.php setup.messages.php 
                setup.php 
  Log:
  Complete rework of the setup code for greater flexibility, code reuse, and 
modularity. Also removed some unnecessary options and added a new one. Updated 
the code that deals with themes to work with bjori's structure. Removed all the 
nonsense about multiple interfaces. Just use the CLI and be happy with it. If 
you need a Web interface that badly, write it yerself :).
  
  
http://cvs.php.net/viewvc.cgi/phd/setup/CLI.class.php?r1=1.6&r2=1.7&diff_format=u
Index: phd/setup/CLI.class.php
diff -u phd/setup/CLI.class.php:1.6 phd/setup/CLI.class.php:1.7
--- phd/setup/CLI.class.php:1.6 Sat Jul 28 13:22:51 2007
+++ phd/setup/CLI.class.php     Tue Aug  7 08:09:07 2007
@@ -1,6 +1,6 @@
 <?php
 
-/*  $Id: CLI.class.php,v 1.6 2007/07/28 13:22:51 gwynne Exp $
+/*  $Id: CLI.class.php,v 1.7 2007/08/07 08:09:07 gwynne Exp $
     +-------------------------------------------------------------------------+
     | Copyright(c) 2007                                                       |
     | Authors:                                                                |
@@ -14,18 +14,15 @@
     +-------------------------------------------------------------------------+
 */
 
-class PhD_CLI_Interface implements PhD_SAPI_Interface {
+class PhD_CLI_Interface {
     
     protected $quietMode = 0;
     
     public function __construct() {
-        
-        if ( php_sapi_name() !== 'cli' ) {
-            PhD_error( PhD_Errors::CLI_WRONG_SAPI );
-        }
-        
+
+        // If we someday have a version of PHP with the nice long getopt() on 
all systems patch...
         if ( in_array( '-h', $_SERVER[ 'argv' ] ) || in_array( '--help', 
$_SERVER[ 'argv' ] ) ) {
-            print PhD_Prompts::paramPrompt( PhD_Prompts::CLI_USAGE, $_SERVER[ 
'argv' ][ 0 ] );
+            print PhD_Output::paramString( 'Message', 'USAGE', $_SERVER[ 
'argv' ][ 0 ] );
             exit( 1 );
         }
         
@@ -42,133 +39,115 @@
     public function __destruct() {
     }
     
-    public function getName() {
-
-        return 'Commandline';
-    
-    }
-    
-    public function errorMessage( $message ) {
-        
-        print "ERROR: {$message}\n";
-        exit( 1 );
-    
-    }
-    
-    public function warningMessage( $message ) {
-        
-        print "WARNING: {$message}\n";
-    
-    }
-    
     public function run() {
         global $configurator, $OPTIONS, $OPTIONS_DATA;
         
         $now = date( DATE_RFC2822 );
-        print PhD_Prompts::paramPrompt( PhD_Prompts::CLI_CONFIG_BEGIN, $now );
+        print PhD_Output::paramString( 'Message', 'CONFIG_BEGIN', $now ) . 
"\n\n";
         
         do {
         
-            print PhD_Prompts::paramPrompt( PhD_Prompts::CLI_CURRENT_SETTINGS 
);
-            $this->displaySettings();
+            $this->displaySettings( 'CURRENT_SETTINGS' );
     
-            print PhD_Prompts::paramPrompt( PhD_Prompts::CLI_INSTRUCTIONS );
+            print PhD_Output::paramString( 'Prompt', 'INSTRUCTIONS' ) . "\n\n";
             
             foreach ( $OPTIONS_DATA as $optionName => $optionData ) {
-
+                
+                printf( "%-40s\n", "{$optionData[ 'display_name' ]}:" );
                 if ( $this->quietMode < 2 ) {
-                    print "\n{$optionData[ 'description' ]}";
+                    print "{$optionData[ 'description' ]}\n";
                 }
                 if ( $this->quietMode < 1 ) {
-                    print "\n{$optionData[ 'details' ]}";
+                    print "{$optionData[ 'details' ]}\n";
                 }
                 
-                $valueList = $optionData[ 'value_list_function' ]();
-                if ( is_null( $valueList ) ) {
-                    print "\n" . PhD_Prompts::paramPrompt( 
PhD_Prompts::CLI_NO_VALUES );
-                } else if ( is_bool( $valueList ) ) {
-                    print "\n" . PhD_Prompts::paramPrompt( 
PhD_Prompts::CLI_BOOLEAN_VALUES );
-                } else if ( is_int( $valueList ) ) {
-                    print "\n" . PhD_Prompts::paramPrompt( 
PhD_Prompts::CLI_NUMBYTES_VALUES );
-                } else {
-                    print "\n" . PhD_Prompts::paramPrompt( 
PhD_Prompts::CLI_AVAILABLE_VALUES,
-                        wordwrap( "\t" . implode( ' ', $valueList ) , 71, 
"\n\t", FALSE ) );
+                switch ( PhD_Options::getType( $optionName ) ) {
+                    case PhD_Options::TYPE_ARBITRARY:
+                        print PhD_Output::paramString( 'Message', 'NO_VALUES' 
);
+                        break;
+                    case PhD_Options::TYPE_LIST:
+                        print PhD_Output::paramString( 'Message', 
'AVAILABLE_VALUES',
+                            wordwrap( "\t" . implode( ' ', 
PhD_Options::getValueList( $optionName ) ), 71, "\n\t", FALSE ) );
+                        break;
+                    case PhD_Options::TYPE_NUMERIC:
+                        print PhD_Output::paramString( 'Message', 
'NUMERIC_VALUE',
+                            $optionData[ 'min_value' ], $optionData[ 
'max_value' ] );
+                        break;
+                    case PhD_Options::TYPE_FILESIZE:
+                        print PhD_Output::paramString( 'Message', 
'NUMBYTES_VALUES' );
+                        break;
+                    case PhD_Options::TYPE_FLAG:
+                        print PhD_Output::paramString( 'Message', 
'BOOLEAN_VALUES' );
+                        break;
+                    default:
+                        PhD_Error( 'INTERNAL_ERROR' );
                 }
                 
-                print "\n";
-
+                print "\n\n";
+                
                 do {
-                    $response = $this->getLine( PhD_Prompts::paramPrompt(
-                        PhD_Prompts::CLI_OPTION_PROMPT, $optionData[ 'prompt' 
], $configurator->$optionName ) );
+                    $response = $this->getLine( PhD_Output::paramString( 
'Prompt', 'OPTION_PROMPT', $optionData[ 'prompt' ],
+                        $configurator->$optionName ) );
                     if ( $response === '' ) {
                         $response = $configurator->$optionName;
                     }
-                    if ( $optionData[ 'validity_check_function' ]( $response ) 
=== TRUE ) {
+                    if ( PhD_Options::checkValidity( $optionName, $response ) 
=== TRUE ) {
                         break;
                     }
                     print "{$optionData[ 'invalid_message' ]}\n";
-                } while( TRUE );
+                } while ( TRUE );
                 
-                $configurator->$optionName = $optionData[ 
'final_value_function' ]( $response );
-                print "\n";
+                $configurator->$optionName = PhD_Options::getFinalValue( 
$optionName, $response );
                 
-            }
+                print "\n";
             
-            print "\n";
-            print PhD_Prompts::paramPrompt( PhD_Prompts::CLI_CHOSEN_SETTINGS );
-            $this->displaySettings();
+            }
+
+            $this->displaySettings( 'CHOSEN_SETTINGS' );
             
             do {
-                $response = $this->getLine( PhD_Prompts::paramPrompt( 
PhD_Prompts::CLI_CONFIG_COMPLETE ) );
+                $response = $this->getLine( PhD_Output::paramString( 'Prompt', 
'CONFIG_COMPLETE' ) );
 
                 switch ( strval( $response ) ) {
                     case 'yes':
                         return TRUE;
-                    
                     case 'restart':
                         continue 3;
-                    
                     case 'quit':
                         return FALSE;
-                    
                     default:
-                        print PhD_Prompts::paramPrompt( 
PhD_Prompts::CLI_INVALID_CONFIG_COMPLETE );
+                        print PhD_Output::paramString( 'Prompt', 
'INVALID_CONFIG_COMPLETE' );
                         continue 2;
                 }
             } while ( TRUE );
             
         } while ( TRUE );
-        
     }
     
     public function reportSuccess() {
-        
-        print PhD_Prompts::paramPrompt( PhD_Prompts::CLI_CONFIG_SAVED );
-    
+        print PhD_Output::paramString( 'Message', 'CONFIG_SAVED' );
     }
     
     protected function getLine( $prompt = NULL ) {
-        
         if ( !is_null( $prompt ) ) {
             print $prompt;
         }
         
         if ( ( $result = fgets( STDIN ) ) === FALSE ) {
-            PhD_Error( PhD_Errors::CLI_INPUT_EOF );
+            PhD_Error( 'INPUT_EOF' );
         }
         return trim( $result );
-    
     }
     
-    protected function displaySettings() {
-        global $configurator;
-
-        foreach ( getOptionNames() as $name ) {
+    protected function displaySettings( $headerConst ) {
+        global $configurator, $OPTIONS_DATA;
+        
+        print PhD_Output::paramString( 'Message', $headerConst ) . "\n";
+        foreach ( $OPTIONS_DATA as $name => $data ) {
             printf( "\t%-25s: %s\n", $name,
                 is_bool( $configurator->$name ) ? ( $configurator->$name ? 
"On" : "Off" ) : $configurator->$name );
         }
         print "\n";
-        
     }
 
 }
http://cvs.php.net/viewvc.cgi/phd/setup/Configurator.class.php?r1=1.4&r2=1.5&diff_format=u
Index: phd/setup/Configurator.class.php
diff -u phd/setup/Configurator.class.php:1.4 
phd/setup/Configurator.class.php:1.5
--- phd/setup/Configurator.class.php:1.4        Fri Jul 27 23:32:11 2007
+++ phd/setup/Configurator.class.php    Tue Aug  7 08:09:07 2007
@@ -1,6 +1,6 @@
 <?php
 
-/*  $Id: Configurator.class.php,v 1.4 2007/07/27 23:32:11 gwynne Exp $
+/*  $Id: Configurator.class.php,v 1.5 2007/08/07 08:09:07 gwynne Exp $
     +-------------------------------------------------------------------------+
     | Copyright(c) 2007                                                       |
     | Authors:                                                                |
@@ -21,63 +21,47 @@
     protected $config_php_path = '';
     
     public function __construct() {
-        
         $this->config_php_path = dirname( __FILE__ ) . '/../config.php';
-        
     }
     
     public function __destruct() {
     }
     
     public function __get( $name ) {
-        
         return $GLOBALS[ 'OPTIONS' ][ $name ];
-    
     }
     
     public function __isset( $name ) {
-        
         return isset( $GLOBALS[ 'OPTIONS' ][ $name ] );
-    
     }
     
     public function __set( $name, $value ) {
-        
         $GLOBALS[ 'OPTIONS' ][ $name ] = $value;
-        
     }
 
     public function __unset( $name ) {
-        
         unset( $GLOBALS[ 'OPTIONS' ][ $name ] );
-        
     }
     
     public function readConfig() {
-        
         if ( file_exists( $this->config_php_path ) && is_readable( 
$this->config_php_path ) && is_file( $this->config_php_path ) ) {
             require $this->config_php_path;
             $GLOBALS[ 'OPTIONS' ] = $OPTIONS;
         } else if ( file_exists( $this->config_php_path ) ) {
             PhD_Error( PhD_Errors::CONFIG_UNREADABLE );
         }
-        
     }
     
     public function isValidOptionValue( $name, $value ) {
-        
         $vf = $GLOBALS[ 'OPTIONS_DATA' ][ $name ][ 'validity_check_function' ];
         return is_callable( $vf ) ? $vf( $value ) : FALSE;
-    
     }
     
     public function writeConfig() {
-        
         try {
             $file = new Template_File( dirname( __FILE__ ) . '/config.in.php', 
$this->config_php_path, TRUE );
-            $file->SETUP_REV = $GLOBALS[ 'REVISION' ];
+            $file->SETUP_REV = $GLOBALS[ 'SETUP_REVISION' ];
             $file->SETUP_DATE = date( DATE_RFC2822 );
-            $file->SAPI = $GLOBALS[ 'chosenInterface' ]->getName();
             $file->OPTION_ARRAY = var_export( $GLOBALS[ 'OPTIONS' ], 1 );
             $file->writeTemplate();
             unset( $file );
@@ -93,7 +77,6 @@
             );
             PhD_Error( isset( $codeMap[ $e->getCode() ] ) ? $codeMap[ 
$e->getCode() ] : PhD_Errors::INTERNAL_ERROR );
         }
-
     }
 
 }
http://cvs.php.net/viewvc.cgi/phd/setup/Option_Metadata.inc.php?r1=1.5&r2=1.6&diff_format=u
Index: phd/setup/Option_Metadata.inc.php
diff -u phd/setup/Option_Metadata.inc.php:1.5 
phd/setup/Option_Metadata.inc.php:1.6
--- phd/setup/Option_Metadata.inc.php:1.5       Sat Jul 28 13:22:51 2007
+++ phd/setup/Option_Metadata.inc.php   Tue Aug  7 08:09:07 2007
@@ -1,6 +1,6 @@
 <?php
 
-/*  $Id: Option_Metadata.inc.php,v 1.5 2007/07/28 13:22:51 gwynne Exp $
+/*  $Id: Option_Metadata.inc.php,v 1.6 2007/08/07 08:09:07 gwynne Exp $
     +-------------------------------------------------------------------------+
     | Copyright(c) 2007                                                       |
     | Authors:                                                                |
@@ -14,13 +14,116 @@
     +-------------------------------------------------------------------------+
 */
 
-$OPTIONS_DATA_COMMON_FUNCS = array(
+class Phd_Options {
+    
+    const TYPE_ARBITRARY = 0;       // Any user-entered value
+    const TYPE_LIST = 1;            // One of a list of enumerated values
+    const TYPE_NUMERIC = 2;         // Any integer
+    const TYPE_FILESIZE = 3;        // A positive integer including the 
[KMGTP[B]] suffix
+    const TYPE_FLAG = 4;            // Boolean flag
+    
+    public static function getType( $optName ) {
+        global $OPTIONS_DATA;
+        
+        if ( empty( $OPTIONS_DATA[ $optName ] ) ) {
+            return NULL;
+        }
+        return $OPTIONS_DATA[ $optName ][ 'type' ];
+    }
+    
+    public static function getValueList( $optName ) {   // TYPE_LIST options 
only
+        global $OPTIONS_DATA;
+        
+        if ( PhD_Options::getType( $optName ) != PhD_Options::TYPE_LIST ) {
+            return NULL;
+        }
+        return call_user_func( $OPTIONS_DATA[ $optName ][ 'value_list_func' ] 
);
+    }
+    
+    public static function checkValidity( $optName, $value ) {
+        global $OPTIONS_DATA;
+        
+        if ( ( $type = PhD_Options::getType( $optName ) ) === NULL ) {
+            return NULL;
+        }
+        switch ( $type ) {
+            case PhD_Options::TYPE_ARBITRARY:
+                return call_user_func( $OPTIONS_DATA[ $optName ][ 
'validity_func' ], $value );
+            case PhD_Options::TYPE_LIST:
+                return in_array( $value, PhD_Options::getValueList( $optName ) 
);
+            case PhD_Options::TYPE_NUMERIC:
+                if ( ctype_digit( $value ) ) {
+                    return ( $value >= $OPTIONS_DATA[ $optName ][ 'min_value' 
] &&
+                             $value <= $OPTIONS_DATA[ $optName ][ 'max_value' 
] );
+                }
+                return FALSE;
+            case PhD_Options::TYPE_FILESIZE:
+                return preg_match( '/^(\d+)(?:([KMGTP])B?)?$/iu', $value ) ? 
TRUE : FALSE;
+            case PhD_Options::TYPE_FLAG:
+                return in_array( substr( strtolower( $value ), 0, 1 ), array( 
1, 0, 'y', 'n' ) ) || $value === TRUE || $value === FALSE;
+            default:
+                return NULL;
+        }
+    }
+    
+    public static function getFinalValue( $optName, $value ) {
+        global $OPTIONS_DATA;
+        
+        if ( ( $type = PhD_Options::getType( $optName ) ) === NULL ) {
+            return NULL;
+        }
+        switch ( $type ) {
+            case PhD_Options::TYPE_ARBITRARY:
+                return isset( $OPTIONS_DATA[ $optName ][ 'final_value_func' ] 
) ?
+                    call_user_func( $OPTIONS_DATA[ $optName ][ 
'final_value_func' ], $value ) : $value;
+            case PhD_Options::TYPE_LIST:
+            case PhD_Options::TYPE_NUMERIC:
+                return $value;
+            case PhD_Options::TYPE_FILESIZE:
+                preg_match( '/^(\d+)(?:([KMGTP])B?)?$/iu', $value, $matches );
+                $multipliers = array(
+                    '' => 1,
+                    'K' => 1024,
+                    'M' => 1048576,
+                    'G' => 1073741824,
+                    'T' => 1099511627776,
+                    'P' => 1125899906842620
+                );
+                return ( intval( $matches[ 1 ] ) * $multipliers[ strval( 
$matches[ 2 ] ) ] );
+            case PhD_Options::TYPE_FLAG:
+                return is_bool( $value ) ? $value : ( substr( strtolower( 
$value ), 0, 1 ) == 'y' ? TRUE : FALSE );
+            default:
+                return NULL;
+        }
+    }
+    
+}    
+
+function OPTIONS_META_scan_script_dir( $name ) {
+    static $lists = NULL;
+
+    if ( is_null( $lists ) ) {
+        $lists = array();
+    }
+    if ( !isset( $lists[ $name ] ) ) {
+        $path = dirname( __FILE__ ) . "/../{$name}";
+        if ( ( $files = @scandir( $path ) ) === FALSE ) {
+            PhD_Error( strtoupper( $name ) . '_UNREADABLE' );
+        }
+        $fileList = array_map( create_function( '$v', 'return substr( $v, 0, 
-4 );' ),
+            array_filter( $files, create_function( '$v', 'return substr( $v, 
-4 ) == ".php" && is_file( "'.$path.'/{$v}" );' ) ) );
+        if ( count( $fileList ) == 0 ) {
+            PhD_Error( strtoupper( $name ) . '_UNAVAILABLE' );
+        }
+        $lists[ $name ] = $fileList;
+    }
+    return $lists[ $name ];
+}
 
-    'get_languages_func' => create_function( '', <<<~FUNCTION
-global $OPTIONS_DATA, $OPTIONS;
-static $languages = NULL;
+function OPTIONS_META_get_languages() {
+    global $OPTIONS_DATA, $OPTIONS;
+    static $languages = NULL;
 
-if ( $OPTIONS_DATA[ 'xml_root' ][ 'validity_check_function' ]( $OPTIONS[ 
'xml_root' ] ) ) {
     if ( is_null( $languages ) ) {
         $d = $OPTIONS[ 'xml_root' ];
         if ( ( $languageList = @scandir( $d ) ) === FALSE ) {
@@ -31,56 +134,23 @@
     }
     return $languages;
 }
-return NULL;
-FUNCTION
-    ),
-    
-    'numbytes_value_list_func' => create_function( '', <<<~FUNCTION
-return 0;
-FUNCTION
-    ),
-    
-    'numbytes_validity_func' => create_function( '$v', <<<~FUNCTION
-return preg_match( '/^(\d+)(?:([KMGTP])B?)?$/iu', $v, $matches ) ? TRUE : 
FALSE;
-FUNCTION
-    ),
-    
-    'numbytes_final_value_func' => create_function( '$v', <<<~FUNCTION
-preg_match( '/^(\d+)(?:([KMGTP])B?)?$/iu', $v, $matches );
-$multipliers = array( '' => 1, 'K' => 1024, 'M' => 1048576, 'G' => 1073741824, 
'T' => 1099511627776, 'P' => 1125899906842620 );
-return ( intval( $matches[ 1 ] ) * $multipliers[ strval( $matches[ 2 ] ) ] );
-FUNCTION
-    ),
-
-    'boolean_value_list_func' => create_function( '', <<<~FUNCTION
-return FALSE;
-FUNCTION
-    ),
-
-    'boolean_validity_func' => create_function( '$v', <<<~FUNCTION
-return in_array( substr( strtolower( $v ), 0, 1 ), array( 1, 0, 'y', 'n' ) ) 
|| $v === TRUE || $v === FALSE;
-FUNCTION
-    ),
-    
-    'boolean_final_value_func' => create_function( '$v', <<<~FUNCTION
-return ( substr( strtolower( $v ), 0, 1 ) == 'y' ) ? TRUE : FALSE;
-FUNCTION
-    ),
-    
-    'verbatim_final_value_func' => create_function( '$v', <<<~FUNCTION
-return $v;
-FUNCTION
-    ),
-    
-    'unknown_value_list_func' => create_function( '', <<<~FUNCTION
-return NULL;
-FUNCTION
-    ),
 
-);
+function OPTIONS_META_validate_file_save( $v, $rp = NULL ) {
+    if ( ( $rp = realpath( $v ) ) === FALSE ) {
+        return FALSE;
+    }
+    $d = dirname( $rp );
+    if ( !is_dir( $d ) || !is_writable( $d ) || !is_executable( $d ) ||
+            ( file_exists( $rp ) && ( !is_writable( $rp ) || is_dir( $rp ) ) ) 
) {
+        return FALSE;
+    }
+    return TRUE;
+}
 
 $OPTIONS_DATA = array(
     'output_format' => array(
+        'display_name' => "Output Format",
+        'type' => PhD_Options::TYPE_LIST,
         'default_value' => 'xhtml',
         'description' => <<<~MESSAGE
 The output format for PhD determines the final form of any output it produces.
@@ -94,33 +164,17 @@
 conformance of any XML-based format.
 MESSAGE
         ,
-        'value_list_function' => create_function( '', <<<~FUNCTION
-static $formatList = NULL;
-
-if ( is_null( $formatList ) ) {
-    $path = dirname( __FILE__ ) . "/../formats";
-    if ( ( $formats = @scandir( $path ) ) === FALSE ) {
-        PhD_Error( "The formats directory is missing or unreadable at 
\"{$path}\"." );
-    }
-    $formatList = array_map( create_function( '$v', 'return substr( $v, 0, -4 
);' ),
-        array_filter( $formats, create_function( '$v', 'return substr( $v, -4 
) == ".php" && is_file( "'.$path.'/{$v}" );' ) ) );
-    if ( count( $formatList ) == 0 ) {
-        PhD_Error( "No output formats are available." );
-    }
-}
-return $formatList;
+        'value_list_func' => create_function( '', <<<~FUNCTION
+return OPTIONS_META_scan_script_dir( 'formats' );
 FUNCTION
         ),
-        'validity_check_function' => create_function( '$format', <<<~FUNCTION
-return in_array( $format, $GLOBALS[ 'OPTIONS_DATA' ][ 'output_format' ][ 
'value_list_function' ]() );
-FUNCTION
-        ),
-        'final_value_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'verbatim_final_value_func' ],
         'prompt' => 'Choose a format',
         'invalid_message' => 'That is not an available format. Please try 
again.'
     ),
     
     'output_theme' => array(
+        'display_name' => 'Output Theme',
+        'type' => PhD_Options::TYPE_LIST,
         'default_value' => 'default',
         'description' => <<<~MESSAGE
 The output theme for PhD determines site-specific alterations to the selected
@@ -133,33 +187,17 @@
 administrator for the site to function.
 MESSAGE
         ,
-        'value_list_function' => create_function( '', <<<~FUNCTION
-static $themeList = NULL;
-
-if ( is_null( $themeList ) ) {
-    $path = dirname( __FILE__ ) . "/../themes";
-    if ( ( $themes = @scandir( $path ) ) === FALSE ) {
-        PhD_Error( "The themes directory is missing or unreadable." );
-    }
-    $themeList = array_filter( $themes,
-        create_function( '$v', 'return is_dir( "'.$path.'/{$v}" ) && 
!in_array( $v, array( ".", "..", "CVS" ) );' ) );
-    if ( count( $themeList ) == 0 ) {
-        PhD_Error( "No themes are available." );
-    }
-}
-return $themeList;
-FUNCTION
-        ),
-        'validity_check_function' => create_function( '$theme', <<<~FUNCTION
-return in_array( $theme, $GLOBALS[ 'OPTIONS_DATA' ][ 'output_theme' ][ 
'value_list_function' ]() );
+        'value_list_func' => create_function( '', <<<~FUNCTION
+return OPTIONS_META_scan_script_dir( 'themes' );
 FUNCTION
         ),
-        'final_value_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'verbatim_final_value_func' ],
         'prompt' => 'Choose a theme',
         'invalid_message' => 'That is not an available theme. Please try 
again.'
     ),
     
     'output_encoding' => array(
+        'display_name' => 'Output Encoding',
+        'type' => PhD_Options::TYPE_ARBITRARY,
         'default_value' => 'utf-8',
         'description' => <<<~MESSAGE
 The output encoding for PDP-E determines the encoding that will be used for all
@@ -177,17 +215,17 @@
 for an unsupported encoding.
 MESSAGE
         ,
-        'value_list_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'unknown_value_list_func' ],
-        'validity_check_function' => create_function( '$encoding', <<<~FUNCTION
+        'validity_func' => create_function( '$encoding', <<<~FUNCTION
 return iconv( $encoding, $encoding, "Test string" ) === "Test string";
 FUNCTION
         ),
-        'final_value_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'verbatim_final_value_func' ],
         'prompt' => 'Choose an encoding',
         'invalid_message' => 'That encoding does not appear to be supported by 
your libiconv. Please try another.'
     ),
     
     'xml_root' => array(
+        'display_name' => 'XML Root Directory',
+        'type' => PhD_Options::TYPE_ARBITRARY,
         'default_value' => '/INVALID/PATH',
         'description' => <<<~MESSAGE
 The location of the language trees.
@@ -201,13 +239,11 @@
 done. Symbolic links are resolved at run time.
 MESSAGE
         ,
-        'value_list_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'unknown_value_list_func' ],
-        'validity_check_function' => create_function( '$root', <<<~FUNCTION
+        'validity_func' => create_function( '$root', <<<~FUNCTION
 $rv = realpath( $root );
 return ( $rv !== FALSE && is_dir( $rv ) && is_readable( $rv ) && 
is_executable( $rv ) && is_dir( "{$rv}/en" ) );
 FUNCTION
         ),
-        'final_value_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'verbatim_final_value_func' ],
         'prompt' => 'Enter the full path to the XML root',
         'invalid_message' => <<<~MESSAGE
 The path you entered does not exist, is not a directory, is not readable, is
@@ -216,6 +252,8 @@
     ),
     
     'language' => array(
+        'display_name' => 'Primary Language',
+        'type' => PhD_Options::TYPE_LIST,
         'default_value' => 'en',
         'description' => <<<~MESSAGE
 The language tells PhD which set of translations to use for display. The
@@ -230,12 +268,7 @@
 translated version of a page is not found.
 MESSAGE
         ,
-        'value_list_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'get_languages_func' ],
-        'validity_check_function' => create_function( '$v', <<<~FUNCTION
-return in_array( $v, $GLOBALS[ 'OPTIONS_DATA' ][ 'language' ][ 
'value_list_function' ]() );
-FUNCTION
-        ),
-        'final_value_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'verbatim_final_value_func' ],
+        'value_list_func' => 'OPTIONS_META_get_languages',
         'prompt' => 'Choose a primary language code',
         'invalid_message' => <<<~MESSAGE
 The language code you entered does not appear to exist, or is not a directory
@@ -244,6 +277,8 @@
     ),
     
     'fallback_language' => array(
+        'display_name' => 'Fallback Language',
+        'type' => PhD_Options::TYPE_LIST,
         'default_value' => 'en',
         'description' => <<<~MESSAGE
 The fallback language is used before English when PhD can not find a translated
@@ -257,12 +292,7 @@
 make more sense for a site. The default is English, causing immediate fallback.
 MESSAGE
         ,
-        'value_list_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'get_languages_func' ],
-        'validity_check_function' => create_function( '$v', <<<~FUNCTION
-return in_array( $v, $GLOBALS[ 'OPTIONS_DATA' ][ 'language' ][ 
'value_list_function' ]() );
-FUNCTION
-        ),
-        'final_value_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'verbatim_final_value_func' ],
+        'value_list_func' => 'OPTIONS_META_get_languages',
         'prompt' => 'Choose a fallback language code',
         'invalid_message' => <<<~MESSAGE
 The language code you entered does not appear to exist, or is not a directory
@@ -271,6 +301,8 @@
     ),
     
     'enforce_revisions' => array(
+        'display_name' => 'Revision Enforce flag',
+        'type' => PhD_Options::TYPE_FLAG,
         'default_value' => FALSE,
         'description' => <<<~MESSAGE
 PhD is capable of using either traditional <!-- Revision: --> and
@@ -288,76 +320,40 @@
 an error or warning to users.
 MESSAGE
         ,
-        'value_list_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'boolean_value_list_func' ],
-        'validity_check_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'boolean_validity_func' ],
-        'final_value_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'boolean_final_value_func' ],
         'prompt' => 'Type "(Y)es" to enable revision control, or "(N)o" to 
disable it',
         'invalid_message' => 'Please enter "(Y)es" or "(N)o".'
     ),
     
-    'database_path' => array(
-        'default_value' => '/INVALID/PATH/phd-data.sqlite',
+    'build_log_file' => array(
+        'display_name' => 'Build Log',
+        'type' => PhD_Options::TYPE_ARBITRARY,
+        'default_value' => 'none',
         'description' => <<<~MESSAGE
-The database path tells PhD where to store the SQLite 3 database file, used for
-indexing and cache data. Most installations will want to place the database
-file in the same directory as PhD itself.
+The log file is where PhD stores the output of the first phase of operation,
+the conversion of xml_root's multitude of XML files into a single blog.
 MESSAGE
         ,
         'details' => <<<~MESSAGE
-This setup will attempt to create a database file in the given location and
-remove it again. The user running PhD must have write and execute permissions
-to the enclosing directory. The file name can be whatever best suits the needs
-of the host system.
+Running the many-to-one build process can sometimes produce a copious amount of
+output, especially with the debug flag on. This setting is provided to
+automatically dump that output to a file for convenience. Multiple runs of the
+build will overwrite an existing log file, so be careful.
 MESSAGE
         ,
-        'value_list_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'unknown_value_list_func' ],
-        'validity_check_function' => create_function( '$path', <<<~FUNCTION
-try {
-    $d = dirname( realpath( $path ) );
-    if ( !is_dir( $d ) || !is_writable( $d ) || !is_executable( $d ) ) {
-        return FALSE;
-    }
-    $p = new PDO( "sqlite:{$path}", NULL, NULL, array( PDO::ATTR_ERRMODE => 
PDO::ERRMODE_EXCEPTION ) );
-    $p = NULL;
-    unset( $p );
-    return @unlink( $path );
-} catch ( PDOException $e ) {
-    return FALSE;
-}
+        'validity_func' => create_function( '$v', <<<~FUNCTION
+return ( $v === 'none' || OPTIONS_META_validate_file_save( $v ) );
 FUNCTION
         ),
-        'final_value_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'verbatim_final_value_func' ],
-        'prompt' => 'Enter the full path to the database file',
+        'prompt' => 'Enter the full path to the build log, or "none" to log to 
stdout',
         'invalid_message' => <<<~MESSAGE
-The path is invalid, you don't have write permission to it, an existing
-database file is in the way, or loading SQLite failed. Please try again.
+The path you entered is invalid or you don't have write permission to it.
+Please try again.
 MESSAGE
     ),
     
-    'chunking_memory_limit' => array(
-        'default_value' => ( 100 * 1048576 ),  // 100MB
-        'description' => <<<~MESSAGE
-The chunking memory limit controls how big a single chunk of output data must
-grow for PhD to begin spooling it to disk to avoid memory exhaustion.
-MESSAGE
-        ,
-        'details' => <<<~MESSAGE
-While performing transformations, PhD stores a growing chunk in memory for
-efficiency. However, efficiency will quickly degrade if the chunk is too large.
-This is particularly problematic for output formats and themes which don't do
-any chunking at all. Setting this limit to zero will force PhD to spool for all
-chunks, no matter how small. This is the recommended setting for non-chunking
-outputs; the default is fine for most other installations.
-MESSAGE
-        ,
-        'value_list_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'numbytes_value_list_func' ],
-        'validity_check_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'numbytes_validity_func' ],
-        'final_value_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'numbytes_final_value_func' ],
-        'prompt' => 'Enter the chunking limit',
-        'invalid_message' => 'You must enter a valid numeric value.'
-    ),
-    
     'debug' => array(
+        'display_name' => 'Debug flag',
+        'type' => PhD_Options::TYPE_FLAG,
         'default_value' => FALSE,
         'description' => <<<~MESSAGE
 The debug flag controls whether PhD runs in debug mode. This should NEVER be
@@ -373,20 +369,11 @@
 administration.
 MESSAGE
         ,
-        'value_list_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'boolean_value_list_func' ],
-        'validity_check_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'boolean_validity_func' ],
-        'final_value_function' => $OPTIONS_DATA_COMMON_FUNCS[ 
'boolean_final_value_func' ],
         'prompt' => 'Type "(Y)es" to enable debug output, or "(N)o" to disable 
it',
         'invalid_message' => 'Please enter "(Y)es" or "(N)o".'
     ),
-
 );
 
-function getOptionNames() {
-    return array_filter( array_keys( $GLOBALS[ 'OPTIONS_DATA' ] ),
-    create_function( '$v', 'return strncmp( "__", $v, 2 );' ) );
-}
-
 /*
 * vim600: sw=4 ts=4 fdm=syntax syntax=php et
 * vim<600: sw=4 ts=4
http://cvs.php.net/viewvc.cgi/phd/setup/config.in.php?r1=1.1&r2=1.2&diff_format=u
Index: phd/setup/config.in.php
diff -u phd/setup/config.in.php:1.1 phd/setup/config.in.php:1.2
--- phd/setup/config.in.php:1.1 Wed Jul 25 04:52:54 2007
+++ phd/setup/config.in.php     Tue Aug  7 08:09:07 2007
@@ -1,6 +1,6 @@
 <?php
 /* This file is autogenerated by setup.php. Do not edit directly. */
-/* Generated by PhD @SETUP_REV@ at @SETUP_DATE@ by @SAPI@ interface. */
+/* Generated by PhD @SETUP_REV@ at @[EMAIL PROTECTED] */
 
 $OPTIONS = @OPTION_ARRAY@;
 
http://cvs.php.net/viewvc.cgi/phd/setup/setup.messages.php?r1=1.5&r2=1.6&diff_format=u
Index: phd/setup/setup.messages.php
diff -u phd/setup/setup.messages.php:1.5 phd/setup/setup.messages.php:1.6
--- phd/setup/setup.messages.php:1.5    Sat Jul 28 13:22:51 2007
+++ phd/setup/setup.messages.php        Tue Aug  7 08:09:07 2007
@@ -1,6 +1,6 @@
 <?php
 
-/*  $Id: setup.messages.php,v 1.5 2007/07/28 13:22:51 gwynne Exp $
+/*  $Id: setup.messages.php,v 1.6 2007/08/07 08:09:07 gwynne Exp $
     +-------------------------------------------------------------------------+
     | Copyright(c) 2007                                                       |
     | Authors:                                                                |
@@ -14,10 +14,80 @@
     +-------------------------------------------------------------------------+
 */
 
+class PhD_Output {
+    
+    protected static $argList = NULL;
+    protected static function paramStringCallback( $v ) {
+        $v = next( self::$argList );
+        return ( is_bool( $v ) ? ( $v ? "Yes" : "No" ) : $v );
+    }
+    public static function paramString( $whichClass, $constName /*, ... */ ) {
+        self::$argList = func_get_args(); next( self::$argList );
+        $str = constant( "PhD_{$whichClass}s::{$constName}" );
+        return count( self::$argList ) > 2 ?
+            preg_replace_callback( '/%%%/', array( __CLASS__, 
'paramStringCallback' ), $str ) :
+            $str;
+    }
+
+}
+    
+class PhD_Messages {
+    
+    const USAGE = <<<~MESSAGE
+PhD per-site configuration setup. Commandline interface.
+Usage:
+%%% [options]
+    -v | --verbose          Give full details on configuration options.
+                            This is the default.
+    -q | --quiet            Give shorter descriptions of configuration options.
+    -s | --silent           Give no descriptions of configuration options.
+    -h | --help             Show this message.
+MESSAGE;
+    
+    const CONFIG_BEGIN = <<<~MESSAGE
+PhD per-site configuration setup. Commandline interface.
+Run began at %%%.
+MESSAGE;
+
+    const CURRENT_SETTINGS = <<<~MESSAGE
+Current settings:
+MESSAGE;
+
+    const NO_VALUES = <<<~MESSAGE
+There is no list of possible values available.
+MESSAGE;
+    
+    const BOOLEAN_VALUES = <<<~MESSAGE
+This is a yes/no setting.
+MESSAGE;
+    
+    const NUMBYTES_VALUES = <<<~MESSAGE
+This is a value given in number of bytes. For convenience you may use any of
+the following suffixes to multiply the number by the shown factor. By the way,
+if you actually use the P suffix, I pity you.
+    K = 1024, M = K*1024, G = M*1024, T = G*1024, P = T*1024
+MESSAGE;
+
+    const AVAILABLE_VALUES = <<<~MESSAGE
+The available values in this installation are:
+%%%
+MESSAGE;
+    
+    const CHOSEN_SETTINGS = <<<~MESSAGE
+Chosen settings:
+MESSAGE;
+
+    const CONFIG_SAVED = <<<~MESSAGE
+The settings were successfully saved to config.php. You may now start using
+PhD.
+MESSAGE;
+
+}    
+
 class PhD_Errors {
     
-    const EMBED_UNSUPPORTED = <<<~ERRMSG
-Embedded SAPI is not supported by PhD.
+    const ONLY_CLI_SUPPORTED = <<<~ERRMSG
+The PhD setup application requires the CLI interface.
 ERRMSG;
     
     const CONFIG_UNREADABLE = <<<~ERRMSG
@@ -48,12 +118,24 @@
 The template file does not exist or is unreadable.
 ERRMSG;
 
-    const CLI_WRONG_SAPI = <<<~ERRMSG
-The CLI interface requires the CLI SAPI!
+    const INPUT_EOF = <<<~ERRMSG
+Input ended unexpectedly.
 ERRMSG;
 
-    const CLI_INPUT_EOF = <<<~ERRMSG
-Input ended unexpectedly.
+    const FORMATS_UNREADABLE = <<<~ERRMSG
+The formats directory is missing or unreadable.
+ERRMSG;
+
+    const FORMATS_UNAVAILABLE = <<<~ERRMSG
+There are no output formats available.
+ERRMSG;
+
+    const THEMES_UNREADABLE = <<<~ERRMSG
+The themes directory is missing or unreadable.
+ERRMSG;
+
+    const THEMES_UNAVAILABLE = <<<~ERRMSG
+There are no output themes available.
 ERRMSG;
     
     const INTERNAL_ERROR = <<<~ERRMSG
@@ -72,103 +154,24 @@
 
 class PhD_Prompts {
     
-    public static function paramPrompt( $prompt/*, ... */ ) {
-        
-        $args = func_get_args();
-$c = '
-static $a = NULL;
-if ( is_null( $a ) ) {
-    $a = unserialize(\''.serialize($args).'\');
-}
-$v = next( $a );
-return ( is_bool( $v ) ? ( $v ? "Yes" : "No" ) : $v );
-';
-
-        return count( $args ) > 1 ? preg_replace_callback( '/%%%/',
-            create_function( '$v', $c ),
-            $prompt ) : $prompt;
-    
-    }
-    
-    const CLI_USAGE = <<<~PROMPTMSG
-PhD per-site configuration setup. Commandline interface.
-Usage:
-%%% [options]
-    -v | --verbose          Give full details on configuration options.
-                            This is the default.
-    -q | --quiet            Give shorter descriptions of configuration options.
-    -s | --silent           Give no descriptions of configuration options.
-    -h | --help             Show this message.
-
-PROMPTMSG;
-    
-    const CLI_CONFIG_BEGIN = <<<~PROMPTMSG
-PhD per-site configuration setup. Commandline interface.
-Run began at %%%.
-
-PROMPTMSG;
-
-    const CLI_CURRENT_SETTINGS = <<<~PROMPTMSG
-Current settings:
-
-PROMPTMSG;
-
-    const CLI_INSTRUCTIONS = <<<~PROMPTMSG
+    const INSTRUCTIONS = <<<~PROMPTMSG
 Press return without entering any text to leave an option at its current value.
 This will be rejected for options which require a value but whose current value
 is empty.
-
-
 PROMPTMSG;
 
-    const CLI_NO_VALUES = <<<~PROMPTMSG
-There is no list of possible values available.
-
-PROMPTMSG;
-    
-    const CLI_BOOLEAN_VALUES = <<<~PROMPTMSG
-This is a yes/no setting.
-
-PROMPTMSG;
-    
-    const CLI_NUMBYTES_VALUES = <<<~PROMPTMSG
-This is a value given in number of bytes. For convenience you may use any of
-the following suffixes to multiply the number by the shown factor. By the way,
-if you actually use the P suffix, I pity you.
-    K = 1024, M = K*1024, G = M*1024, T = G*1024, P = T*1024
-
-PROMPTMSG;
-
-    const CLI_AVAILABLE_VALUES = <<<~PROMPTMSG
-The available values in this installation are:
-%%%
-
-PROMPTMSG;
-
-    const CLI_OPTION_PROMPT = <<<~PROMPTMSG
+    const OPTION_PROMPT = <<<~PROMPTMSG
 %%% [%%%]: 
 PROMPTMSG;
     
-    const CLI_CHOSEN_SETTINGS = <<<~PROMPTMSG
-Chosen settings:
-
-PROMPTMSG;
-
-    const CLI_CONFIG_COMPLETE = <<<~PROMPTMSG
+    const CONFIG_COMPLETE = <<<~PROMPTMSG
 To confirm these settings, type "yes" now.
 To start over, type "restart".
 To quit without saving, type "quit": 
 PROMPTMSG;
 
-    const CLI_INVALID_CONFIG_COMPLETE = <<<~PROMPTMSG
+    const INVALID_CONFIG_COMPLETE = <<<~PROMPTMSG
 This is not a valid response. Please try again.
-
-PROMPTMSG;
-    
-    const CLI_CONFIG_SAVED = <<<~PROMPTMSG
-The settings were successfully saved to config.php. You may now start using
-PhD.
-
 PROMPTMSG;
 
 }
http://cvs.php.net/viewvc.cgi/phd/setup/setup.php?r1=1.4&r2=1.5&diff_format=u
Index: phd/setup/setup.php
diff -u phd/setup/setup.php:1.4 phd/setup/setup.php:1.5
--- phd/setup/setup.php:1.4     Sat Jul 28 13:22:51 2007
+++ phd/setup/setup.php Tue Aug  7 08:09:07 2007
@@ -1,6 +1,6 @@
 <?php
 
-/*  $Id: setup.php,v 1.4 2007/07/28 13:22:51 gwynne Exp $
+/*  $Id: setup.php,v 1.5 2007/08/07 08:09:07 gwynne Exp $
     +-------------------------------------------------------------------------+
     | Copyright(c) 2007                                                       |
     | Authors:                                                                |
@@ -10,86 +10,62 @@
     | world-wide-web at the following url:                                    |
     | http://phd.php.net/LICENSE                                              |
     +-------------------------------------------------------------------------+
-    | Provides a simple HTML and CLI interface for configuration of the       |
-    | per-site PhD system options. Must be ubiquitous with respect to the     |
-    | options provided by each interface. Selects interface automatically     |
-    | based on the SAPI in use. Chosen options are saved in config.php, an    |
+    | Provides a simple CLI interface for configuration of the per-site PhD   |
+    | system options. Chosen options are saved in config.php, an              |
     | automagically generated file. An existing config.php is presumed to     |
     | offer defaults for setup. No user authentication is done by this        |
-    | script; do not make it accessible in your production tree.              |
+    | script; do not make it accessible to non-administrators.                |
     +-------------------------------------------------------------------------+
 */
 
-// Used for versioning.
-$REVISION = '$Id: setup.php,v 1.4 2007/07/28 13:22:51 gwynne Exp $';
-
-// Chosen interface for the setup. Determined from SAPI name at main()-time.
-$chosenInterface = NULL;
-
-// Configurator instance.
-$configurator = NULL;
+$SETUP_REVISION = '$Id: setup.php,v 1.5 2007/08/07 08:09:07 gwynne Exp $';
 
 /*---------------------------------------------------------------------------*/
 require_once 'setup.messages.php';
 require_once 'Option_Metadata.inc.php';
-/*---------------------------------------------------------------------------*/
 require_once 'Configurator.class.php';
-/*---------------------------------------------------------------------------*/
-require_once 'SAPI.interface.php';
-/*---------------------------------------------------------------------------*/
 require_once 'CLI.class.php';
-require_once 'HTTP.class.php';
-/*---------------------------------------------------------------------------*/
-
-$configurator = new PhD_Configurator;
-
-switch ( php_sapi_name() ) {
-
-    case 'cli':
-        $chosenInterface = new PhD_CLI_Interface;
-        break;
-    
-    case 'embed':
-        PhD_Error( PhD_Errors::EMBED_UNSUPPORTED );
-        break;
-
-    case 'cgi': // Assume all others are HTTP for now
-    default:
-        $chosenInterface = new PhD_HTTP_Interface;
-        break;
-    
-}
 
+/*---------------------------------------------------------------------------*/
 function PhD_Error( $message ) {
-    
-    $GLOBALS[ 'chosenInterface' ]->errorMessage( $message );
-
+    print "ERROR: " . PhD_Output::paramString( 'Error', $message ) . "\n";
+    exit( 1 );
 }
 
 function PhD_Warning( $message ) {
-    
-    $GLOBALS[ 'chosenInterface' ]->warningMessage( $message );
-    
+    print "WARNING: " . PhD_Output::paramString( 'Warning', $message ) ."\n";
+}
+
+/*---------------------------------------------------------------------------*/
+$userInterface = NULL;
+$configurator = NULL;
+
+/*---------------------------------------------------------------------------*/
+if ( php_sapi_name() != 'cli' ) {
+    PhD_Error( 'ONLY_CLI_SUPPORTED' );
 }
+$configurator = new PhD_Configurator;
+$userInterface = new PhD_CLI_Interface;
 
+/*---------------------------------------------------------------------------*/
 // Fill in defaults.
 $OPTIONS = array();
 foreach ( $OPTIONS_DATA as $name => $data ) {
     $OPTIONS[ $name ] = $data[ 'default_value' ];
 }
 
+/*---------------------------------------------------------------------------*/
 // Pull in any existing config.php.
 $configurator->readConfig();
 
-// Let the interface determine how to run. TRUE if user chose values, FALSE if 
user wanted to break out
-if ( $chosenInterface->run() === TRUE ) {
-    
+/*---------------------------------------------------------------------------*/
+// Run the interface. TRUE if user chose values, FALSE if user wanted to break 
out
+if ( $userInterface->run() === TRUE ) {
     // We have a set of values. We trust the interface to have checked the 
validity.
     $configurator->writeConfig();
-    $chosenInterface->reportSuccess();
-
+    $userInterface->reportSuccess();
 } else {
-    PhD_Warning( PhD_Warnings::UNSAVED_CHANGES );
+    PhD_Warning( 'UNSAVED_CHANGES' );
 }
 
 /*

Reply via email to