CLI 956 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php if(PHP_SAPI !== 'cli') die();
  2. /**
  3. * CLI
  4. *
  5. * This file is the command-line interface (CLI) entry point for the system
  6. *
  7. * @package MicroMVC
  8. * @author David Pennington
  9. * @copyright (c) 2010 MicroMVC Framework
  10. * @license http://micromvc.com/license
  11. ********************************** 80 Columns *********************************
  12. */
  13. // Include bootstrap
  14. require('Bootstrap.php');
  15. // Require a CLI path
  16. if(empty($argv[1]))
  17. {
  18. die("Please enter a path to the CLI file.\nExample: " . colorize('php cli file.php', 'blue') . "\n");
  19. }
  20. // Build path to file
  21. $file = SP . 'Command/' . str_replace(EXT, '', trim($argv[1], '/')) . EXT;
  22. // Does the file exist?
  23. if( ! is_file($file)) die("Please enter a valid file path\n");
  24. // Require a valid, safe path
  25. if( ! preg_match('/^[\w\-~\/\.+]{1,600}/', $argv[1])) die(colorize("Invalid path given", 'red'). "\n");
  26. try
  27. {
  28. require($file);
  29. }
  30. catch (Exception $e)
  31. {
  32. \Micro\Error::exception($e);
  33. }
  34. // End