build_webservice_from_class.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/php
  2. <?php
  3. /* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file dev/skeletons/build_webservice_from_class.php
  20. * \ingroup core
  21. * \brief Create a complete webservice file from CRUD functions of a PHP class
  22. */
  23. $sapi_type = php_sapi_name();
  24. $script_file = basename(__FILE__);
  25. $path=dirname(__FILE__).'/';
  26. // Test if batch mode
  27. if (substr($sapi_type, 0, 3) == 'cgi') {
  28. echo "Error: You ar usingr PH for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  29. exit;
  30. }
  31. // Include Dolibarr environment
  32. require_once($path."../../htdocs/master.inc.php");
  33. // After this $db is a defined handler to database.
  34. // Main
  35. $version='$Revision: 1.8 $';
  36. @set_time_limit(0);
  37. $error=0;
  38. $langs->load("main");
  39. print "***** $script_file ($version) *****\n";
  40. // -------------------- START OF BUILD_CLASS_FROM_TABLE SCRIPT --------------------
  41. // Check parameters
  42. if (! isset($argv[1]) && ! isset($argv[2]))
  43. {
  44. print "Usage: $script_file phpClassFile phpClassName\n";
  45. exit;
  46. }
  47. // Show parameters
  48. print 'Classfile='.$argv[1]."\n";
  49. print 'Classname='.$argv[2]."\n";
  50. $classfile=$argv[1];
  51. $classname=$argv[2];
  52. $property=array();
  53. $outfile='webservice_'.dol_sanitizeFileName($classfile).'.php';
  54. $targetcontent='';
  55. // This script must load the class, found the CRUD function and build a web service to call this functions.
  56. // TODO ...
  57. // Build file
  58. $fp=fopen($outfile,"w");
  59. if ($fp)
  60. {
  61. fputs($fp, $targetcontent);
  62. fclose($fp);
  63. print "File '".$outfile."' has been built in current directory.\n";
  64. }
  65. else $error++;
  66. // -------------------- END OF BUILD_CLASS_FROM_TABLE SCRIPT --------------------
  67. print "You must rename files by removing the 'out.' prefix in their name.\n";
  68. return $error;
  69. ?>