@@ -33,11 +33,17 @@ |
||
| 33 | 33 | class Text extends Tag { |
| 34 | 34 | protected $escape = true; |
| 35 | 35 | |
| 36 | + /** |
|
| 37 | + * @param string $tag |
|
| 38 | + */ |
|
| 36 | 39 | function __construct($tag) { |
| 37 | 40 | parent::__construct(); |
| 38 | 41 | $this->escape = ($tag == "_"); |
| 39 | 42 | } |
| 40 | 43 | |
| 44 | + /** |
|
| 45 | + * @param string $s |
|
| 46 | + */ |
|
| 41 | 47 | function addContent($s, $strtype = H\Text::TOKEN_HTML) { |
| 42 | 48 | if (trim($s)) { |
| 43 | 49 | if ($this->escape) { |
@@ -43,8 +43,9 @@ |
||
| 43 | 43 | if ($this->escape) { |
| 44 | 44 | $parse = new H\Text($s, $strtype); |
| 45 | 45 | $this->content[] = $parse->toHTML(); |
| 46 | - } else |
|
| 47 | - $this->content[] = $s; |
|
| 46 | + } else { |
|
| 47 | + $this->content[] = $s; |
|
| 48 | + } |
|
| 48 | 49 | } |
| 49 | 50 | } |
| 50 | 51 | |
@@ -13,6 +13,9 @@ |
||
| 13 | 13 | protected $s; |
| 14 | 14 | protected $type; |
| 15 | 15 | |
| 16 | + /** |
|
| 17 | + * @param string $s |
|
| 18 | + */ |
|
| 16 | 19 | function __construct($s, $type = self::TOKEN_HTML) { |
| 17 | 20 | $this->s = str_replace('\\$', "$", $s); |
| 18 | 21 | $this->type = $type; |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Created by PhpStorm. |
|
| 4 | - * User: Chris |
|
| 5 | - * Date: 4/12/2014 |
|
| 6 | - * Time: 12:04 PM |
|
| 7 | - */ |
|
| 3 | + * Created by PhpStorm. |
|
| 4 | + * User: Chris |
|
| 5 | + * Date: 4/12/2014 |
|
| 6 | + * Time: 12:04 PM |
|
| 7 | + */ |
|
| 8 | 8 | namespace Seufert\Hamle\Text; |
| 9 | 9 | |
| 10 | 10 | use Seufert\Hamle\Text; |
@@ -23,8 +23,9 @@ |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | function toHTML($escape = false) { |
| 26 | - if ($this->type == self::TOKEN_CODE) |
|
| 27 | - return $this->s; |
|
| 26 | + if ($this->type == self::TOKEN_CODE) { |
|
| 27 | + return $this->s; |
|
| 28 | + } |
|
| 28 | 29 | return htmlspecialchars($this->s); |
| 29 | 30 | } |
| 30 | 31 | } |
| 31 | 32 | \ No newline at end of file |
@@ -34,11 +34,11 @@ |
||
| 34 | 34 | * @param string $class Class name to be autoloaded |
| 35 | 35 | */ |
| 36 | 36 | spl_autoload_register(function($class) {
|
| 37 | - if(strpos($class, "Seufert\\Hamle\\") === 0) {
|
|
| 37 | + if (strpos($class, "Seufert\\Hamle\\") === 0) {
|
|
| 38 | 38 | $s = DIRECTORY_SEPARATOR; |
| 39 | - $class = str_replace("\\",$s,substr($class,14));
|
|
| 40 | - $path = __DIR__.$s."hamle".$s."$class.php"; |
|
| 41 | - if(is_file($path)) include_once($path); |
|
| 39 | + $class = str_replace("\\", $s, substr($class, 14));
|
|
| 40 | + $path = __DIR__ . $s . "hamle" . $s . "$class.php"; |
|
| 41 | + if (is_file($path)) include_once($path); |
|
| 42 | 42 | } |
| 43 | -},true,true); |
|
| 43 | +},true, true); |
|
| 44 | 44 | |
@@ -38,7 +38,9 @@ |
||
| 38 | 38 | $s = DIRECTORY_SEPARATOR; |
| 39 | 39 | $class = str_replace("\\",$s,substr($class,14));
|
| 40 | 40 | $path = __DIR__.$s."hamle".$s."$class.php"; |
| 41 | - if(is_file($path)) include_once($path); |
|
| 41 | + if(is_file($path)) { |
|
| 42 | + include_once($path); |
|
| 43 | + } |
|
| 42 | 44 | } |
| 43 | 45 | },true,true); |
| 44 | 46 | |
@@ -34,14 +34,18 @@ |
||
| 34 | 34 | static function filterText($s) { |
| 35 | 35 | $as = explode("\n", $s); |
| 36 | 36 | $indent = -1; |
| 37 | - foreach ($as as $line) |
|
| 38 | - if (preg_match('/^(\s+).*$/', $line, $m)) { |
|
| 37 | + foreach ($as as $line) { |
|
| 38 | + if (preg_match('/^(\s+).*$/', $line, $m)) { |
|
| 39 | 39 | $lnInd = strlen($m[1]); |
| 40 | - if ($indent < 0) $indent = $lnInd; |
|
| 40 | + } |
|
| 41 | + if ($indent < 0) { |
|
| 42 | + $indent = $lnInd; |
|
| 43 | + } |
|
| 41 | 44 | $indent = min($indent, $lnInd); |
| 42 | 45 | } |
| 43 | - foreach ($as as $k => $v) |
|
| 44 | - $as[$k] = substr($v, $indent); |
|
| 46 | + foreach ($as as $k => $v) { |
|
| 47 | + $as[$k] = substr($v, $indent); |
|
| 48 | + } |
|
| 45 | 49 | $s = implode("\n", $as); |
| 46 | 50 | |
| 47 | 51 | require_once ME_DIR . "/lib/phpsass/SassParser.php"; |
@@ -53,39 +53,48 @@ discard block |
||
| 53 | 53 | $pos = 0; |
| 54 | 54 | $this->nodes = array(); |
| 55 | 55 | $rFlag = PREG_OFFSET_CAPTURE + PREG_SET_ORDER; |
| 56 | - if (strlen(trim($s)) == 0) return; |
|
| 56 | + if (strlen(trim($s)) == 0) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 57 | 59 | if ($mode == self::TOKEN_CONTROL) { |
| 58 | 60 | if (preg_match('/^"(.*)"$/', trim($s), $m)) { |
| 59 | 61 | $this->nodes[] = new Text($m[1]); |
| 60 | - } else |
|
| 61 | - $this->nodes[] = new Text\Complex(trim($s)); |
|
| 62 | + } else { |
|
| 63 | + $this->nodes[] = new Text\Complex(trim($s)); |
|
| 64 | + } |
|
| 62 | 65 | return; |
| 63 | 66 | } |
| 64 | 67 | preg_match_all(self::REGEX_HTML, $s, $m, $rFlag); |
| 65 | 68 | foreach ($m as $match) { |
| 66 | 69 | if ($mode & self::FIND_BARDOLLAR && isset($match[2])) { |
| 67 | - if ($match[2][1] != $pos) |
|
| 68 | - $this->nodes[] = new Text\Plain( |
|
| 70 | + if ($match[2][1] != $pos) { |
|
| 71 | + $this->nodes[] = new Text\Plain( |
|
| 69 | 72 | substr($s, $pos, $match[2][1] - $pos), $mode); |
| 73 | + } |
|
| 70 | 74 | $this->nodes[] = new Text\Complex(substr($match[2][0], 1, -1)); |
| 71 | 75 | $pos = $match[2][1] + strlen($match[2][0]); |
| 72 | 76 | } elseif ($mode & self::FIND_DOLLARVAR) { |
| 73 | - if ($match[1][1] > 0 && $s[$match[1][1] - 1] == '\\') continue; |
|
| 74 | - if ($match[1][1] != $pos) |
|
| 75 | - $this->nodes[] = new Text\Plain( |
|
| 77 | + if ($match[1][1] > 0 && $s[$match[1][1] - 1] == '\\') { |
|
| 78 | + continue; |
|
| 79 | + } |
|
| 80 | + if ($match[1][1] != $pos) { |
|
| 81 | + $this->nodes[] = new Text\Plain( |
|
| 76 | 82 | substr($s, $pos, $match[1][1] - $pos), $mode); |
| 83 | + } |
|
| 77 | 84 | $this->nodes[] = new Text\SimpleVar($match[1][0]); |
| 78 | 85 | $pos = $match[1][1] + strlen($match[1][0]); |
| 79 | 86 | } |
| 80 | 87 | } |
| 81 | - if ($pos != strlen($s)) |
|
| 82 | - $this->nodes[] = new Text\Plain(substr($s, $pos), $mode); |
|
| 88 | + if ($pos != strlen($s)) { |
|
| 89 | + $this->nodes[] = new Text\Plain(substr($s, $pos), $mode); |
|
| 90 | + } |
|
| 83 | 91 | } |
| 84 | 92 | |
| 85 | 93 | function toHTML($escape = false) { |
| 86 | 94 | $out = array(); |
| 87 | - foreach ($this->nodes as $string) |
|
| 88 | - $out[] = $string->toHTML($escape); |
|
| 95 | + foreach ($this->nodes as $string) { |
|
| 96 | + $out[] = $string->toHTML($escape); |
|
| 97 | + } |
|
| 89 | 98 | return implode("", $out); |
| 90 | 99 | } |
| 91 | 100 | |
@@ -95,8 +104,9 @@ discard block |
||
| 95 | 104 | |
| 96 | 105 | function toPHP() { |
| 97 | 106 | $out = array(); |
| 98 | - foreach ($this->nodes as $string) |
|
| 99 | - $out[] = $string->toPHP(); |
|
| 107 | + foreach ($this->nodes as $string) { |
|
| 108 | + $out[] = $string->toPHP(); |
|
| 109 | + } |
|
| 100 | 110 | return implode(".", $out); |
| 101 | 111 | } |
| 102 | 112 | |
@@ -107,8 +117,9 @@ discard block |
||
| 107 | 117 | static function varToCode($var) { |
| 108 | 118 | if (is_array($var)) { |
| 109 | 119 | $code = array(); |
| 110 | - foreach ($var as $key => $value) |
|
| 111 | - $code[] = self::varToCode($key) . "=>" . self::varToCode($value); |
|
| 120 | + foreach ($var as $key => $value) { |
|
| 121 | + $code[] = self::varToCode($key) . "=>" . self::varToCode($value); |
|
| 122 | + } |
|
| 112 | 123 | return 'array(' . implode(",", $code) . ')'; //remove unnecessary coma |
| 113 | 124 | } elseif (is_bool($var)) { |
| 114 | 125 | return ($var ? 'TRUE' : 'FALSE'); |
@@ -42,17 +42,17 @@ |
||
| 42 | 42 | function __construct($tag, $class = array(), $attr = array(), $id = "") { |
| 43 | 43 | parent::__construct(); |
| 44 | 44 | $this->opt = $attr; |
| 45 | - if(isset($attr['class']) && !is_array($attr['class'])) |
|
| 46 | - $this->opt['class'] = $attr['class']?explode(" ",$attr['class']):array(); |
|
| 45 | + if (isset($attr['class']) && !is_array($attr['class'])) |
|
| 46 | + $this->opt['class'] = $attr['class'] ? explode(" ", $attr['class']) : array(); |
|
| 47 | 47 | $this->source = array(); |
| 48 | 48 | $this->type = $tag ? $tag : "div"; |
| 49 | - if($class) { |
|
| 49 | + if ($class) { |
|
| 50 | 50 | if (isset($this->opt['class'])) |
| 51 | 51 | $this->opt['class'] = array_merge($this->opt['class'], $class); |
| 52 | 52 | else |
| 53 | 53 | $this->opt['class'] = $class; |
| 54 | 54 | } |
| 55 | - if($id) $this->opt['id'] = $id; |
|
| 55 | + if ($id) $this->opt['id'] = $id; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function renderStTag() { |
@@ -42,17 +42,21 @@ discard block |
||
| 42 | 42 | function __construct($tag, $class = array(), $attr = array(), $id = "") { |
| 43 | 43 | parent::__construct(); |
| 44 | 44 | $this->opt = $attr; |
| 45 | - if(isset($attr['class']) && !is_array($attr['class'])) |
|
| 46 | - $this->opt['class'] = $attr['class']?explode(" ",$attr['class']):array(); |
|
| 45 | + if(isset($attr['class']) && !is_array($attr['class'])) { |
|
| 46 | + $this->opt['class'] = $attr['class']?explode(" ",$attr['class']):array(); |
|
| 47 | + } |
|
| 47 | 48 | $this->source = array(); |
| 48 | 49 | $this->type = $tag ? $tag : "div"; |
| 49 | 50 | if($class) { |
| 50 | - if (isset($this->opt['class'])) |
|
| 51 | - $this->opt['class'] = array_merge($this->opt['class'], $class); |
|
| 52 | - else |
|
| 53 | - $this->opt['class'] = $class; |
|
| 51 | + if (isset($this->opt['class'])) { |
|
| 52 | + $this->opt['class'] = array_merge($this->opt['class'], $class); |
|
| 53 | + } else { |
|
| 54 | + $this->opt['class'] = $class; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + if($id) { |
|
| 58 | + $this->opt['id'] = $id; |
|
| 54 | 59 | } |
| 55 | - if($id) $this->opt['id'] = $id; |
|
| 56 | 60 | } |
| 57 | 61 | |
| 58 | 62 | function renderStTag() { |
@@ -61,8 +65,9 @@ discard block |
||
| 61 | 65 | } |
| 62 | 66 | |
| 63 | 67 | function renderEnTag() { |
| 64 | - if (in_array($this->type, self::$selfCloseTags)) |
|
| 65 | - return ""; |
|
| 68 | + if (in_array($this->type, self::$selfCloseTags)) { |
|
| 69 | + return ""; |
|
| 70 | + } |
|
| 66 | 71 | return "</{$this->type}>"; |
| 67 | 72 | } |
| 68 | 73 | |
@@ -74,10 +79,15 @@ discard block |
||
| 74 | 79 | function optToTags() { |
| 75 | 80 | $out = array(); |
| 76 | 81 | foreach ($this->opt as $k => $v) { |
| 77 | - if ($k == "class" && !$v) continue; |
|
| 78 | - if (is_array($v)) $v = implode(" ", $v); |
|
| 79 | - if (!$v instanceof H\Text) |
|
| 80 | - $v = new H\Text($v); |
|
| 82 | + if ($k == "class" && !$v) { |
|
| 83 | + continue; |
|
| 84 | + } |
|
| 85 | + if (is_array($v)) { |
|
| 86 | + $v = implode(" ", $v); |
|
| 87 | + } |
|
| 88 | + if (!$v instanceof H\Text) { |
|
| 89 | + $v = new H\Text($v); |
|
| 90 | + } |
|
| 81 | 91 | $k = new H\Text($k); |
| 82 | 92 | $out[] = " " . $k->toHTML() . "=\"" . $v->toHTMLAtt() . "\""; |
| 83 | 93 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * Fills the $this->fields array with hamleFields |
| 45 | 45 | */ |
| 46 | 46 | function setup() {
|
| 47 | - throw new Exception\RunTime("You must configure the form in the setup ".
|
|
| 47 | + throw new Exception\RunTime("You must configure the form in the setup " .
|
|
| 48 | 48 | "function, by adding fields to the \$this->fields array"); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $this->setup(); |
| 55 | 55 | $fields = $this->_fields; |
| 56 | 56 | $this->_fields = array(); |
| 57 | - foreach($fields as $v) {
|
|
| 57 | + foreach ($fields as $v) {
|
|
| 58 | 58 | $this->_fields[$v->name] = $v; |
| 59 | 59 | $v->form($this->_name); |
| 60 | 60 | } |
@@ -64,23 +64,23 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | function process() {
|
| 66 | 66 | $clicked = ""; |
| 67 | - foreach($this->_fields as $f) |
|
| 68 | - if($f instanceOf Field\Button) |
|
| 69 | - if($f->isClicked()) |
|
| 67 | + foreach ($this->_fields as $f) |
|
| 68 | + if ($f instanceOf Field\Button) |
|
| 69 | + if ($f->isClicked()) |
|
| 70 | 70 | $clicked = $f; |
| 71 | - foreach($this->_fields as $f) |
|
| 72 | - $f->doProcess($clicked?true:false); |
|
| 73 | - if($clicked) |
|
| 71 | + foreach ($this->_fields as $f) |
|
| 72 | + $f->doProcess($clicked ? true : false); |
|
| 73 | + if ($clicked) |
|
| 74 | 74 | try {
|
| 75 | 75 | $this->onSubmit($clicked); |
| 76 | - } catch(Exception\FormInvalid $e) {
|
|
| 76 | + } catch (Exception\FormInvalid $e) {
|
|
| 77 | 77 | $this->hint = $e->getMessage(); |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | function isValid() {
|
| 82 | 82 | $valid = true; |
| 83 | - foreach($this->_fields as $f) |
|
| 83 | + foreach ($this->_fields as $f) |
|
| 84 | 84 | $valid = $f->valid && $valid; |
| 85 | 85 | return $valid; |
| 86 | 86 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | return $this->_fields; |
| 96 | 96 | } |
| 97 | 97 | function getField($n) {
|
| 98 | - if(!isset($this->_fields[$n])) |
|
| 98 | + if (!isset($this->_fields[$n])) |
|
| 99 | 99 | throw new Exception\NoKey("unable to find form field ($n)");
|
| 100 | 100 | return $this->_fields[$n]; |
| 101 | 101 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function getHTMLProp() {
|
| 107 | - return array('action'=>'','method'=>'post','name'=>$this->_name,
|
|
| 107 | + return array('action'=>'', 'method'=>'post', 'name'=>$this->_name,
|
|
| 108 | 108 | 'enctype'=>'multipart/form-data'); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -64,15 +64,18 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | function process() {
|
| 66 | 66 | $clicked = ""; |
| 67 | - foreach($this->_fields as $f) |
|
| 68 | - if($f instanceOf Field\Button) |
|
| 67 | + foreach($this->_fields as $f) { |
|
| 68 | + if($f instanceOf Field\Button) |
|
| 69 | 69 | if($f->isClicked()) |
| 70 | - $clicked = $f; |
|
| 71 | - foreach($this->_fields as $f) |
|
| 72 | - $f->doProcess($clicked?true:false); |
|
| 73 | - if($clicked) |
|
| 74 | - try {
|
|
| 75 | - $this->onSubmit($clicked); |
|
| 70 | + $clicked = $f; |
|
| 71 | + } |
|
| 72 | + foreach($this->_fields as $f) { |
|
| 73 | + $f->doProcess($clicked?true:false); |
|
| 74 | + } |
|
| 75 | + if($clicked) { |
|
| 76 | + try {
|
|
| 77 | + $this->onSubmit($clicked); |
|
| 78 | + } |
|
| 76 | 79 | } catch(Exception\FormInvalid $e) {
|
| 77 | 80 | $this->hint = $e->getMessage(); |
| 78 | 81 | } |
@@ -80,8 +83,9 @@ discard block |
||
| 80 | 83 | |
| 81 | 84 | function isValid() {
|
| 82 | 85 | $valid = true; |
| 83 | - foreach($this->_fields as $f) |
|
| 84 | - $valid = $f->valid && $valid; |
|
| 86 | + foreach($this->_fields as $f) { |
|
| 87 | + $valid = $f->valid && $valid; |
|
| 88 | + } |
|
| 85 | 89 | return $valid; |
| 86 | 90 | } |
| 87 | 91 | /** |
@@ -95,8 +99,9 @@ discard block |
||
| 95 | 99 | return $this->_fields; |
| 96 | 100 | } |
| 97 | 101 | function getField($n) {
|
| 98 | - if(!isset($this->_fields[$n])) |
|
| 99 | - throw new Exception\NoKey("unable to find form field ($n)");
|
|
| 102 | + if(!isset($this->_fields[$n])) { |
|
| 103 | + throw new Exception\NoKey("unable to find form field ($n)"); |
|
| 104 | + } |
|
| 100 | 105 | return $this->_fields[$n]; |
| 101 | 106 | } |
| 102 | 107 | function __get($n) {
|
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | |
| 34 | 34 | function __construct($s) { |
| 35 | 35 | $m = array(); |
| 36 | - if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) |
|
| 36 | + if (!preg_match('/^ +([><]) +(' . self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) |
|
| 37 | 37 | throw new ParseError("Unable to read \$ sub func in '$s'"); |
| 38 | 38 | if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT; |
| 39 | 39 | elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD; |
@@ -33,17 +33,25 @@ |
||
| 33 | 33 | |
| 34 | 34 | function __construct($s) { |
| 35 | 35 | $m = array(); |
| 36 | - if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) |
|
| 37 | - throw new ParseError("Unable to read \$ sub func in '$s'"); |
|
| 38 | - if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT; |
|
| 39 | - elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD; |
|
| 40 | - else $this->dir = Hamle\Hamle::REL_ANY; |
|
| 36 | + if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) { |
|
| 37 | + throw new ParseError("Unable to read \$ sub func in '$s'"); |
|
| 38 | + } |
|
| 39 | + if ($m[1] == "<") { |
|
| 40 | + $this->dir = Hamle\Hamle::REL_PARENT; |
|
| 41 | + } elseif ($m[1] == ">") { |
|
| 42 | + $this->dir = Hamle\Hamle::REL_CHILD; |
|
| 43 | + } else { |
|
| 44 | + $this->dir = Hamle\Hamle::REL_ANY; |
|
| 45 | + } |
|
| 41 | 46 | $this->sortlimit = $this->attSortLimit($m[2]); |
| 42 | 47 | $this->filt = $this->attIdTag($m[2]); |
| 43 | 48 | $this->grouptype = $this->attGroupType($m[2]); |
| 44 | - if ($this->filt['id']) throw new ParseError("Unable to select by id"); |
|
| 45 | - if (trim($m[3])) |
|
| 46 | - $this->sub = new FuncSub($m[3]); |
|
| 49 | + if ($this->filt['id']) { |
|
| 50 | + throw new ParseError("Unable to select by id"); |
|
| 51 | + } |
|
| 52 | + if (trim($m[3])) { |
|
| 53 | + $this->sub = new FuncSub($m[3]); |
|
| 54 | + } |
|
| 47 | 55 | } |
| 48 | 56 | |
| 49 | 57 | function toPHP() { |
@@ -34,9 +34,9 @@ discard block |
||
| 34 | 34 | protected $filter; |
| 35 | 35 | |
| 36 | 36 | function __construct($s) { |
| 37 | - if(FALSE !== $pos = strpos($s,'|')) { |
|
| 38 | - $this->filter = new Filter(substr($s, $pos+1), $this); |
|
| 39 | - $s = substr($s,0,$pos); |
|
| 37 | + if (FALSE !== $pos = strpos($s, '|')) { |
|
| 38 | + $this->filter = new Filter(substr($s, $pos + 1), $this); |
|
| 39 | + $s = substr($s, 0, $pos); |
|
| 40 | 40 | } |
| 41 | 41 | $s = explode("->", $s); |
| 42 | 42 | if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
@@ -51,12 +51,12 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | function toHTML($escape = false) { |
| 54 | - if($escape) |
|
| 55 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 54 | + if ($escape) |
|
| 55 | + return "<?=htmlspecialchars(" . $this->toPHP() . ")?>"; |
|
| 56 | 56 | return "<?=" . $this->toPHP() . "?>"; |
| 57 | 57 | } |
| 58 | 58 | function toPHP() { |
| 59 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
| 59 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
| 60 | 60 | } |
| 61 | 61 | function toPHPVar() { |
| 62 | 62 | if ($this->sel) { |
@@ -39,20 +39,24 @@ discard block |
||
| 39 | 39 | $s = substr($s,0,$pos); |
| 40 | 40 | } |
| 41 | 41 | $s = explode("->", $s); |
| 42 | - if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
|
| 43 | - if ($s[0][1] == "(") |
|
| 44 | - $this->func = new Text\Func($s[0]); |
|
| 45 | - elseif ($s[0][1] == "[") |
|
| 46 | - $this->func = new Text\Scope($s[0]); |
|
| 47 | - else |
|
| 48 | - $this->func = new SimpleVar($s[0]); |
|
| 42 | + if (!$s[0]) { |
|
| 43 | + throw new ParseError("Unable to parse Complex Expression"); |
|
| 44 | + } |
|
| 45 | + if ($s[0][1] == "(") { |
|
| 46 | + $this->func = new Text\Func($s[0]); |
|
| 47 | + } elseif ($s[0][1] == "[") { |
|
| 48 | + $this->func = new Text\Scope($s[0]); |
|
| 49 | + } else { |
|
| 50 | + $this->func = new SimpleVar($s[0]); |
|
| 51 | + } |
|
| 49 | 52 | array_shift($s); |
| 50 | 53 | $this->sel = $s; |
| 51 | 54 | } |
| 52 | 55 | |
| 53 | 56 | function toHTML($escape = false) { |
| 54 | - if($escape) |
|
| 55 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 57 | + if($escape) { |
|
| 58 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 59 | + } |
|
| 56 | 60 | return "<?=" . $this->toPHP() . "?>"; |
| 57 | 61 | } |
| 58 | 62 | function toPHP() { |
@@ -61,11 +65,13 @@ discard block |
||
| 61 | 65 | function toPHPVar() { |
| 62 | 66 | if ($this->sel) { |
| 63 | 67 | $sel = array(); |
| 64 | - foreach ($this->sel as $s) |
|
| 65 | - $sel[] = "hamleGet('$s')"; |
|
| 68 | + foreach ($this->sel as $s) { |
|
| 69 | + $sel[] = "hamleGet('$s')"; |
|
| 70 | + } |
|
| 66 | 71 | return $this->func->toPHP() . "->" . implode('->', $sel); |
| 67 | - } else |
|
| 68 | - return $this->func->toPHP(); |
|
| 72 | + } else { |
|
| 73 | + return $this->func->toPHP(); |
|
| 74 | + } |
|
| 69 | 75 | } |
| 70 | 76 | |
| 71 | 77 | } |
| 72 | 78 | \ No newline at end of file |
@@ -13,6 +13,9 @@ |
||
| 13 | 13 | protected $s; |
| 14 | 14 | protected $type; |
| 15 | 15 | |
| 16 | + /** |
|
| 17 | + * @param string $s |
|
| 18 | + */ |
|
| 16 | 19 | function __construct($s, $type = self::TOKEN_HTML) { |
| 17 | 20 | $this->s = str_replace('\\$', "$", $s); |
| 18 | 21 | $this->type = $type; |