Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 85 lines (78 sloc) 1.619 kb
59b5898 Initial commit
Niklas Närhinen authored
1 <?php
068d32a some basic information to the php doc
Niklas Närhinen authored
2
3 /**
4 * For the full copyright and license information, please view the LICENSE
5 * file that was distributed with this source code.
6 *
7 * @license MIT License
8 */
9
10 /**
11 * The main class for the Behavior
12 *
13 * @author Niklas Närhinen <niklas@narhinen.net>
14 */
59b5898 Initial commit
Niklas Närhinen authored
15 class ArrayAccessBehavior extends Behavior
16 {
17 public function objectMethods()
18 {
19 $script = '';
20 $script .= $this->addArrayAccessGetter();
21 $script .= $this->addArrayAccessSetter();
22 $script .= $this->addArrayAccessUnsetter();
23 $script .= $this->addArrayAccessIssetChecker();
24 return $script;
25 }
26
27 public function objectFilter(&$script)
28 {
29 $pattern = '/abstract class (\w+) extends (\w+) implements (\w+)/i';
30 $replace = 'abstract class ${1} extends ${2} implements ${3}, ArrayAccess';
31 $script = preg_replace($pattern, $replace, $script);
32 }
33
34 protected function addArrayAccessIssetChecker()
35 {
36 return "
37 public function offsetExists(\$offset)
38 {
360dc9c Added support for foreign keys in ArrayAccess methods
Niklas Närhinen authored
39 try {
40 \$getter = 'get' . \$offset;
41 return \$this->\$getter() !== null;
42 }
43 catch (PropelException \$ex) {
44 return false;
45 }
59b5898 Initial commit
Niklas Närhinen authored
46 }
47 ";
48 }
49
50 protected function addArrayAccessGetter()
51 {
52 return "
53 public function offsetGet(\$offset)
54 {
360dc9c Added support for foreign keys in ArrayAccess methods
Niklas Närhinen authored
55 \$getter = 'get' . \$offset;
56 return \$this->\$getter();
59b5898 Initial commit
Niklas Närhinen authored
57 }
58 ";
59 }
60
61 protected function addArrayAccessUnsetter()
62 {
63 return "
64 public function offsetUnset(\$offset)
65 {
360dc9c Added support for foreign keys in ArrayAccess methods
Niklas Närhinen authored
66 try {
67 \$setter = 'set' . \$offset;
68 \$this->\$setter(null);
69 }
70 catch (PropelException \$ex) { }
59b5898 Initial commit
Niklas Närhinen authored
71 }
72 ";
73 }
74
75 protected function addArrayAccessSetter()
76 {
77 return "
78 public function offsetSet(\$offset, \$value)
79 {
360dc9c Added support for foreign keys in ArrayAccess methods
Niklas Närhinen authored
80 \$setter = 'set' . \$offset;
81 \$this->\$setter(\$value);
59b5898 Initial commit
Niklas Närhinen authored
82 }
83 ";
84 }
85 }
Something went wrong with that request. Please try again.