/framework/core/cli/CliApplication.php

http://zoop.googlecode.com/ · PHP · 103 lines · 51 code · 8 blank · 44 comment · 9 complexity · c48fe4391a937a53a731095bff3f64d0 MD5 · raw file

  1. <?php
  2. // todo: I think that this should extend Application.
  3. class CliApplication
  4. {
  5. /*
  6. function loadZone($name)
  7. {
  8. $name = ucfirst($name);
  9. include(app_dir . "/zones/Zone$name.php");
  10. }
  11. */
  12. function run()
  13. {
  14. global $argv;
  15. // parse the flags
  16. $params = array();
  17. $inShortFlag = 0;
  18. $shortFlags = array();
  19. foreach($argv as $thisArg)
  20. {
  21. // check for long flags
  22. if($thisArg[0] == '-' && $thisArg[1] == '-')
  23. {
  24. }
  25. // check for short flags
  26. else if($thisArg[0] == '-')
  27. {
  28. $inShortFlag = 1;
  29. $shortFlagName = substr($thisArg, 1);
  30. }
  31. // it's a paramater
  32. else
  33. {
  34. if($inShortFlag)
  35. {
  36. $inShortFlag = 0;
  37. $shortFlags[$shortFlagName] = $thisArg;
  38. }
  39. else
  40. {
  41. $params[] = $thisArg;
  42. }
  43. }
  44. }
  45. if(!isset($params[1]))
  46. {
  47. echo "usages:\n";
  48. echo "zap apply migrations:\n";
  49. die();
  50. }
  51. $zoneName = 'Zone' . $params[1];
  52. $pageName = 'sub' . $params[2];
  53. $zone = new $zoneName();
  54. $zone->$pageName($params, $shortFlags);
  55. }
  56. /*
  57. function run()
  58. {
  59. // get the path parts
  60. $pathParts = explode('/', virtual_path);
  61. array_shift($pathParts);
  62. // special case: see if we need to dish out a static page from a zoop module
  63. if(isset($pathParts[0]) && $pathParts[0] == 'modpub')
  64. {
  65. $this->handleStaticFile($pathParts);
  66. }
  67. else
  68. {
  69. // handle the request
  70. $zoneDefault = new ZoneDefault();
  71. $zoneDefault->handleRequest($pathParts);
  72. }
  73. }
  74. */
  75. //static
  76. function handleRequest()
  77. {
  78. global $app;
  79. //$app->loadZone('default');
  80. $app->run();
  81. }
  82. /*
  83. function handleStaticFile($pathParts)
  84. {
  85. array_shift($pathParts);
  86. $modName = str_replace('..', '', array_shift($pathParts));
  87. $staticPath = str_replace('..', '', implode('/', $pathParts));
  88. $filePath = zoop_dir . "/$modName/public/" . $staticPath;
  89. EchoStaticFile($filePath);
  90. }
  91. */
  92. }
  93. global $app;
  94. $app = new CliApplication();