Skip to content

Commit 86d3478

Browse files
committed
- (API) Refactored settings models so that even parcel settings are parsed dynamically
1 parent b4b7b3c commit 86d3478

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
namespace Craft;
3+
4+
use Craft\Plugins\Postmaster\Interfaces\ParseInterface;
5+
6+
class Postmaster_BaseSettingsModel extends BaseModel implements ParseInterface
7+
{
8+
public function parse(Array $data = array())
9+
{
10+
$this->setAttributes($this->parseArray($this->getAttributes(), $data));
11+
12+
return $this;
13+
}
14+
15+
public function render($value, Array $data = array())
16+
{
17+
return craft()->templates->renderString($value, $data);
18+
}
19+
20+
public function parseArray($subject, Array $data = array())
21+
{
22+
if(is_string($subject) && !empty($subject))
23+
{
24+
$subject = $this->render($subject, $data);
25+
}
26+
else if(is_array($subject) || is_object($subject))
27+
{
28+
foreach($subject as $index => $value)
29+
{
30+
$subject[$index] = $this->parseArray($value, $data);
31+
}
32+
}
33+
34+
return $subject;
35+
}
36+
37+
protected function defineAttributes()
38+
{
39+
return array();
40+
}
41+
}

0 commit comments

Comments
 (0)