Source for file BaseLoader.php

Documentation is available at BaseLoader.php

  1. <?php
  2.  
  3. /**
  4. * MVCnPHP - BaseLoader.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: BaseLoader.class.php,v 1.4 2004/03/23 02:38:53 tony Exp $
  18. *
  19. */
  20.  
  21. /**
  22. * Mapping class which holds all data mapped to a given
  23. * model or view
  24. */
  25. require_once 'Mapping.php';
  26.  
  27. /**
  28. * This is an abstract loader class which provides
  29. * 90% of all functionality to the various loaders since
  30. * we assume all config data will eventually be turned into
  31. * a PHP array
  32. *
  33. * @author Tony Bibbs <tony@geeklog.net>
  34. * @package net.geeklog.mvc
  35. *
  36. */
  37. abstract class MVCnPHP_BaseLoader {
  38. /**
  39. * @access protected
  40. * @var array
  41. */
  42. protected $arrayData = null;
  43.  
  44. /**
  45. * Gets config data for given object in the form of
  46. * a mapping object
  47. *
  48. * @author Tony Bibbs <tony@geeklog.net>
  49. * @access public
  50. * @param string $name Name of object to get mapping for
  51. * @param array $arrayData Array of configuration data
  52. * @return object Mapping object
  53. *
  54. */
  55. public function &getMapping($name, $viewsDir, $commandsDir, $baseURL, $arrayData = '')
  56. {
  57. $mapping = new MVCnPHP_Mapping();
  58. if ($name == 'default') {
  59. $name = $this->getDefaultMapping();
  60. }
  61. if (!empty($arrayData[MVC_VIEWS][$name])) {
  62. $mapping->setName($arrayData[MVC_VIEWS][$name][MVC_NAME]);
  63. $mapping->setType('view');
  64. $mapping->setTypePath($viewsDir);
  65. } elseif (!empty($arrayData[MVC_COMMANDS][$name])) {
  66. $mapping->setName($arrayData[MVC_COMMANDS][$name][MVC_NAME]);
  67. $mapping->setType('command');
  68. $mapping->setTypePath($commandsDir);
  69. }
  70.  
  71. $mapping->setBaseURL($baseURL);
  72. $mapping->setForwards($this->getForwards($name, $mapping->getType()));
  73. return $mapping;
  74. }
  75. /**
  76. * If no object was specified in the request, this will return
  77. * the default mapping if one was specified in the configuration
  78. *
  79. * @author Tony Bibbs <tony@geeklog.net>
  80. * @access private
  81. * @return array Mapping data for given model or view
  82. *
  83. */
  84. private function getDefaultMapping()
  85. {
  86. foreach ($this->arrayData[MVC_VIEWS] as $curView) {
  87. $curView = current($this->arrayData[MVC_VIEWS]);
  88. if ($curView[MVC_DEFAULT] == true) {
  89. return key($this->arrayData[MVC_VIEWS]);
  90. }
  91. next($this->arrayData[MVC_VIEWS]);
  92. }
  93. }
  94. /**
  95. * Gets all forwards for a given object
  96. *
  97. * @author Tony Bibbs <tony@geeklog.net>
  98. * @access private
  99. * @param string $name Name of model to get forwards for
  100. * @param string $type Type of object (command or view)
  101. * @return array Forwards for given model
  102. *
  103. */
  104. private function getForwards($name, $type)
  105. {
  106. if ($type == 'view') {
  107. return $this->arrayData[MVC_VIEWS][$name][MVC_FORWARDS];
  108. } else {
  109. return $this->arrayData[MVC_COMMANDS][$name][MVC_FORWARDS];
  110. }
  111. }
  112. }

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