This repository was archived by the owner on Jan 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +66
-2
lines changed Expand file tree Collapse file tree 3 files changed +66
-2
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ $this->placeholder('foo')
63
63
<?= $this->placeholder('foo') ?>
64
64
```
65
65
66
- The above results in an unodered list with pretty indentation.
66
+ The above results in an unordered list with pretty indentation.
67
67
68
68
Because the ` Placeholder ` container objects extend ` ArrayObject ` , you can also
69
69
assign content to a specific key in the container easily, instead of simply
@@ -131,6 +131,21 @@ foreach ($this->data as $datum): ?>
131
131
<?= $this->placeholder('foo')->data ?>
132
132
```
133
133
134
+ ## Clearing Content
135
+
136
+ In certain situations it is desirable to remove or clear containers and aggregated content. The placeholder view helper
137
+ provides two methods to either delete a specific container or clear all containers at once:
138
+
139
+ ``` php
140
+ <?php
141
+ // Delete a single Container
142
+ $placeholderHelper = $this->plugin('placeholder');
143
+ $placeholderHelper->deleteContainer('myNamedContainer');
144
+ // Clear all containers at once
145
+ $placeholderHelper->clearContainers();
146
+ ?>
147
+ ```
148
+
134
149
## Concrete Implementations
135
150
136
151
zend-view ships with a number of "concrete" placeholder implementations. These
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class Placeholder extends AbstractHelper
23
23
/**
24
24
* Placeholder items
25
25
*
26
- * @var array
26
+ * @var Container\AbstractContainer[]
27
27
*/
28
28
protected $ items = [];
29
29
@@ -97,4 +97,28 @@ public function containerExists($key)
97
97
$ return = array_key_exists ($ key , $ this ->items );
98
98
return $ return ;
99
99
}
100
+
101
+ /**
102
+ * Delete a specific container by name
103
+ *
104
+ * @param string $key
105
+ * @return self
106
+ */
107
+ public function deleteContainer ($ key )
108
+ {
109
+ $ key = (string ) $ key ;
110
+ unset($ this ->items [$ key ]);
111
+ return $ this ;
112
+ }
113
+
114
+ /**
115
+ * Remove all containers
116
+ *
117
+ * @return self
118
+ */
119
+ public function clearContainers ()
120
+ {
121
+ $ this ->items = [];
122
+ return $ this ;
123
+ }
100
124
}
Original file line number Diff line number Diff line change @@ -77,4 +77,29 @@ public function testPlaceholderRetrievesSameContainerOnSubsequentCalls()
77
77
$ container2 = $ this ->placeholder ->__invoke ('foo ' );
78
78
$ this ->assertSame ($ container1 , $ container2 );
79
79
}
80
+
81
+ public function testContainersCanBeDeleted ()
82
+ {
83
+ $ container = $ this ->placeholder ->__invoke ('foo ' );
84
+ $ container ->set ('Value ' );
85
+ $ this ->assertTrue ($ this ->placeholder ->containerExists ('foo ' ));
86
+ $ this ->assertSame ('Value ' , (string ) $ this ->placeholder ->__invoke ('foo ' ));
87
+ $ this ->placeholder ->deleteContainer ('foo ' );
88
+ $ this ->assertFalse ($ this ->placeholder ->containerExists ('foo ' ));
89
+ $ this ->assertSame ('' , (string ) $ this ->placeholder ->__invoke ('foo ' ));
90
+ }
91
+
92
+ public function testClearContainersRemovesAllContainers ()
93
+ {
94
+ $ this ->placeholder ->__invoke ('foo ' );
95
+ $ this ->placeholder ->__invoke ('bar ' );
96
+
97
+ $ this ->assertTrue ($ this ->placeholder ->containerExists ('foo ' ));
98
+ $ this ->assertTrue ($ this ->placeholder ->containerExists ('bar ' ));
99
+
100
+ $ this ->placeholder ->clearContainers ();
101
+
102
+ $ this ->assertFalse ($ this ->placeholder ->containerExists ('foo ' ));
103
+ $ this ->assertFalse ($ this ->placeholder ->containerExists ('bar ' ));
104
+ }
80
105
}
You can’t perform that action at this time.
0 commit comments