Skip to content

Commit 6162e90

Browse files
committed
Introduced smarty namespace to the project.
Fixes: #79
1 parent 2043643 commit 6162e90

File tree

10 files changed

+1044
-0
lines changed

10 files changed

+1044
-0
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"phpunit/phpunit": ">=6.4.0",
2525
"ext-mbstring": "*"
2626
},
27+
"suggest": {
28+
"smarty/smarty": "Required for smarty template namespace."
29+
},
2730
"autoload": {
2831
"psr-4": {"Candango\\MyFuses\\": "src/MyFuses/"}
2932
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/**
3+
* MyFuses Framework (http://myfuses.candango.org)
4+
*
5+
* @link http://github.com/candango/myfuses
6+
* @copyright Copyright (c) 2006 - 2020 Flavio Garcia
7+
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
8+
*/
9+
10+
use Candango\MyFuses\Core\AbstractVerb;
11+
12+
13+
class SmartyAddVerb extends AbstractVerb
14+
{
15+
16+
private $instanceName = "default";
17+
18+
private $templateFile;
19+
20+
/**
21+
*
22+
*/
23+
public function getInstanceName()
24+
{
25+
return $this->instanceName;
26+
}
27+
28+
/**
29+
*
30+
*/
31+
public function setInstanceName($instanceName)
32+
{
33+
$this->instanceName = $instanceName;
34+
}
35+
36+
/**
37+
*
38+
*/
39+
public function getTemplateFile()
40+
{
41+
return $this->templateFile;
42+
}
43+
44+
/**
45+
*
46+
*/
47+
public function setTemplateFile($templateFile)
48+
{
49+
$this->templateFile = $templateFile;
50+
}
51+
52+
53+
/**
54+
* Get verb data
55+
*
56+
* @return array
57+
*/
58+
public function getData()
59+
{
60+
$data = parent::getData();
61+
62+
if( $this->getInstanceName() != "default" ) {
63+
$data['attributes']['template'] = $this->getInstanceName();
64+
}
65+
66+
$data['attributes']['file'] = $this->getTemplateFile();
67+
68+
return $data;
69+
}
70+
71+
/**
72+
* Set verb data
73+
*
74+
* @param array $data
75+
*/
76+
public function setData($data)
77+
{
78+
parent::setData($data);
79+
80+
if(isset($data['attributes']['template']))
81+
{
82+
$this->setInstanceName($data['attributes']['template']);
83+
}
84+
85+
if(isset($data['attributes']['file']))
86+
{
87+
$this->setTemplateFile($data['attributes']['file']);
88+
}
89+
90+
}
91+
92+
/**
93+
* Return the parsed code
94+
*
95+
* @return string
96+
*/
97+
public function getParsedCode($commented, $identLevel)
98+
{
99+
$strOut = parent::getParsedCode($commented, $identLevel );
100+
$strTemplateHandler = "Candango\MyFuses\Util\Template\TemplateHandler";
101+
$strOut .= str_repeat("\t", $identLevel);
102+
$strOut .= "\$templateHandler = " . $strTemplateHandler .
103+
"::getInstance(\"" . $this->getInstanceName() . "\");\n";
104+
$strOut .= str_repeat( "\t", $identLevel );
105+
$strOut .= "\$templateHandler->addFile( \"" .
106+
$this->getTemplateFile() . "\" );\n\n";
107+
return $strOut;
108+
}
109+
110+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
/**
3+
* MyFuses Framework (http://myfuses.candango.org)
4+
*
5+
* @link http://github.com/candango/myfuses
6+
* @copyright Copyright (c) 2006 - 2020 Flavio Garcia
7+
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
8+
*/
9+
10+
use Candango\MyFuses\Core\AbstractVerb;
11+
use Candango\MyFuses\Process\Context;
12+
13+
14+
class SmartyAssignVerb extends AbstractVerb
15+
{
16+
17+
private $instanceName = "default";
18+
19+
private $variableName;
20+
21+
private $variableValue;
22+
23+
/**
24+
*
25+
*/
26+
public function getInstanceName()
27+
{
28+
return $this->instanceName;
29+
}
30+
31+
/**
32+
*
33+
*/
34+
public function setInstanceName($instanceName)
35+
{
36+
$this->instanceName = $instanceName;
37+
}
38+
39+
/**
40+
*
41+
*/
42+
public function getVariableName()
43+
{
44+
return $this->variableName;
45+
}
46+
47+
/**
48+
*
49+
*/
50+
public function setVariableName($variableName)
51+
{
52+
$this->variableName = $variableName;
53+
}
54+
55+
/**
56+
*
57+
*/
58+
public function getVariableValue()
59+
{
60+
return $this->variableValue;
61+
}
62+
63+
/**
64+
*
65+
*/
66+
public function setVariableValue($variableValue)
67+
{
68+
$this->variableValue = $variableValue;
69+
}
70+
71+
/**
72+
* Get verb data
73+
*
74+
* @return array
75+
*/
76+
public function getData()
77+
{
78+
$data = parent::getData();
79+
if($this->getInstanceName() != "default")
80+
{
81+
$data['attributes']['template'] = $this->getInstanceName();
82+
}
83+
$data['attributes']['name'] = $this->getVariableName();
84+
$data['attributes']['value'] = $this->getVariableValue();
85+
return $data;
86+
}
87+
88+
/**
89+
* Set verb data
90+
*
91+
* @param array $data
92+
*/
93+
public function setData($data)
94+
{
95+
parent::setData($data);
96+
if(isset($data['attributes']['template']))
97+
{
98+
$this->setInstanceName($data['attributes']['name']);
99+
}
100+
if(isset($data['attributes']['name']))
101+
{
102+
$this->setVariableName($data['attributes']['name']);
103+
}
104+
if(isset($data['attributes']['value']))
105+
{
106+
$this->setVariableValue($data['attributes']['value']);
107+
}
108+
}
109+
110+
/**
111+
* Return the parsed code
112+
*
113+
* @return string
114+
*/
115+
public function getParsedCode($commented, $identLevel)
116+
{
117+
$strOut = parent::getParsedCode($commented, $identLevel );
118+
$strTemplateHandler = "Candango\MyFuses\Util\Template\TemplateHandler";
119+
$strOut .= str_repeat("\t", $identLevel);
120+
$strOut .= "\$templateHandler = " . $strTemplateHandler .
121+
"::getInstance(\"" . $this->getInstanceName() . "\");\n";
122+
$strOut .= str_repeat("\t", $identLevel);
123+
if (is_null($this->getVariableName())) {
124+
$strOut .= str_repeat("\t", $identLevel);
125+
$strOut .= Context::sanitizeHashedString(
126+
"\$templateHandler->assign(\"" . $this->getVariableName() .
127+
"\", \"\"") . ");\n\n";
128+
}
129+
else {
130+
$strOut .= Context::sanitizeHashedString(
131+
"\$templateHandler->assign(\"" . $this->getVariableName() .
132+
"\", \"" . $this->getVariableValue() ) . "\");\n\n";
133+
}
134+
return $strOut;
135+
}
136+
137+
}

0 commit comments

Comments
 (0)