Source for file ColumnFixture.php

Documentation is available at ColumnFixture.php

  1. <?php
  2. /**
  3. * FIT Fixture ColumnFixture
  4. *
  5. * $Id$
  6. *
  7. * @author Luis A. Floreani <luis.floreani@gmail.com>
  8. * @author gERD Schaufelberger <gerd@php-tools.net>
  9. * @package FIT
  10. * @subpackage Fixture
  11. * @license LGPL http://www.gnu.org/copyleft/lesser.html
  12. * @copyright Copyright (c) 2002-2005 Cunningham & Cunningham, Inc.
  13. */
  14.  
  15. /**
  16. * load class Fixture
  17. */
  18. include_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'Fixture.php';
  19.  
  20. /**
  21. * load class TypeAdapter
  22. */
  23. include_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'TypeAdapter.php';
  24.  
  25. /**
  26. * FIT Fixture: ColumnFixture
  27. *
  28. * @version 0.1.0
  29. * @package FIT
  30. * @subpackage Fixture
  31. */
  32. class ColumnFixture extends Fixture {
  33.  
  34. /**
  35. * TypeAdapter
  36. * @var object
  37. */
  38. protected $columnBindings;
  39. /**
  40. * Excecution state
  41. * @var bool
  42. */
  43. protected $hasExecuted = false;
  44. /**
  45. * Process a table's row
  46. *
  47. * @param Parce rows
  48. */
  49. public function doRows( Parse $rows ) {
  50. $this->bind( $rows->parts );
  51. parent::doRows( $rows->more );
  52. }
  53. /**
  54. * Process a table's row
  55. *
  56. * @param Parce rows
  57. */
  58. public function doRow( $row ) {
  59. $this->hasExecuted = false;
  60. try {
  61. $this->reset();
  62. parent::doRow( $row );
  63. if( !$this->hasExecuted ) {
  64. $this->execute();
  65. }
  66. }
  67. catch( Exception $e ) {
  68. $this->exception($row->leaf(), $e);
  69. }
  70. }
  71. /**
  72. * @param Parce cell
  73. * @param int column
  74. */
  75. public function doCell($cell, $column) {
  76. $a = $this->columnBindings[$column];
  77. try {
  78. $text = $cell->text();
  79. if (strcmp($text,"")==0) {
  80. $this->check($cell, $a);
  81. } else if ($a == null) {
  82. $this->ignore($cell);
  83. } else if ($a->field != null) {
  84. $a->set($a->parse($text));
  85. } else if ($a->method != null) {
  86. $this->check($cell, $a);
  87. }
  88. } catch(Exception $e) {
  89. $this->exception($cell, $e);
  90. }
  91.  
  92. }
  93.  
  94. /**
  95. * @param Parce cell
  96. * @param TypeAdapter $a
  97. */
  98. public function check($cell, $a) {
  99. if (!$this->hasExecuted) {
  100. try {
  101. $this->execute();
  102. } catch (Exception $e) {
  103. $this->exception ($cell, $e);
  104. }
  105. $this->hasExecuted = true;
  106. }
  107. parent::check($cell, $a);
  108. }
  109. /**
  110. * @param Parse heads (ej: x, y, plus(), times(), etc)
  111. */
  112. protected function bind($heads) {
  113. $this->columnBindings = array($heads->size());
  114. //echo "<br>SIZE=" . $heads->size() . "<br>";
  115. for ($i=0; $heads != null; $heads = $heads->more) {
  116. //echo "<br>".$heads->text();
  117. $name = $heads->text();
  118. $suffix = "()";
  119. try {
  120. if ($name == "") {
  121. $this->columnBindings[$i] = null;
  122. } else if (strstr($name, $suffix) !== false) {
  123. $this->columnBindings[$i] = $this->bindMethod(substr($name, 0, strlen($name)-strlen($suffix)));
  124. } else {
  125. $this->columnBindings[$i] = $this->bindField($name);
  126. }
  127. } catch (Exception $e) {
  128. $this->exception($heads, $e);
  129. }
  130. $i=$i+1;
  131. }
  132. }
  133. /**
  134. * @param String name
  135. * @return TypeAdapter
  136. */
  137. protected function bindMethod($name) {
  138. return TypeAdapter::onMethod($this, $name);
  139. }
  140.  
  141. /**
  142. * @param String name
  143. * @return TypeAdapter
  144. */
  145. protected function bindField($name) {
  146. return TypeAdapter::onField($this, $name);
  147. }
  148. public function reset() {
  149. }
  150. public function execute() {
  151. }
  152.  
  153. }
  154. ?>

Documentation generated on Sun, 02 Apr 2006 16:01:03 +0200 by phpDocumentor 1.3.0RC5