Best Phpunit code snippet using Count.__construct
tag.php
Source:tag.php
...29 * string values. Note that30 * the keys must have been31 * converted to lower case.32 */33 function __construct($name, $attributes) {34 $this->name = strtolower(trim($name));35 $this->attributes = $attributes;36 $this->content = '';37 }38 39 /**40 * Check to see if the tag can have both start and41 * end tags with content in between.42 * @return boolean True if content allowed.43 * @access public44 */45 function expectEndTag() {46 return true;47 }48 49 /**50 * The current tag should not swallow all content for51 * itself as it's searchable page content. Private52 * content tags are usually widgets that contain default53 * values.54 * @return boolean False as content is available55 * to other tags by default.56 * @access public57 */58 function isPrivateContent() {59 return false;60 }61 /**62 * Appends string content to the current content.63 * @param string $content Additional text.64 * @access public65 */66 function addContent($content) {67 $this->content .= (string)$content;68 }69 70 /**71 * Adds an enclosed tag to the content.72 * @param SimpleTag $tag New tag.73 * @access public74 */75 function addTag($tag) {76 }77 78 /**79 * Accessor for tag name.80 * @return string Name of tag.81 * @access public82 */83 function getTagName() {84 return $this->name;85 }86 87 /**88 * List of legal child elements.89 * @return array List of element names.90 * @access public91 */92 function getChildElements() {93 return array();94 }95 96 /**97 * Accessor for an attribute.98 * @param string $label Attribute name.99 * @return string Attribute value.100 * @access public101 */102 function getAttribute($label) {103 $label = strtolower($label);104 if (! isset($this->attributes[$label])) {105 return false;106 }107 return (string)$this->attributes[$label];108 }109 110 /**111 * Sets an attribute.112 * @param string $label Attribute name.113 * @return string $value New attribute value.114 * @access protected115 */116 protected function setAttribute($label, $value) {117 $this->attributes[strtolower($label)] = $value;118 }119 120 /**121 * Accessor for the whole content so far.122 * @return string Content as big raw string.123 * @access public124 */125 function getContent() {126 return $this->content;127 }128 129 /**130 * Accessor for content reduced to visible text. Acts131 * like a text mode browser, normalising space and132 * reducing images to their alt text.133 * @return string Content as plain text.134 * @access public135 */136 function getText() {137 return SimpleHtmlSaxParser::normalise($this->content);138 }139 140 /**141 * Test to see if id attribute matches.142 * @param string $id ID to test against.143 * @return boolean True on match.144 * @access public145 */146 function isId($id) {147 return ($this->getAttribute('id') == $id);148 }149}150/**151 * Base url.152 * @package SimpleTest153 * @subpackage WebTester154 */155class SimpleBaseTag extends SimpleTag {156 157 /**158 * Starts with a named tag with attributes only.159 * @param hash $attributes Attribute names and160 * string values.161 */162 function __construct($attributes) {163 parent::__construct('base', $attributes);164 }165 /**166 * Base tag is not a block tag.167 * @return boolean false168 * @access public169 */170 function expectEndTag() {171 return false;172 }173}174/**175 * Page title.176 * @package SimpleTest177 * @subpackage WebTester178 */179class SimpleTitleTag extends SimpleTag {180 181 /**182 * Starts with a named tag with attributes only.183 * @param hash $attributes Attribute names and184 * string values.185 */186 function __construct($attributes) {187 parent::__construct('title', $attributes);188 }189}190/**191 * Link.192 * @package SimpleTest193 * @subpackage WebTester194 */195class SimpleAnchorTag extends SimpleTag {196 197 /**198 * Starts with a named tag with attributes only.199 * @param hash $attributes Attribute names and200 * string values.201 */202 function __construct($attributes) {203 parent::__construct('a', $attributes);204 }205 206 /**207 * Accessor for URL as string.208 * @return string Coerced as string.209 * @access public210 */211 function getHref() {212 $url = $this->getAttribute('href');213 if (is_bool($url)) {214 $url = '';215 }216 return $url;217 }218}219/**220 * Form element.221 * @package SimpleTest222 * @subpackage WebTester223 */224class SimpleWidget extends SimpleTag {225 private $value;226 private $label;227 private $is_set;228 229 /**230 * Starts with a named tag with attributes only.231 * @param string $name Tag name.232 * @param hash $attributes Attribute names and233 * string values.234 */235 function __construct($name, $attributes) {236 parent::__construct($name, $attributes);237 $this->value = false;238 $this->label = false;239 $this->is_set = false;240 }241 242 /**243 * Accessor for name submitted as the key in244 * GET/POST privateiables hash.245 * @return string Parsed value.246 * @access public247 */248 function getName() {249 return $this->getAttribute('name');250 }251 252 /**253 * Accessor for default value parsed with the tag.254 * @return string Parsed value.255 * @access public256 */257 function getDefault() {258 return $this->getAttribute('value');259 }260 261 /**262 * Accessor for currently set value or default if263 * none.264 * @return string Value set by form or default265 * if none.266 * @access public267 */268 function getValue() {269 if (! $this->is_set) {270 return $this->getDefault();271 }272 return $this->value;273 }274 275 /**276 * Sets the current form element value.277 * @param string $value New value.278 * @return boolean True if allowed.279 * @access public280 */281 function setValue($value) {282 $this->value = $value;283 $this->is_set = true;284 return true;285 }286 287 /**288 * Resets the form element value back to the289 * default.290 * @access public291 */292 function resetValue() {293 $this->is_set = false;294 }295 296 /**297 * Allows setting of a label externally, say by a298 * label tag.299 * @param string $label Label to attach.300 * @access public301 */302 function setLabel($label) {303 $this->label = trim($label);304 }305 306 /**307 * Reads external or internal label.308 * @param string $label Label to test.309 * @return boolean True is match.310 * @access public311 */312 function isLabel($label) {313 return $this->label == trim($label);314 }315 316 /**317 * Dispatches the value into the form encoded packet.318 * @param SimpleEncoding $encoding Form packet.319 * @access public320 */321 function write($encoding) {322 if ($this->getName()) {323 $encoding->add($this->getName(), $this->getValue());324 }325 }326}327/**328 * Text, password and hidden field.329 * @package SimpleTest330 * @subpackage WebTester331 */332class SimpleTextTag extends SimpleWidget {333 334 /**335 * Starts with a named tag with attributes only.336 * @param hash $attributes Attribute names and337 * string values.338 */339 function __construct($attributes) {340 parent::__construct('input', $attributes);341 if ($this->getAttribute('value') === false) {342 $this->setAttribute('value', '');343 }344 }345 346 /**347 * Tag contains no content.348 * @return boolean False.349 * @access public350 */351 function expectEndTag() {352 return false;353 }354 355 /**356 * Sets the current form element value. Cannot357 * change the value of a hidden field.358 * @param string $value New value.359 * @return boolean True if allowed.360 * @access public361 */362 function setValue($value) {363 if ($this->getAttribute('type') == 'hidden') {364 return false;365 }366 return parent::setValue($value);367 }368}369/**370 * Submit button as input tag.371 * @package SimpleTest372 * @subpackage WebTester373 */374class SimpleSubmitTag extends SimpleWidget {375 376 /**377 * Starts with a named tag with attributes only.378 * @param hash $attributes Attribute names and379 * string values.380 */381 function __construct($attributes) {382 parent::__construct('input', $attributes);383 if ($this->getAttribute('value') === false) {384 $this->setAttribute('value', 'Submit');385 }386 }387 388 /**389 * Tag contains no end element.390 * @return boolean False.391 * @access public392 */393 function expectEndTag() {394 return false;395 }396 397 /**398 * Disables the setting of the button value.399 * @param string $value Ignored.400 * @return boolean True if allowed.401 * @access public402 */403 function setValue($value) {404 return false;405 }406 407 /**408 * Value of browser visible text.409 * @return string Visible label.410 * @access public411 */412 function getLabel() {413 return $this->getValue();414 }415 416 /**417 * Test for a label match when searching.418 * @param string $label Label to test.419 * @return boolean True on match.420 * @access public421 */422 function isLabel($label) {423 return trim($label) == trim($this->getLabel());424 }425}426 427/**428 * Image button as input tag.429 * @package SimpleTest430 * @subpackage WebTester431 */432class SimpleImageSubmitTag extends SimpleWidget {433 434 /**435 * Starts with a named tag with attributes only.436 * @param hash $attributes Attribute names and437 * string values.438 */439 function __construct($attributes) {440 parent::__construct('input', $attributes);441 }442 443 /**444 * Tag contains no end element.445 * @return boolean False.446 * @access public447 */448 function expectEndTag() {449 return false;450 }451 452 /**453 * Disables the setting of the button value.454 * @param string $value Ignored.455 * @return boolean True if allowed.456 * @access public457 */458 function setValue($value) {459 return false;460 }461 462 /**463 * Value of browser visible text.464 * @return string Visible label.465 * @access public466 */467 function getLabel() {468 if ($this->getAttribute('title')) {469 return $this->getAttribute('title');470 }471 return $this->getAttribute('alt');472 }473 474 /**475 * Test for a label match when searching.476 * @param string $label Label to test.477 * @return boolean True on match.478 * @access public479 */480 function isLabel($label) {481 return trim($label) == trim($this->getLabel());482 }483 484 /**485 * Dispatches the value into the form encoded packet.486 * @param SimpleEncoding $encoding Form packet.487 * @param integer $x X coordinate of click.488 * @param integer $y Y coordinate of click.489 * @access public490 */491 function write($encoding, $x = 1, $y = 1) {492 if ($this->getName()) {493 $encoding->add($this->getName() . '.x', $x);494 $encoding->add($this->getName() . '.y', $y);495 } else {496 $encoding->add('x', $x);497 $encoding->add('y', $y);498 }499 }500}501 502/**503 * Submit button as button tag.504 * @package SimpleTest505 * @subpackage WebTester506 */507class SimpleButtonTag extends SimpleWidget {508 509 /**510 * Starts with a named tag with attributes only.511 * Defaults are very browser dependent.512 * @param hash $attributes Attribute names and513 * string values.514 */515 function __construct($attributes) {516 parent::__construct('button', $attributes);517 }518 519 /**520 * Check to see if the tag can have both start and521 * end tags with content in between.522 * @return boolean True if content allowed.523 * @access public524 */525 function expectEndTag() {526 return true;527 }528 529 /**530 * Disables the setting of the button value.531 * @param string $value Ignored.532 * @return boolean True if allowed.533 * @access public534 */535 function setValue($value) {536 return false;537 }538 539 /**540 * Value of browser visible text.541 * @return string Visible label.542 * @access public543 */544 function getLabel() {545 return $this->getContent();546 }547 548 /**549 * Test for a label match when searching.550 * @param string $label Label to test.551 * @return boolean True on match.552 * @access public553 */554 function isLabel($label) {555 return trim($label) == trim($this->getLabel());556 }557}558/**559 * Content tag for text area.560 * @package SimpleTest561 * @subpackage WebTester562 */563class SimpleTextAreaTag extends SimpleWidget {564 565 /**566 * Starts with a named tag with attributes only.567 * @param hash $attributes Attribute names and568 * string values.569 */570 function __construct($attributes) {571 parent::__construct('textarea', $attributes);572 }573 574 /**575 * Accessor for starting value.576 * @return string Parsed value.577 * @access public578 */579 function getDefault() {580 return $this->wrap(SimpleHtmlSaxParser::decodeHtml($this->getContent()));581 }582 583 /**584 * Applies word wrapping if needed.585 * @param string $value New value.586 * @return boolean True if allowed.587 * @access public588 */589 function setValue($value) {590 return parent::setValue($this->wrap($value));591 }592 593 /**594 * Test to see if text should be wrapped.595 * @return boolean True if wrapping on.596 * @access private597 */598 function wrapIsEnabled() {599 if ($this->getAttribute('cols')) {600 $wrap = $this->getAttribute('wrap');601 if (($wrap == 'physical') || ($wrap == 'hard')) {602 return true;603 }604 }605 return false;606 }607 608 /**609 * Performs the formatting that is peculiar to610 * this tag. There is strange behaviour in this611 * one, including stripping a leading new line.612 * Go figure. I am using Firefox as a guide.613 * @param string $text Text to wrap.614 * @return string Text wrapped with carriage615 * returns and line feeds616 * @access private617 */618 protected function wrap($text) {619 $text = str_replace("\r\r\n", "\r\n", str_replace("\n", "\r\n", $text));620 $text = str_replace("\r\n\n", "\r\n", str_replace("\r", "\r\n", $text));621 if (strncmp($text, "\r\n", strlen("\r\n")) == 0) {622 $text = substr($text, strlen("\r\n"));623 }624 if ($this->wrapIsEnabled()) {625 return wordwrap(626 $text,627 (integer)$this->getAttribute('cols'),628 "\r\n");629 }630 return $text;631 }632 633 /**634 * The content of textarea is not part of the page.635 * @return boolean True.636 * @access public637 */638 function isPrivateContent() {639 return true;640 }641}642/**643 * File upload widget.644 * @package SimpleTest645 * @subpackage WebTester646 */647class SimpleUploadTag extends SimpleWidget {648 649 /**650 * Starts with attributes only.651 * @param hash $attributes Attribute names and652 * string values.653 */654 function __construct($attributes) {655 parent::__construct('input', $attributes);656 }657 658 /**659 * Tag contains no content.660 * @return boolean False.661 * @access public662 */663 function expectEndTag() {664 return false;665 }666 667 /**668 * Dispatches the value into the form encoded packet.669 * @param SimpleEncoding $encoding Form packet.670 * @access public671 */672 function write($encoding) {673 if (! file_exists($this->getValue())) {674 return;675 }676 $encoding->attach(677 $this->getName(),678 implode('', file($this->getValue())),679 basename($this->getValue()));680 }681}682/**683 * Drop down widget.684 * @package SimpleTest685 * @subpackage WebTester686 */687class SimpleSelectionTag extends SimpleWidget {688 private $options;689 private $choice;690 691 /**692 * Starts with attributes only.693 * @param hash $attributes Attribute names and694 * string values.695 */696 function __construct($attributes) {697 parent::__construct('select', $attributes);698 $this->options = array();699 $this->choice = false;700 }701 702 /**703 * Adds an option tag to a selection field.704 * @param SimpleOptionTag $tag New option.705 * @access public706 */707 function addTag($tag) {708 if ($tag->getTagName() == 'option') {709 $this->options[] = $tag;710 }711 }712 713 /**714 * Text within the selection element is ignored.715 * @param string $content Ignored.716 * @access public717 */718 function addContent($content) {719 }720 721 /**722 * Scans options for defaults. If none, then723 * the first option is selected.724 * @return string Selected field.725 * @access public726 */727 function getDefault() {728 for ($i = 0, $count = count($this->options); $i < $count; $i++) {729 if ($this->options[$i]->getAttribute('selected') !== false) {730 return $this->options[$i]->getDefault();731 }732 }733 if ($count > 0) {734 return $this->options[0]->getDefault();735 }736 return '';737 }738 739 /**740 * Can only set allowed values.741 * @param string $value New choice.742 * @return boolean True if allowed.743 * @access public744 */745 function setValue($value) {746 for ($i = 0, $count = count($this->options); $i < $count; $i++) {747 if ($this->options[$i]->isValue($value)) {748 $this->choice = $i;749 return true;750 }751 }752 return false;753 }754 755 /**756 * Accessor for current selection value.757 * @return string Value attribute or758 * content of opton.759 * @access public760 */761 function getValue() {762 if ($this->choice === false) {763 return $this->getDefault();764 }765 return $this->options[$this->choice]->getValue();766 }767}768/**769 * Drop down widget.770 * @package SimpleTest771 * @subpackage WebTester772 */773class MultipleSelectionTag extends SimpleWidget {774 private $options;775 private $values;776 777 /**778 * Starts with attributes only.779 * @param hash $attributes Attribute names and780 * string values.781 */782 function __construct($attributes) {783 parent::__construct('select', $attributes);784 $this->options = array();785 $this->values = false;786 }787 788 /**789 * Adds an option tag to a selection field.790 * @param SimpleOptionTag $tag New option.791 * @access public792 */793 function addTag($tag) {794 if ($tag->getTagName() == 'option') {795 $this->options[] = &$tag;796 }797 }798 799 /**800 * Text within the selection element is ignored.801 * @param string $content Ignored.802 * @access public803 */804 function addContent($content) {805 }806 807 /**808 * Scans options for defaults to populate the809 * value array().810 * @return array Selected fields.811 * @access public812 */813 function getDefault() {814 $default = array();815 for ($i = 0, $count = count($this->options); $i < $count; $i++) {816 if ($this->options[$i]->getAttribute('selected') !== false) {817 $default[] = $this->options[$i]->getDefault();818 }819 }820 return $default;821 }822 823 /**824 * Can only set allowed values. Any illegal value825 * will result in a failure, but all correct values826 * will be set.827 * @param array $desired New choices.828 * @return boolean True if all allowed.829 * @access public830 */831 function setValue($desired) {832 $achieved = array();833 foreach ($desired as $value) {834 $success = false;835 for ($i = 0, $count = count($this->options); $i < $count; $i++) {836 if ($this->options[$i]->isValue($value)) {837 $achieved[] = $this->options[$i]->getValue();838 $success = true;839 break;840 }841 }842 if (! $success) {843 return false;844 }845 }846 $this->values = $achieved;847 return true;848 }849 850 /**851 * Accessor for current selection value.852 * @return array List of currently set options.853 * @access public854 */855 function getValue() {856 if ($this->values === false) {857 return $this->getDefault();858 }859 return $this->values;860 }861}862/**863 * Option for selection field.864 * @package SimpleTest865 * @subpackage WebTester866 */867class SimpleOptionTag extends SimpleWidget {868 869 /**870 * Stashes the attributes.871 */872 function __construct($attributes) {873 parent::__construct('option', $attributes);874 }875 876 /**877 * Does nothing.878 * @param string $value Ignored.879 * @return boolean Not allowed.880 * @access public881 */882 function setValue($value) {883 return false;884 }885 886 /**887 * Test to see if a value matches the option.888 * @param string $compare Value to compare with.889 * @return boolean True if possible match.890 * @access public891 */892 function isValue($compare) {893 $compare = trim($compare);894 if (trim($this->getValue()) == $compare) {895 return true;896 }897 return trim($this->getContent()) == $compare;898 }899 900 /**901 * Accessor for starting value. Will be set to902 * the option label if no value exists.903 * @return string Parsed value.904 * @access public905 */906 function getDefault() {907 if ($this->getAttribute('value') === false) {908 return $this->getContent();909 }910 return $this->getAttribute('value');911 }912 913 /**914 * The content of options is not part of the page.915 * @return boolean True.916 * @access public917 */918 function isPrivateContent() {919 return true;920 }921}922/**923 * Radio button.924 * @package SimpleTest925 * @subpackage WebTester926 */927class SimpleRadioButtonTag extends SimpleWidget {928 929 /**930 * Stashes the attributes.931 * @param array $attributes Hash of attributes.932 */933 function __construct($attributes) {934 parent::__construct('input', $attributes);935 if ($this->getAttribute('value') === false) {936 $this->setAttribute('value', 'on');937 }938 }939 940 /**941 * Tag contains no content.942 * @return boolean False.943 * @access public944 */945 function expectEndTag() {946 return false;947 }948 949 /**950 * The only allowed value sn the one in the951 * "value" attribute.952 * @param string $value New value.953 * @return boolean True if allowed.954 * @access public955 */956 function setValue($value) {957 if ($value === false) {958 return parent::setValue($value);959 }960 if ($value != $this->getAttribute('value')) {961 return false;962 }963 return parent::setValue($value);964 }965 966 /**967 * Accessor for starting value.968 * @return string Parsed value.969 * @access public970 */971 function getDefault() {972 if ($this->getAttribute('checked') !== false) {973 return $this->getAttribute('value');974 }975 return false;976 }977}978/**979 * Checkbox widget.980 * @package SimpleTest981 * @subpackage WebTester982 */983class SimpleCheckboxTag extends SimpleWidget {984 985 /**986 * Starts with attributes only.987 * @param hash $attributes Attribute names and988 * string values.989 */990 function __construct($attributes) {991 parent::__construct('input', $attributes);992 if ($this->getAttribute('value') === false) {993 $this->setAttribute('value', 'on');994 }995 }996 997 /**998 * Tag contains no content.999 * @return boolean False.1000 * @access public1001 */1002 function expectEndTag() {1003 return false;1004 }1005 1006 /**1007 * The only allowed value in the one in the1008 * "value" attribute. The default for this1009 * attribute is "on". If this widget is set to1010 * true, then the usual value will be taken.1011 * @param string $value New value.1012 * @return boolean True if allowed.1013 * @access public1014 */1015 function setValue($value) {1016 if ($value === false) {1017 return parent::setValue($value);1018 }1019 if ($value === true) {1020 return parent::setValue($this->getAttribute('value'));1021 }1022 if ($value != $this->getAttribute('value')) {1023 return false;1024 }1025 return parent::setValue($value);1026 }1027 1028 /**1029 * Accessor for starting value. The default1030 * value is "on".1031 * @return string Parsed value.1032 * @access public1033 */1034 function getDefault() {1035 if ($this->getAttribute('checked') !== false) {1036 return $this->getAttribute('value');1037 }1038 return false;1039 }1040}1041/**1042 * A group of multiple widgets with some shared behaviour.1043 * @package SimpleTest1044 * @subpackage WebTester1045 */1046class SimpleTagGroup {1047 private $widgets = array();1048 /**1049 * Adds a tag to the group.1050 * @param SimpleWidget $widget1051 * @access public1052 */1053 function addWidget($widget) {1054 $this->widgets[] = $widget;1055 }1056 1057 /**1058 * Accessor to widget set.1059 * @return array All widgets.1060 * @access protected1061 */1062 protected function &getWidgets() {1063 return $this->widgets;1064 }1065 /**1066 * Accessor for an attribute.1067 * @param string $label Attribute name.1068 * @return boolean Always false.1069 * @access public1070 */1071 function getAttribute($label) {1072 return false;1073 }1074 1075 /**1076 * Fetches the name for the widget from the first1077 * member.1078 * @return string Name of widget.1079 * @access public1080 */1081 function getName() {1082 if (count($this->widgets) > 0) {1083 return $this->widgets[0]->getName();1084 }1085 }1086 1087 /**1088 * Scans the widgets for one with the appropriate1089 * ID field.1090 * @param string $id ID value to try.1091 * @return boolean True if matched.1092 * @access public1093 */1094 function isId($id) {1095 for ($i = 0, $count = count($this->widgets); $i < $count; $i++) {1096 if ($this->widgets[$i]->isId($id)) {1097 return true;1098 }1099 }1100 return false;1101 }1102 1103 /**1104 * Scans the widgets for one with the appropriate1105 * attached label.1106 * @param string $label Attached label to try.1107 * @return boolean True if matched.1108 * @access public1109 */1110 function isLabel($label) {1111 for ($i = 0, $count = count($this->widgets); $i < $count; $i++) {1112 if ($this->widgets[$i]->isLabel($label)) {1113 return true;1114 }1115 }1116 return false;1117 }1118 1119 /**1120 * Dispatches the value into the form encoded packet.1121 * @param SimpleEncoding $encoding Form packet.1122 * @access public1123 */1124 function write($encoding) {1125 $encoding->add($this->getName(), $this->getValue());1126 }1127}1128/**1129 * A group of tags with the same name within a form.1130 * @package SimpleTest1131 * @subpackage WebTester1132 */1133class SimpleCheckboxGroup extends SimpleTagGroup {1134 1135 /**1136 * Accessor for current selected widget or false1137 * if none.1138 * @return string/array Widget values or false if none.1139 * @access public1140 */1141 function getValue() {1142 $values = array();1143 $widgets = $this->getWidgets();1144 for ($i = 0, $count = count($widgets); $i < $count; $i++) {1145 if ($widgets[$i]->getValue() !== false) {1146 $values[] = $widgets[$i]->getValue();1147 }1148 }1149 return $this->coerceValues($values);1150 }1151 1152 /**1153 * Accessor for starting value that is active.1154 * @return string/array Widget values or false if none.1155 * @access public1156 */1157 function getDefault() {1158 $values = array();1159 $widgets = $this->getWidgets();1160 for ($i = 0, $count = count($widgets); $i < $count; $i++) {1161 if ($widgets[$i]->getDefault() !== false) {1162 $values[] = $widgets[$i]->getDefault();1163 }1164 }1165 return $this->coerceValues($values);1166 }1167 1168 /**1169 * Accessor for current set values.1170 * @param string/array/boolean $values Either a single string, a1171 * hash or false for nothing set.1172 * @return boolean True if all values can be set.1173 * @access public1174 */1175 function setValue($values) {1176 $values = $this->makeArray($values);1177 if (! $this->valuesArePossible($values)) {1178 return false;1179 }1180 $widgets = $this->getWidgets();1181 for ($i = 0, $count = count($widgets); $i < $count; $i++) {1182 $possible = $widgets[$i]->getAttribute('value');1183 if (in_array($widgets[$i]->getAttribute('value'), $values)) {1184 $widgets[$i]->setValue($possible);1185 } else {1186 $widgets[$i]->setValue(false);1187 }1188 }1189 return true;1190 }1191 1192 /**1193 * Tests to see if a possible value set is legal.1194 * @param string/array/boolean $values Either a single string, a1195 * hash or false for nothing set.1196 * @return boolean False if trying to set a1197 * missing value.1198 * @access private1199 */1200 protected function valuesArePossible($values) {1201 $matches = array();1202 $widgets = &$this->getWidgets();1203 for ($i = 0, $count = count($widgets); $i < $count; $i++) {1204 $possible = $widgets[$i]->getAttribute('value');1205 if (in_array($possible, $values)) {1206 $matches[] = $possible;1207 }1208 }1209 return ($values == $matches);1210 }1211 1212 /**1213 * Converts the output to an appropriate format. This means1214 * that no values is false, a single value is just that1215 * value and only two or more are contained in an array.1216 * @param array $values List of values of widgets.1217 * @return string/array/boolean Expected format for a tag.1218 * @access private1219 */1220 protected function coerceValues($values) {1221 if (count($values) == 0) {1222 return false;1223 } elseif (count($values) == 1) {1224 return $values[0];1225 } else {1226 return $values;1227 }1228 }1229 1230 /**1231 * Converts false or string into array. The opposite of1232 * the coercian method.1233 * @param string/array/boolean $value A single item is converted1234 * to a one item list. False1235 * gives an empty list.1236 * @return array List of values, possibly empty.1237 * @access private1238 */1239 protected function makeArray($value) {1240 if ($value === false) {1241 return array();1242 }1243 if (is_string($value)) {1244 return array($value);1245 }1246 return $value;1247 }1248}1249/**1250 * A group of tags with the same name within a form.1251 * Used for radio buttons.1252 * @package SimpleTest1253 * @subpackage WebTester1254 */1255class SimpleRadioGroup extends SimpleTagGroup {1256 1257 /**1258 * Each tag is tried in turn until one is1259 * successfully set. The others will be1260 * unchecked if successful.1261 * @param string $value New value.1262 * @return boolean True if any allowed.1263 * @access public1264 */1265 function setValue($value) {1266 if (! $this->valueIsPossible($value)) {1267 return false;1268 }1269 $index = false;1270 $widgets = $this->getWidgets();1271 for ($i = 0, $count = count($widgets); $i < $count; $i++) {1272 if (! $widgets[$i]->setValue($value)) {1273 $widgets[$i]->setValue(false);1274 }1275 }1276 return true;1277 }1278 1279 /**1280 * Tests to see if a value is allowed.1281 * @param string Attempted value.1282 * @return boolean True if a valid value.1283 * @access private1284 */1285 protected function valueIsPossible($value) {1286 $widgets = $this->getWidgets();1287 for ($i = 0, $count = count($widgets); $i < $count; $i++) {1288 if ($widgets[$i]->getAttribute('value') == $value) {1289 return true;1290 }1291 }1292 return false;1293 }1294 1295 /**1296 * Accessor for current selected widget or false1297 * if none.1298 * @return string/boolean Value attribute or1299 * content of opton.1300 * @access public1301 */1302 function getValue() {1303 $widgets = $this->getWidgets();1304 for ($i = 0, $count = count($widgets); $i < $count; $i++) {1305 if ($widgets[$i]->getValue() !== false) {1306 return $widgets[$i]->getValue();1307 }1308 }1309 return false;1310 }1311 1312 /**1313 * Accessor for starting value that is active.1314 * @return string/boolean Value of first checked1315 * widget or false if none.1316 * @access public1317 */1318 function getDefault() {1319 $widgets = $this->getWidgets();1320 for ($i = 0, $count = count($widgets); $i < $count; $i++) {1321 if ($widgets[$i]->getDefault() !== false) {1322 return $widgets[$i]->getDefault();1323 }1324 }1325 return false;1326 }1327}1328/**1329 * Tag to keep track of labels.1330 * @package SimpleTest1331 * @subpackage WebTester1332 */1333class SimpleLabelTag extends SimpleTag {1334 1335 /**1336 * Starts with a named tag with attributes only.1337 * @param hash $attributes Attribute names and1338 * string values.1339 */1340 function __construct($attributes) {1341 parent::__construct('label', $attributes);1342 }1343 1344 /**1345 * Access for the ID to attach the label to.1346 * @return string For attribute.1347 * @access public1348 */1349 function getFor() {1350 return $this->getAttribute('for');1351 }1352}1353/**1354 * Tag to aid parsing the form.1355 * @package SimpleTest1356 * @subpackage WebTester1357 */1358class SimpleFormTag extends SimpleTag {1359 1360 /**1361 * Starts with a named tag with attributes only.1362 * @param hash $attributes Attribute names and1363 * string values.1364 */1365 function __construct($attributes) {1366 parent::__construct('form', $attributes);1367 }1368}1369/**1370 * Tag to aid parsing the frames in a page.1371 * @package SimpleTest1372 * @subpackage WebTester1373 */1374class SimpleFrameTag extends SimpleTag {1375 1376 /**1377 * Starts with a named tag with attributes only.1378 * @param hash $attributes Attribute names and1379 * string values.1380 */1381 function __construct($attributes) {1382 parent::__construct('frame', $attributes);1383 }1384 1385 /**1386 * Tag contains no content.1387 * @return boolean False.1388 * @access public1389 */1390 function expectEndTag() {1391 return false;1392 }1393}1394?>...
Modules.php
Source:Modules.php
...7 *8 * 9 * Class and Function List:10 * Function list:11 * - __construct()12 * - getFilters()13 * - getSorts()14 * - getPerPage()15 * - getPage()16 * - getPlayerID()17 * - returnData()18 * - setDataSetSize()19 * - getPagination()20 * - setOffset()21 * - getOffset()22 * - retrieveData()23 * - __construct()24 * - __construct()25 * - __construct()26 * - __construct()27 * - __construct()28 * - __construct()29 * - __construct()30 * - __construct()31 * - __construct()32 * - __construct()33 * - __construct()34 * - __construct()35 * - __construct()36 * - __construct()37 * - getQuery()38 * - getPerPage()39 * - getPage()40 * - retrieveData()41 * - setDataSetSize()42 * - returnData()43 * - getPagination()44 * - setOffset()45 * - getOffset()46 * Classes list:47 * - Module48 * - People extends Module49 * - Pitching extends Module50 * - PitchingPost extends Module51 * - Batting extends Module52 * - BattingPost extends Module53 * - Fielding extends Module54 * - FieldingPost extends Module55 * - FieldingOF extends Module56 * - FieldingOFSplit extends Module57 * - Appearances extends Module58 * - Salaries extends Module59 * - Images extends Module60 * - Colleges extends Module61 * - Search62 * 63******************************************************************************/64include_once('Common-Structures.php');65include_once ('Constants.php');66require_once('Pagination.php');67require_once('API-Functions.php');68require_once('Parser.php');69class Module {70 protected $filters; // array of filters71 protected $sorts; // array of sorts72 protected $perPage; // int - number of items in data set73 protected $page; // int - offset74 protected $dataSet;75 protected $aggregate;76 protected $playerID;77 protected $offset;78 protected $dataSetSize;79 protected $parser;80 protected $db;81 protected $filterColumns;82 public function __construct() {83 $this->parser = new Parser();84 $this->setFilterColumns();85 $this->filters = $this->parser->getFilters();86 $this->verifyFilters();87 $this->sorts = $this->parser->getSorts();88 $this->verifySorts();89 $this->perPage = $this->parser->getPerPage();90 $this->page = $this->parser->getPage();91 $this->aggregate = $this->parser->getAggregate();92 $this->playerID = $this->parser->getPlayerID();93 $this->setOffset();94 $this->db = new DB($this->playerID, $this->sorts, $this->filters, $this->perPage, $this->offset);95 $this->dataSet = null;96 $this->dataSetSize = 1; // this will get changed later in each of the sub modules97 }98 protected function setFilterColumns() {99 switch ($this->parser->getModule()) {100 case Constants::Modules['Batting']:101 $this->filterColumns = Constants::Batting; break;102 case Constants::Modules['Pitching']:103 $this->filterColumns = Constants::Pitching; break;104 case Constants::Modules['Appearances']:105 $this->filterColumns = Constants::Appearances; break;106 case Constants::Modules['Fielding']:107 $this->filterColumns = Constants::Fielding; break;108 case Constants::Modules['People']:109 $this->filterColumns = Constants::People; break;110 case Constants::Modules['FieldingOF']:111 $this->filterColumns = Constants::FieldingOF; break;112 case Constants::Modules['FieldingOFSplit']:113 $this->filterColumns = Constants::FieldingOFSplit; break;114 case Constants::Modules['Salaries']:115 $this->filterColumns = Constants::Salaries; break;116 case Constants::Modules['Colleges']:117 $this->filterColumns = Constants::Colleges; break;118 case Constants::Modules['Images']:119 $this->filterColumns = Constants::Images; break;120 case Constants::Modules['BattingPost']:121 $this->filterColumns = Constants::BattingPost; break;122 case Constants::Modules['PitchingPost']:123 $this->filterColumns = Constants::PitchingPost; break;124 case Constants::Modules['FieldingPost']:125 $this->filterColumns = Constants::FieldingPost; break;126 case Constants::Modules['Teams']:127 $parserTeams = new ParserTeams();128 if ($parserTeams->returnPlayers()) $this->filterColumns = Constants::TeamPlayers;129 else $this->filterColumns = Constants::Teams;130 break;131 default:132 $this->filterColumns = null; break;133 }134 }135 private function verifySorts() {136 if ($this->sorts == null)137 return;138 // verify that the sort is included in the columns139 if (!in_array($this->sorts['column'], $this->filterColumns)) {140 ApiFunctions::returnBadRequest('Unrecognized sort column!');141 exit;142 }143 }144 private function verifyFilters() {145 if ($this->filters == null)146 return;147 for ($count = 0; $count < count($this->filters); $count++) {148 $filter = $this->filters[$count];149 // verify that the column is valid150 if (!in_array($filter['column'], $this->filterColumns)) {151 ApiFunctions::returnBadRequest('Error. Unrecognized filter column.');152 exit;153 }154 // verify that the filter conditional is valid155 if (!in_array($filter['conditional'], Constants::FilterConditionals)) {156 ApiFunctions::returnBadRequest('Unrecognized filter conditional');157 exit;158 }159 }160 }161 public function getFilters() {162 return $this->filters;163 }164 public function getSorts() {165 return $this->sorts;166 }167 public function getPerPage() {168 return $this->perPage;169 }170 public function getPage() {171 return $this->page;172 }173 public function getPlayerID() {174 return $this->playerID;175 }176 public function returnData() {177 $data = [];178 $data['pagination'] = $this->getPagination(); 179 $data['resultsCount'] = $this->dataSetSize; 180 $data['results'] = $this->dataSet;181 ApiFunctions::printJson($data);182 }183 public function setDataSetSize($functionAggregate, $function) {184 if ($this->aggregate)185 $this->dataSetSize = call_user_func(array($this->db, $functionAggregate));186 else187 $this->dataSetSize = call_user_func(array($this->db, $function));188 }189 public function getPagination() {190 $pagination = new Pagination($this->dataSetSize);191 $links = [];192 $links['first'] = $pagination->getPageFirst();193 $links['current'] = $pagination->getPageCurrent();194 $links['next'] = $pagination->getPageNext();195 $links['previous'] = $pagination->getPagePrevious();196 $links['last'] = $pagination->getPageLast();197 return $links;198 }199 public function setOffset() {200 $this->offset = ($this->perPage) * ($this->page - 1);201 }202 public function getOffset() {203 return $this->offset;204 }205 protected function retrieveData($aggregateFunction, $function) {206 // determine if I should use aggregate function or not207 if ($this->aggregate == true)208 $dataset = call_user_func(array($this->db, $aggregateFunction));209 else 210 $dataset = call_user_func(array($this->db, $function));211 212 $parser = new Parser(); // need this to get the module213 // if there is only 1 row for the results, then just fetch the first row214 if ($this->playerID != null && ($this->aggregate || $parser->getModule() == Constants::Modules['People']))215 $this->dataSet = $dataset->fetch(PDO::FETCH_ASSOC);216 else 217 $this->dataSet = $dataset->fetchAll(PDO::FETCH_ASSOC);218 }219}220class People extends Module {221 public function __construct() {222 parent::__construct();223 $this->retrieveData('getPeople', 'getPeople');224 $this->setDataSetSize('getPeopleCount', 'getPeopleCount');225 // add additional info if playerID is specified226 if ($this->playerID != null) {227 // teams played for228 $teams = $this->db->getTeamsPlayedFor($this->playerID)->fetchAll(PDO::FETCH_ASSOC);229 $this->dataSet['teamsPlayedFor'] = array_column($teams, 'name');230 // images231 $images = $this->db->getImagesPlayer($this->playerID)->fetchAll(PDO::FETCH_ASSOC);232 $this->dataSet['images'] = array_column($images, 'source');233 }234 }235}236class Pitching extends Module {237 public function __construct() {238 parent::__construct();239 $this->retrieveData('getPitchingAggregate', 'getPitching');240 $this->setDataSetSize('getPitchingAggregateCount', 'getPitchingCount');241 }242}243class PitchingPost extends Module {244 public function __construct() {245 parent::__construct();246 $this->retrieveData('getPitchingPostAggregate', 'getPitchingPost');247 $this->setDataSetSize('getPitchingPostAggregateCount', 'getPitchingPostCount');248 }249}250class Batting extends Module {251 public function __construct() {252 parent::__construct();253 $this->retrieveData('getBattingAggregate', 'getBatting');254 $this->setDataSetSize('getBattingAggregateCount', 'getBattingCount');255 }256}257class BattingPost extends Module {258 public function __construct() {259 parent::__construct();260 $this->retrieveData('getBattingPostAggregate', 'getBattingPost');261 $this->setDataSetSize('getBattingPostAggregateCount', 'getBattingPostCount');262 }263}264class Fielding extends Module {265 public function __construct() {266 parent::__construct();267 $this->retrieveData('getFieldingAggregate', 'getFielding');268 $this->setDataSetSize('getFieldingAggregateCount', 'getFieldingCount');269 }270}271class FieldingPost extends Module {272 public function __construct() {273 parent::__construct();274 $this->retrieveData('getFieldingPostAggregate', 'getFieldingPost');275 $this->setDataSetSize('getFieldingPostAggregateCount', 'getFieldingPostCount');276 }277}278class FieldingOF extends Module {279 public function __construct() {280 parent::__construct();281 $this->retrieveData('getFieldingOFAggregate', 'getFieldingOF');282 $this->setDataSetSize('getFieldingOFAggregateCount', 'getFieldingOFCount');283 }284}285class FieldingOFSplit extends Module {286 public function __construct() {287 parent::__construct();288 $this->retrieveData('getFieldingOFSplitAggregate', 'getFieldingOFSplit');289 $this->setDataSetSize('getFieldingOFSplitAggregateCount', 'getFieldingOFSplitCount');290 }291}292class Appearances extends Module {293 public function __construct() {294 parent::__construct();295 $this->retrieveData('getAppearancesAggregate', 'getAppearances');296 $this->setDataSetSize('getAppearancesAggregateCount', 'getAppearancesCount');297 }298}299class Salaries extends Module {300 public function __construct() {301 parent::__construct();302 $this->retrieveData('getSalariesAggregate', 'getSalaries');303 $this->setDataSetSize('getSalariesAggregateCount', 'getSalariesCount');304 }305}306class Images extends Module {307 public function __construct() {308 parent::__construct();309 $this->retrieveData('getImages', 'getImages');310 $this->setDataSetSize('getImagesCount', 'getImagesCount');311 }312}313Class Colleges extends Module {314 public function __construct() {315 parent::__construct();316 $this->retrieveData('getColleges', 'getColleges');317 $this->setDataSetSize('getCollegesCount', 'getCollegesCount');318 }319}320Class Teams extends Module {321 public function __construct() {322 parent::__construct();323 $parserTeams = new ParserTeams();324 // normal teams325 if ($parserTeams->getYear() == null) {326 $this->retrieveData('getTeamsAggregate', 'getTeams');327 $this->setDataSetSize('getTeamsAggregateCount', 'getTeamsCount');328 }329 // teams/year330 else if ($parserTeams->returnPlayers() == false) {331 $data = $this->db->getTeamYear($parserTeams->getYear());332 $this->dataSet = $data->fetch(PDO::FETCH_ASSOC);333 $this->dataSetSize = 1;334 }335 // teams/year/players336 else {337 $data = $this->db->getTeamYearPlayers($parserTeams->getYear());338 $this->dataSet = $data->fetchAll(PDO::FETCH_ASSOC);339 $this->dataSetSize = $this->db->getTeamYearPlayersCount($parserTeams->getYear());340 }341 }342}343class Describe extends Module {344 public function __construct() {345 $this->dataSetSize = 1;346 $dataSet = [];347 $modules = array_values(Constants::Modules);348 sort($modules);349 $dataSet['modules'] = $modules;350 $this->dataSet = $dataSet;351 }352}353class Search {354 private $query;355 private $perPage;356 private $dataSet;357 private $dataSetSize;358 private $page;359 private $offset;360 private $parser;361 private $db;362 public function __construct($newQuery) {363 $this->query = $newQuery;364 $this->parser = new Parser();365 $this->perPage = $this->parser->getPerPage();366 $this->page = $this->parser->getPage();367 $this->setOffset();368 $this->db = new DB(null, null, null, $this->perPage, $this->offset);369 $this->retrieveData();370 $this->setDataSetSize();371 }372 public function getQuery() {373 return $this->query;374 }375 public function getPerPage() {376 return $this->perPage;...
Diff.php
Source:Diff.php
...30 * @param array $params Parameters to pass to the diffing engine.31 * Normally an array of two arrays, each32 * containing the lines from a file.33 */34 function __construct( $engine, $params )35 {36 // Backward compatibility workaround.37 if (!is_string($engine)) {38 $params = array($engine, $params);39 $engine = 'auto';40 }41 if ($engine == 'auto') {42 $engine = extension_loaded('xdiff') ? 'xdiff' : 'native';43 } else {44 $engine = basename($engine);45 }46 // WP #739147 require_once dirname(__FILE__).'/Diff/Engine/' . $engine . '.php';48 $class = 'Text_Diff_Engine_' . $engine;49 $diff_engine = new $class();50 $this->_edits = call_user_func_array(array($diff_engine, 'diff'), $params);51 }52 /**53 * PHP4 constructor.54 */55 public function Text_Diff( $engine, $params ) {56 self::__construct( $engine, $params );57 }58 /**59 * Returns the array of differences.60 */61 function getDiff()62 {63 return $this->_edits;64 }65 /**66 * returns the number of new (added) lines in a given diff.67 *68 * @since Text_Diff 1.1.069 *70 * @return int The number of new lines71 */72 function countAddedLines()73 {74 $count = 0;75 foreach ($this->_edits as $edit) {76 if (is_a($edit, 'Text_Diff_Op_add') ||77 is_a($edit, 'Text_Diff_Op_change')) {78 $count += $edit->nfinal();79 }80 }81 return $count;82 }83 /**84 * Returns the number of deleted (removed) lines in a given diff.85 *86 * @since Text_Diff 1.1.087 *88 * @return int The number of deleted lines89 */90 function countDeletedLines()91 {92 $count = 0;93 foreach ($this->_edits as $edit) {94 if (is_a($edit, 'Text_Diff_Op_delete') ||95 is_a($edit, 'Text_Diff_Op_change')) {96 $count += $edit->norig();97 }98 }99 return $count;100 }101 /**102 * Computes a reversed diff.103 *104 * Example:105 * <code>106 * $diff = new Text_Diff($lines1, $lines2);107 * $rev = $diff->reverse();108 * </code>109 *110 * @return Text_Diff A Diff object representing the inverse of the111 * original diff. Note that we purposely don't return a112 * reference here, since this essentially is a clone()113 * method.114 */115 function reverse()116 {117 if (version_compare(zend_version(), '2', '>')) {118 $rev = clone($this);119 } else {120 $rev = $this;121 }122 $rev->_edits = array();123 foreach ($this->_edits as $edit) {124 $rev->_edits[] = $edit->reverse();125 }126 return $rev;127 }128 /**129 * Checks for an empty diff.130 *131 * @return bool True if two sequences were identical.132 */133 function isEmpty()134 {135 foreach ($this->_edits as $edit) {136 if (!is_a($edit, 'Text_Diff_Op_copy')) {137 return false;138 }139 }140 return true;141 }142 /**143 * Computes the length of the Longest Common Subsequence (LCS).144 *145 * This is mostly for diagnostic purposes.146 *147 * @return int The length of the LCS.148 */149 function lcs()150 {151 $lcs = 0;152 foreach ($this->_edits as $edit) {153 if (is_a($edit, 'Text_Diff_Op_copy')) {154 $lcs += count($edit->orig);155 }156 }157 return $lcs;158 }159 /**160 * Gets the original set of lines.161 *162 * This reconstructs the $from_lines parameter passed to the constructor.163 *164 * @return array The original sequence of strings.165 */166 function getOriginal()167 {168 $lines = array();169 foreach ($this->_edits as $edit) {170 if ($edit->orig) {171 array_splice($lines, count($lines), 0, $edit->orig);172 }173 }174 return $lines;175 }176 /**177 * Gets the final set of lines.178 *179 * This reconstructs the $to_lines parameter passed to the constructor.180 *181 * @return array The sequence of strings.182 */183 function getFinal()184 {185 $lines = array();186 foreach ($this->_edits as $edit) {187 if ($edit->final) {188 array_splice($lines, count($lines), 0, $edit->final);189 }190 }191 return $lines;192 }193 /**194 * Removes trailing newlines from a line of text. This is meant to be used195 * with array_walk().196 *197 * @param string $line The line to trim.198 * @param int $key The index of the line in the array. Not used.199 */200 static function trimNewlines(&$line, $key)201 {202 $line = str_replace(array("\n", "\r"), '', $line);203 }204 /**205 * Determines the location of the system temporary directory.206 *207 * @access protected208 *209 * @return string A directory name which can be used for temp files.210 * Returns false if one could not be found.211 */212 static function _getTempDir()213 {214 $tmp_locations = array('/tmp', '/var/tmp', 'c:\WUTemp', 'c:\temp',215 'c:\windows\temp', 'c:\winnt\temp');216 /* Try PHP's upload_tmp_dir directive. */217 $tmp = ini_get('upload_tmp_dir');218 /* Otherwise, try to determine the TMPDIR environment variable. */219 if (!strlen($tmp)) {220 $tmp = getenv('TMPDIR');221 }222 /* If we still cannot determine a value, then cycle through a list of223 * preset possibilities. */224 while (!strlen($tmp) && count($tmp_locations)) {225 $tmp_check = array_shift($tmp_locations);226 if (@is_dir($tmp_check)) {227 $tmp = $tmp_check;228 }229 }230 /* If it is still empty, we have failed, so return false; otherwise231 * return the directory determined. */232 return strlen($tmp) ? $tmp : false;233 }234 /**235 * Checks a diff for validity.236 *237 * This is here only for debugging purposes.238 */239 function _check($from_lines, $to_lines)240 {241 if (serialize($from_lines) != serialize($this->getOriginal())) {242 trigger_error("Reconstructed original doesn't match", E_USER_ERROR);243 }244 if (serialize($to_lines) != serialize($this->getFinal())) {245 trigger_error("Reconstructed final doesn't match", E_USER_ERROR);246 }247 $rev = $this->reverse();248 if (serialize($to_lines) != serialize($rev->getOriginal())) {249 trigger_error("Reversed original doesn't match", E_USER_ERROR);250 }251 if (serialize($from_lines) != serialize($rev->getFinal())) {252 trigger_error("Reversed final doesn't match", E_USER_ERROR);253 }254 $prevtype = null;255 foreach ($this->_edits as $edit) {256 if ($edit instanceof $prevtype) {257 trigger_error("Edit sequence is non-optimal", E_USER_ERROR);258 }259 $prevtype = get_class($edit);260 }261 return true;262 }263}264/**265 * @package Text_Diff266 * @author Geoffrey T. Dairiki <dairiki@dairiki.org>267 */268class Text_MappedDiff extends Text_Diff {269 /**270 * Computes a diff between sequences of strings.271 *272 * This can be used to compute things like case-insensitve diffs, or diffs273 * which ignore changes in white-space.274 *275 * @param array $from_lines An array of strings.276 * @param array $to_lines An array of strings.277 * @param array $mapped_from_lines This array should have the same size278 * number of elements as $from_lines. The279 * elements in $mapped_from_lines and280 * $mapped_to_lines are what is actually281 * compared when computing the diff.282 * @param array $mapped_to_lines This array should have the same number283 * of elements as $to_lines.284 */285 function __construct($from_lines, $to_lines,286 $mapped_from_lines, $mapped_to_lines)287 {288 assert(count($from_lines) == count($mapped_from_lines));289 assert(count($to_lines) == count($mapped_to_lines));290 parent::Text_Diff($mapped_from_lines, $mapped_to_lines);291 $xi = $yi = 0;292 for ($i = 0; $i < count($this->_edits); $i++) {293 $orig = &$this->_edits[$i]->orig;294 if (is_array($orig)) {295 $orig = array_slice($from_lines, $xi, count($orig));296 $xi += count($orig);297 }298 $final = &$this->_edits[$i]->final;299 if (is_array($final)) {300 $final = array_slice($to_lines, $yi, count($final));301 $yi += count($final);302 }303 }304 }305 /**306 * PHP4 constructor.307 */308 public function Text_MappedDiff( $from_lines, $to_lines,309 $mapped_from_lines, $mapped_to_lines ) {310 self::__construct( $from_lines, $to_lines,311 $mapped_from_lines, $mapped_to_lines );312 }313}314/**315 * @package Text_Diff316 * @author Geoffrey T. Dairiki <dairiki@dairiki.org>317 *318 * @access private319 */320class Text_Diff_Op {321 var $orig;322 var $final;323 function &reverse()324 {325 trigger_error('Abstract method', E_USER_ERROR);326 }327 function norig()328 {329 return $this->orig ? count($this->orig) : 0;330 }331 function nfinal()332 {333 return $this->final ? count($this->final) : 0;334 }335}336/**337 * @package Text_Diff338 * @author Geoffrey T. Dairiki <dairiki@dairiki.org>339 *340 * @access private341 */342class Text_Diff_Op_copy extends Text_Diff_Op {343 /**344 * PHP5 constructor.345 */346 function __construct( $orig, $final = false )347 {348 if (!is_array($final)) {349 $final = $orig;350 }351 $this->orig = $orig;352 $this->final = $final;353 }354 /**355 * PHP4 constructor.356 */357 public function Text_Diff_Op_copy( $orig, $final = false ) {358 self::__construct( $orig, $final );359 }360 function &reverse()361 {362 $reverse = new Text_Diff_Op_copy($this->final, $this->orig);363 return $reverse;364 }365}366/**367 * @package Text_Diff368 * @author Geoffrey T. Dairiki <dairiki@dairiki.org>369 *370 * @access private371 */372class Text_Diff_Op_delete extends Text_Diff_Op {373 /**374 * PHP5 constructor.375 */376 function __construct( $lines )377 {378 $this->orig = $lines;379 $this->final = false;380 }381 /**382 * PHP4 constructor.383 */384 public function Text_Diff_Op_delete( $lines ) {385 self::__construct( $lines );386 }387 function &reverse()388 {389 $reverse = new Text_Diff_Op_add($this->orig);390 return $reverse;391 }392}393/**394 * @package Text_Diff395 * @author Geoffrey T. Dairiki <dairiki@dairiki.org>396 *397 * @access private398 */399class Text_Diff_Op_add extends Text_Diff_Op {400 /**401 * PHP5 constructor.402 */403 function __construct( $lines )404 {405 $this->final = $lines;406 $this->orig = false;407 }408 /**409 * PHP4 constructor.410 */411 public function Text_Diff_Op_add( $lines ) {412 self::__construct( $lines );413 }414 function &reverse()415 {416 $reverse = new Text_Diff_Op_delete($this->final);417 return $reverse;418 }419}420/**421 * @package Text_Diff422 * @author Geoffrey T. Dairiki <dairiki@dairiki.org>423 *424 * @access private425 */426class Text_Diff_Op_change extends Text_Diff_Op {427 /**428 * PHP5 constructor.429 */430 function __construct( $orig, $final )431 {432 $this->orig = $orig;433 $this->final = $final;434 }435 /**436 * PHP4 constructor.437 */438 public function Text_Diff_Op_change( $orig, $final ) {439 self::__construct( $orig, $final );440 }441 function &reverse()442 {443 $reverse = new Text_Diff_Op_change($this->final, $this->orig);444 return $reverse;445 }446}...
results.php
Source:results.php
...12 return $text; 13 }14 15 16 function __construct($name, $picture) {17 $this->name = $name;18 $this->picture = $picture; 19 }20 21 abstract function makeSound();22 23 24 function alertPicture() {25 echo "<img src='".$this->picture. "' onClick= '" .$this->onClickPicture(). "'/>"; 26 }27 28}29class Apa extends Animal {30 31 function __construct($name, $picture) {32 parent::__construct($name, $picture);33 }34 35 function makeSound() {36 return "AOOOPAAA"; 37 }38 39}40class Giraff extends Animal {41 42 43 function __construct($name, $picture) {44 parent::__construct($name, $picture);45 }46 47 48 function makeSound() {49 return "IAWOOO"; 50 51 }52 53}54class Tiger extends Animal {55 56 57 function __construct($name, $picture) {58 parent::__construct($name, $picture); 59 }60 61 62 function makeSound() {63 return "WAAAGH"; 64 65 }66 67}68class Coconut extends Animal {69 70 71 function __construct($name, $picture) {72 parent::__construct($name, $picture); 73 }74 75 76 function makeSound() {77 return "PLOOOP"; 78 79 }80 81}82function animalsPicture($pictureCount) {83 if($pictureCount == 2) {84 return 1; 85 } else {86 return $pictureCount + 1; ...
__construct
Using AI Code Generation
1$object = new Count();2$object->count();3$object = new Count();4$object->count();5$object = new Count();6$object->count();
__construct
Using AI Code Generation
1$counter = new Count(5);2echo $counter->getCount();3$counter = new Count(5);4echo $counter->getCount();5$counter = new Count(5);6echo $counter->getCount();7$counter = new Count(5);8echo $counter->getCount();9$counter = new Count(5);10echo $counter->getCount();11$counter = new Count(5);12echo $counter->getCount();13$counter = new Count(5);14echo $counter->getCount();15$counter = new Count(5);16echo $counter->getCount();17$counter = new Count(5);18echo $counter->getCount();19$counter = new Count(5);20echo $counter->getCount();21$counter = new Count(5);22echo $counter->getCount();23$counter = new Count(5);24echo $counter->getCount();25$counter = new Count(5);26echo $counter->getCount();27$counter = new Count(5);28echo $counter->getCount();29$counter = new Count(5);30echo $counter->getCount();
__construct
Using AI Code Generation
1$obj = new Count();2$obj->__construct();3$obj->count();4$obj->__destruct();5$obj = new Count();6$obj->__construct();7$obj->count();8$obj->__destruct();9Recommended Posts: PHP | __destruct() Magic Method10PHP | __call() Magic Method11PHP | __callStatic() Magic Method12PHP | __get() Magic Method13PHP | __set() Magic Method14PHP | __isset() Magic Method15PHP | __unset() Magic Method16PHP | __sleep() Magic Method17PHP | __wakeup() Magic Method18PHP | __toString() Magic Method19PHP | __invoke() Magic Method20PHP | __set_state() Magic Method21PHP | __clone() Magic Method22PHP | __debugInfo() Magic Method23PHP | __autoload() Magic Method24PHP | __halt_compiler() Magic Method25PHP | __HALT_COMPILER() Magic Constant26PHP | __HALT_COMPILER() Magic Constant27PHP | __HALT_COMPILER() Magic Constant
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with __construct on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!