Source for file CommandFactory.php

Documentation is available at CommandFactory.php

  1. <?php
  2.  
  3. /**
  4. * MVCnPHP - CommandFactory.class.php
  5. *
  6. * This source file is subject to version 2.02 of the PHP license,
  7. * that is bundled with this package in the file LICENSE, and is
  8. * available at through the world-wide-web at
  9. * http://www.php.net/license/2_02.txt.
  10. * If you did not receive a copy of the PHP license and are unable to
  11. * obtain it through the world-wide-web, please send a note to
  12. * license@php.net so we can mail you a copy immediately.
  13. *
  14. * @author Tony Bibbs <tony@geeklog.net>
  15. * @copyright Tony Bibbs 2003
  16. * @package net.geeklog.mvc
  17. * @version $Id: CommandFactory.class.php,v 1.3 2003/12/09 04:14:08 tony Exp $
  18. *
  19. */
  20.  
  21. /**
  22. * This implements the factory design pattern and is
  23. * responsible for building command objects
  24. *
  25. * @author Tony Bibbs <tony@geeklog.net>
  26. * @package net.geeklog.mvc
  27. *
  28. */
  29. class MVCnPHP_CommandFactory {
  30. /**
  31. * Builds the requested command object
  32. *
  33. * @author Tony Bibbs <tony@geeklog.net>
  34. * @access public
  35. * @param string $path Path to directory holding commands
  36. * @param string $name Name of command to create
  37. * @return object Command object
  38. *
  39. */
  40. public function &getCommand($path, $name)
  41. {
  42. if (!isset($name)) {
  43. throw new Exception('No command name given to CommandFactory::getCommand');
  44. }
  45. $filename = $path . $name . '.php';
  46. if (file_exists($filename)) {
  47. require_once $filename;
  48. $name = $name;
  49. return new $name();
  50. } else {
  51. throw new Exception('Bad set of parameters to CommandFactory::getCommand');
  52. }
  53. }
  54. }
  55.  
  56. ?>

Documentation generated on Mon, 7 Mar 2005 22:36:20 -0600 by phpDocumentor 1.3.0RC3