1 <?php
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
22
23 class phpMorphy_Link_Base {
24 protected
25 $fsa,
26 $trans,
27 $raw_trans;
28
29 function phpMorphy_Link_Base(phpMorphy_Fsa_Interface $fsa, $trans, $rawTrans) {
30 $this->fsa = $fsa;
31 $this->trans = $trans;
32 $this->raw_trans = $rawTrans;
33 }
34
35 function isAnnotation() { }
36 function getTrans() { return $this->trans; }
37 function getFsa() { return $this->fsa; }
38 function getRawTrans() { return $this->raw_trans; }
39 };
40
41 42 43
44 class phpMorphy_Link extends phpMorphy_Link_Base {
45 function isAnnotation() { return false; }
46
47 function getDest() { return $this->trans['dest']; }
48 function getAttr() { return $this->trans['attr']; }
49
50 function getTargetState() {
51 return $this->createState($this->trans['dest']);
52 }
53
54 protected function createState($index) {
55 return new phpMorphy_State($this->fsa, $index);
56 }
57 }
58
59 class phpMorphy_Link_Annot extends phpMorphy_Link_Base {
60 function isAnnotation() { return true; }
61
62 function getAnnotation() {
63 return $this->fsa->getAnnot($this->raw_trans);
64 }
65 };
66
67 class phpMorphy_State {
68 protected
69 $fsa,
70 $transes,
71 $raw_transes;
72
73 function phpMorphy_State(phpMorphy_Fsa_Interface $fsa, $index) {
74 $this->fsa = $fsa;
75
76 $this->raw_transes = $fsa->readState($index);
77 $this->transes = $fsa->unpackTranses($this->raw_transes);
78 }
79
80 function getLinks() {
81 $result = array();
82
83 for($i = 0, $c = count($this->transes); $i < $c; $i++) {
84 $trans = $this->transes[$i];
85
86 if(!$trans['term']) {
87 $result[] = $this->createNormalLink($trans, $this->raw_transes[$i]);
88 } else {
89 $result[] = $this->createAnnotLink($trans, $this->raw_transes[$i]);
90 }
91 }
92
93 return $result;
94 }
95
96 function getSize() { return count($this->transes); }
97
98 protected function createNormalLink($trans, $raw) {
99 return new phpMorphy_Link($this->fsa, $trans, $raw);
100 }
101
102 protected function createAnnotLink($trans, $raw) {
103 return new phpMorphy_Link_Annot($this->fsa, $trans, $raw);
104 }
105 };
106
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-