Source for file Services.abstract.php

Documentation is available at Services.abstract.php

  1. <?php
  2.  
  3. require_once(HARMONI."services/Services.interface.php");
  4.  
  5. /**
  6. * The ServicesAbstract class defines the public static methods used by users.
  7. *
  8. * @static
  9. * @abstract
  10. *
  11. * @package harmoni.services
  12. *
  13. * @copyright Copyright &copy; 2005, Middlebury College
  14. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  15. *
  16. * @version $Id: Services.abstract.php,v 1.15 2007/09/04 20:25:49 adamfranco Exp $
  17. */
  18. class ServicesAbstract
  19. extends ServicesInterface {
  20. /**
  21. * Registers a new service named $name. Upon starting, a new class of type $class will be instantiated.
  22. * @param string $name The reference name of the service.
  23. * @param string $class The class name to be instantiated.
  24. * @access public
  25. * @static
  26. * @return boolean True on success. False if service is registered and running or an error occurs.
  27. ***/
  28. function registerService( $name, $class ) {
  29. return $GLOBALS[SERVICES_OBJECT]->register( $name, $class );
  30. }
  31. /**
  32. * Register's an object as a service.
  33. * @param string $name The name of the new service.
  34. * @param ref object $object The object.
  35. * @access public
  36. * @return void
  37. ***/
  38. function registerObjectAsService($name, $object) {
  39. $GLOBALS[SERVICES_OBJECT]->registerObject($name,$object);
  40. }
  41. /**
  42. * Create an alias from one service name to another.
  43. *
  44. * @param string $name1
  45. * @param string $name2
  46. * @return void
  47. * @access public
  48. * @since 3/24/05
  49. */
  50. function createServiceAlias ($name1, $name2) {
  51. $GLOBALS[SERVICES_OBJECT]->createAlias($name1, $name2);
  52. }
  53. /**
  54. * Returns the services object.
  55. * @access public
  56. * @static
  57. * @return object Services The Services object.
  58. ***/
  59. function getServices() {
  60. return $GLOBALS[SERVICES_OBJECT];
  61. }
  62. /**
  63. * Returns the service object associated with reference name $name.
  64. * @param string $name The reference name of the service.
  65. * @access public
  66. * @static
  67. * @return object Object The service object.
  68. ***/
  69. function getService( $name ) {
  70. return $GLOBALS[SERVICES_OBJECT]->get( $name );
  71. }
  72. /**
  73. * Attempts to start the service referenced by $name.
  74. * @param string $name The service name.
  75. * @param optional mixed $args,... Optional arguments to pass to the constructor of the service class.
  76. * @access public
  77. * @static
  78. * @return boolean True on success.
  79. * @deprecated 2005/04/04 Use {@link startManagerAsService()} and {@link getService()} instead.
  80. ***/
  81. function startService( $name, $args=null ) {
  82. $backtrace = debug_backtrace();
  83. print "\n<br/><strong>Warning: Method call, Services::startService(), is deprecated. Please use Services::startManagerAsService() and/or Services::getService() instead. ";
  84. print $backtrace[0]['file']." (Line ".$backtrace[0]['line'].")";
  85. $argList='';
  86. if (func_num_args() > 1) {
  87. for ($i=1; $i<func_num_args(); $i++) {
  88. $var = "arg$i";
  89. $$var = func_get_arg($i);
  90. $argList .= ', $arg'.$i;
  91. }
  92. }
  93. $str = '$result = $GLOBALS[SERVICES_OBJECT]->start( $name'.$argList.' );';
  94. // print "$name: ".$str."<pre>".print_r($arg1, TRUE)."</pre>";
  95. // $str = 'return $GLOBALS[SERVICES_OBJECT]->start( $name'.$argList.' );';
  96. eval($str);
  97. // var_dump($result);
  98. return $result;
  99. }
  100. /**
  101. * Attempts to start the manager referenced by $name. The manager must
  102. * extend OsidManager And assign its context and configuration.
  103. *
  104. * @param string $name
  105. * @param object OsidContext $context
  106. * @param object Properties $configuration
  107. * @return boolean true on success
  108. * @access public
  109. * @since 3/24/05
  110. */
  111. function startManagerAsService ( $name, $context, $configuration ) {
  112. return $GLOBALS[SERVICES_OBJECT]->startManager($name, $context, $configuration);
  113. }
  114. /**
  115. * Cycles through all registered services and attempts to start them.
  116. * @static
  117. * @access public
  118. * @return void
  119. * @deprecated 2005/04/04 Use {@link startManagerAsService()} and {@link getService()} instead.
  120. ***/
  121. function startAllServices() {
  122. $backtrace = debug_backtrace();
  123. print "\n<br/><strong>Warning: Method call, Services::startAllServices(), is deprecated. Please use Services::startManagerAsService() and/or Services::getService() instead. ";
  124. print $backtrace[0]['file']." (Line ".$backtrace[0]['line'].")";
  125. print "</strong><br/>\n";
  126. $GLOBALS[SERVICES_OBJECT]->startAll();
  127. }
  128. /**
  129. * Attempts to stop the service reference by $name.
  130. * @param string $name The service name.
  131. * @access public
  132. * @static
  133. * @return boolean True on success.
  134. * @deprecated 2005/04/04 Use {@link startManagerAsService()} and {@link getService()} instead.
  135. ***/
  136. function stopService( $name ) {
  137. $backtrace = debug_backtrace();
  138. print "\n<br/><strong>Warning: Method call, Services::stopService(), is deprecated. Please use Services::startManagerAsService() and/or Services::getService() instead. ";
  139. print $backtrace[0]['file']." (Line ".$backtrace[0]['line'].")";
  140. return $GLOBALS[SERVICES_OBJECT]->stop( $name );
  141. }
  142. /**
  143. * Attempts to stop all running services.
  144. * @access public
  145. * @return void
  146. * @deprecated 2005/04/04 Use {@link startManagerAsService()} and {@link getService()} instead.
  147. ***/
  148. function stopAllServices() {
  149. $backtrace = debug_backtrace();
  150. print "\n<br/><strong>Warning: Method call, Services::stopAllServices(), is deprecated. Please use Services::startManagerAsService() and/or Services::getService() instead. ";
  151. print $backtrace[0]['file']." (Line ".$backtrace[0]['line'].")";
  152. return $GLOBALS[SERVICES_OBJECT]->stopAll();
  153. }
  154. /**
  155. * Attempts to restart the service reference by $name.
  156. * @param string $name The service name.
  157. * @access public
  158. * @static
  159. * @return boolean True on success.
  160. * @deprecated 2005/04/04 Use {@link startManagerAsService()} and {@link getService()} instead.
  161. ***/
  162. function restartService( $name ) {
  163. $backtrace = debug_backtrace();
  164. print "\n<br/><strong>Warning: Method call, Services::restartService(), is deprecated. Please use Services::startManagerAsService() and/or Services::getService() instead. ";
  165. print $backtrace[0]['file']." (Line ".$backtrace[0]['line'].")";
  166. print "</strong><br/>\n";
  167. return $GLOBALS[SERVICES_OBJECT]->restart( $name );
  168. }
  169. /**
  170. * Checks if the service referenced by $name is available for use.
  171. * @access public
  172. * @static
  173. * @param string $name The service name.
  174. * @return boolean True if the service is available, false otherwise.
  175. ***/
  176. function serviceAvailable( $name ) {
  177. return $GLOBALS[SERVICES_OBJECT]->available( $name );
  178. }
  179. /**
  180. * Checks if the service referenced by $name has been started.
  181. * @access public
  182. * @static
  183. * @param string $name The service name.
  184. * @return boolean True if the service is running, false otherwise.
  185. ***/
  186. function serviceRunning( $name ) {
  187. return $GLOBALS[SERVICES_OBJECT]->running( $name );
  188. }
  189. /**
  190. * The Require Service function checks for required service availability.
  191. *
  192. * The function first checks for service availabilty, and then attempts to
  193. * start the service if it's available. If either action fails, it stops
  194. * script execution. If $start=false then the function will only check for
  195. * availability.
  196. * @param string $name The name of the service.
  197. * @param boolean $start If we should attempt to start the service or not.
  198. * @access public
  199. * @static
  200. * @return ref object The started service object. (if start=true)
  201. * @deprecated 2004/07/28 Use {@link startManagerAsService()} and {@link getService()} instead.
  202. ***/
  203. function requireService( $service, $start=true ) {
  204. $backtrace = debug_backtrace();
  205. print "\n<br/><strong>Warning: Method call, Services::requireService(), is deprecated. Please use Services::startManagerAsService() and/or Services::getService() instead. ";
  206. print $backtrace[0]['file']." (Line ".$backtrace[0]['line'].")";
  207. print "</strong><br/>\n";
  208. $error = false;
  209. if (!Services::serviceAvailable($service)) {
  210. $error = true;
  211. } else if ($start && !Services::serviceRunning($service) && !Services::startService($service)) {
  212. $error = true;
  213. }
  214. if ($error) {
  215. // if we have the error Handler, throw a pretty error with that,
  216. // otherwise, use the die() function.
  217. if ($GLOBALS[SERVICES_OBJECT]->available( 'ErrorHandler' )) {
  218. throwError(new Error("A required Service <b>\"$service\"</b> ".(($start)? "could not be started":"is not available"), "Services", 1));
  219. } else {
  220. $debug = debug_backtrace();
  221. $str = "<B>FATAL ERROR</b><br /><br />";
  222. $str .= "A required Service <b>\"$service\"</b> ";
  223. $str .= ($start)? "could not be started":"is not available";
  224. $str .= ".<br /><br />\n";
  225. $str .= "<b>Debug backtrace:</b>\n";
  226. $str .= "<pre>\n";
  227. $str .= print_r($debug, true);
  228. $str .= "\n</pre>\n";
  229. die($str);
  230. }
  231. }
  232. if ($start) return Services::getService($service);
  233. }
  234. }

Documentation generated on Wed, 19 Sep 2007 10:26:24 -0400 by phpDocumentor 1.3.0RC3