[ Index ]

PHP Cross Reference of Automap

title

Body

[close]

/Automap/CLI/ -> Cmd.php (source)

   1  <?php
   2  //=============================================================================
   3  //
   4  // Copyright Francois Laupretre <automap@tekwire.net>
   5  //
   6  //   Licensed under the Apache License, Version 2.0 (the "License");
   7  //   you may not use this file except in compliance with the License.
   8  //   You may obtain a copy of the License at
   9  //
  10  //       http://www.apache.org/licenses/LICENSE-2.0
  11  //
  12  //   Unless required by applicable law or agreed to in writing, software
  13  //   distributed under the License is distributed on an "AS IS" BASIS,
  14  //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15  //   See the License for the specific language governing permissions and
  16  //   limitations under the License.
  17  //
  18  //=============================================================================
  19  /**
  20  * @copyright Francois Laupretre <automap@tekwire.net>
  21  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0
  22  * @category Automap
  23  * @package Automap
  24  *///==========================================================================
  25  
  26  //=============================================================================
  27  /**
  28  * The main script of the CLI Automap manager tool.
  29  *
  30  * API status: Private
  31  * Included in the PHK PHP runtime: No
  32  * Implemented in the extension: No
  33  *///==========================================================================
  34  
  35  namespace Automap\CLI {
  36  
  37  if (!class_exists('Automap\CLI\Cmd',false)) 
  38  {
  39  class Cmd
  40  {
  41  //---------
  42  
  43  private static function errorAbort($msg,$usage=true)
  44  {
  45  if ($usage) $msg .= " - Use 'help' command for syntax";
  46  throw new \Exception($msg);
  47  }
  48  
  49  //---------
  50  
  51  private static function usage()
  52  {
  53  echo "
  54  Available commands :
  55  
  56    - register [-a] [-b <base_path>] <relative paths...>
  57          Scans PHP scripts and builds a map. The relative paths can reference
  58          regular files and/or directories. Directories are scanned recursively
  59          and every PHP scripts they contain are scanned.
  60          Options :
  61              -a : Append. If the map file exists, add symbols without recreating it
  62              -b <base_path> : Specifies a base path. If relative, the reference
  63                               is the map file directory.
  64  
  65    - show [-f {auto|html|text}]
  66          Displays the content of a map file
  67          Options :
  68              -f <format> : Output format. Default is 'auto'.
  69  
  70    - check
  71          Checks a map file
  72  
  73    - export [-o <path>]
  74          Exports the symbol table from a map file
  75          Options :
  76              -o <path> : path of file to create with exported data. Default is
  77                          to write to stdout.
  78  
  79    - import [-a] [-i <path>]
  80          Import symbols from an exported file
  81          Options :
  82              -i <path> : path of file where data will be read. Default is to read
  83                          from stdin.
  84              -a : If the map file exists, add symbols without recreating it
  85  
  86    - setOption <name> <value>
  87          Sets an option in an existing map
  88  
  89    - unsetOption <name>
  90          Unsets an option in an existing map
  91  
  92    - help
  93          Display this message
  94  
  95  Global options :
  96  
  97    -v : Increase verbose level (can be set more than once)
  98    -q : Decrease verbose level (can be set more than once)
  99    -m <path> : Specifies the path of the map file the command applies to. Default
 100                is './auto.map'.
 101  
 102  More information at http://automap.tekwire.net\n\n";
 103  }
 104  
 105  //---------
 106  // Main
 107  // Options can be located before AND after the action keyword.
 108  
 109  public static function run($args)
 110  {
 111  $op=new Options;
 112  $op->parseAll($args);
 113  $action=(count($args)) ? array_shift($args) : 'help';
 114  
 115  switch($action)
 116      {
 117      case 'show':
 118          $map=new \Automap\Map($op->option('map_path'));
 119          $map->show($op->option('format'));
 120          break;
 121  
 122      case 'check':
 123          $map=new \Automap\Map($op->option('map_path'));
 124          $errs=$map->check($id);
 125          if (count($errs))
 126              {
 127              foreach($errs as $err) \Phool\Display::error($err);
 128              throw new \Exception("*** The check procedure found errors in file $mapfile");
 129              }
 130          \Phool\Display::info('Check OK');
 131          break;
 132  
 133      case 'setOption':
 134          if (count($args)!=2) self::errorAbort('setOption requires 2 arguments');
 135          list($name,$value)=$args;
 136          $map=new \Automap\Build\Creator();
 137          $map->readMapFile($op->option('map_path'));
 138          $map->setOption($name,$value);
 139          $map->save($op->option('map_path'));
 140          break;
 141  
 142      case 'unsetOption':
 143          if (count($args)!=1) self::errorAbort('unsetOption requires 1 argument');
 144          $name=array_shift($args);
 145          $map=new \Automap\Build\Creator();
 146          $map->readMapFile($op->option('map_path'));
 147          $map->unsetOption($name);
 148          $map->save($op->option('map_path'));
 149          break;
 150  
 151      case 'register_extensions':
 152          //-- Must be executed with :
 153          //-- php -n -d <Extension_dir> automap.phk register_extensions
 154          //-- in order to ignore extension preloading directives in php.ini
 155          //-- (if an extension is already loaded, we cannot determine which file
 156          //-- it came from). The '-d' flag is mandatory as long as PHP cannot
 157          //-- dl() outside of 'extension_dir'.
 158  
 159          $map=new \Automap\Build\Creator();
 160          if (($op->option('append')) && is_file($op->option('map_path')))
 161              $map->readMapFile($op->option('map_path'));
 162          $map->registerExtensionDir();
 163          $map->save($op->option('map_path'));
 164          break;
 165  
 166      case 'register':
 167          $map=new \Automap\Build\Creator();
 168          if (($op->option('append')) && is_file($op->option('map_path')))
 169              $map->readMapFile($op->option('map_path'));
 170          $abs_map_dir=\Phool\File::mkAbsolutePath(dirname($op->option('map_path')));
 171          if (!is_null($op->option('base_path')))
 172              $map->setOption('base_path',$op->option('base_path'));
 173          $abs_base=\Phool\File::combinePath($abs_map_dir,$map->option('base_path'));
 174          foreach($args as $rpath)
 175              {
 176              $abs_path=\Phool\File::combinePath($abs_base,$rpath);
 177              $map->registerPath($abs_path,$rpath);
 178              }
 179          $map->save($op->option('map_path'));
 180          break;
 181  
 182      case 'export':
 183          $map=new \Automap\Map($op->option('map_path'));
 184          $map->export($op->option('output'));
 185          break;
 186  
 187      case 'import':
 188          $map=new \Automap\Build\Creator();
 189          if (($op->option('append')) && is_file($op->option('map_path')))
 190              $map->readMapFile($op->option('map_path'));
 191          $map->import($op->option('input'));
 192          $map->save($op->option('map_path'));
 193          break;
 194  
 195      case 'help':
 196          self::usage();
 197          break;
 198  
 199      default:
 200          self::errorAbort("Unknown action: '$action'");
 201      }
 202  }
 203  
 204  //---
 205  } // End of class
 206  //===========================================================================
 207  } // End of class_exists
 208  //===========================================================================
 209  } // End of namespace
 210  //===========================================================================
 211  ?>


Generated: Thu Jun 4 18:32:29 2015 Cross-referenced by PHPXref 0.7.1