Skip to content

Commit

Permalink
- 2020-04-21 3.39
Browse files Browse the repository at this point in the history
    * fix method isQuoted() when the string is fewer than 2 chars.
    * new method isVariablePHP()
  • Loading branch information
jorgecc committed Apr 21, 2020
1 parent c5ffacf commit d4b0574
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,34 @@ $obj=new BladeOne();
$url=$obj->addAssetDict('css/style.css','http://....');
```

## Util methods

It is a collection of methods not used directly by the end user but used in some functionalities.

### stripQuotes

Return true if the string is a php variable (it starts with $)

### addInsideQuote

Execute the user defined extensions.

### isQuoted

Returns true if the text is surrounded by quotes (double or single quote)

### isVariablePHP

Return true if the string is a php variable (it starts with $)

### stripParentheses

Strip the parentheses from the given expression.

### startsWith

Determine if a given string starts with a given substring.


## Extensions Libraries (optional)

Expand Down Expand Up @@ -1190,7 +1218,9 @@ You could download it or add it via Composer


## Version

- 2020-04-21 3.39
* fix method isQuoted() when the string is fewer than 2 chars.
* new method isVariablePHP()
- 2020-04-20 3.38.1
* fix in method parseArgs() when it returns a single array
- 2020-04-20 3.38
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "eftec/bladeone",
"description": "The standalone version Blade Template Engine from Laravel in a single php file",
"type": "library",
"version": "3.38.1",
"version": "3.39",
"keywords": [
"blade",
"template",
Expand Down
22 changes: 18 additions & 4 deletions lib/BladeOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @copyright Copyright (c) 2016-2019 Jorge Patricio Castro Castillo MIT License.
* Don't delete this comment, its part of the license.
* Part of this code is based in the work of Laravel PHP Components.
* @version 3.38.1
* @version 3.39
* @link https://github.com/EFTEC/BladeOne
*/
class BladeOne
Expand Down Expand Up @@ -1898,7 +1898,7 @@ public function stripQuotes($text)
* @param $newFragment
* @return string
*/
protected function addInsideQuote($quoted, $newFragment)
public function addInsideQuote($quoted, $newFragment)
{
if ($this->isQuoted($quoted)) {
return substr($quoted, 0, -1).$newFragment.substr($quoted, -1);
Expand All @@ -1908,7 +1908,7 @@ protected function addInsideQuote($quoted, $newFragment)
/**
* Returns true if the text is surrounded by quotes (double or single quote)
*
* @param $text
* @param string|null $text
* @return bool
*/
public function isQuoted($text)
Expand All @@ -1921,6 +1921,20 @@ public function isQuoted($text)
}
return (substr($text, 0, 1) === "'" && substr($text, -1) === "'");
}

/**
* Return true if the string is a php variable (it starts with $)
*
* @param string|null $text
* @return bool
*/
public function isVariablePHP($text)
{
if (!$text || strlen($text)<2) {
return false;
}
return substr($text, 0, 1) === '$';
}
/**
* Execute the user defined extensions.
*
Expand Down Expand Up @@ -2055,7 +2069,7 @@ protected function compileStatements($value)
}
return isset($match[3]) ? $match[0] : $match[0] . $match[2];
};
/* return \preg_replace_callback('/\B@(@?\w+)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', $callback, $value); */
/* return \preg_replace_callback('/\B@(@?\w+)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', $callback, $value); */
return preg_replace_callback('/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', $callback, $value);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/OtherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,20 @@ public function test2()


$this->assertEquals($compare, $arr);
$this->assertEquals(true, $this->blade->isQuoted("'aaa'"));
$this->assertEquals(false, $this->blade->isQuoted("aaa'"));
$this->assertEquals(true, $this->blade->isQuoted('"aaa"'));
$this->assertEquals(false, $this->blade->isQuoted(''));
$this->assertEquals(false, $this->blade->isQuoted('"'));
$this->assertEquals(false, $this->blade->isQuoted(null));
$this->assertEquals(false, $this->blade->isVariablePHP('aaa'));
$this->assertEquals(true, $this->blade->isVariablePHP('$aaa'));
$this->assertEquals(false, $this->blade->isVariablePHP(''));
$this->assertEquals(false, $this->blade->isVariablePHP(null));
$this->assertEquals(false, $this->blade->isVariablePHP('$'));
$this->assertEquals('"aaabcd"', $this->blade->addInsideQuote('"aaa"', "bcd"));
$this->assertEquals('aaa"bcd', $this->blade->addInsideQuote('aaa"', "bcd"));
$this->assertEquals('bcd', $this->blade->addInsideQuote('', "bcd"));
$this->assertEquals('"bcd"', $this->blade->addInsideQuote('""', "bcd"));
}
}

0 comments on commit d4b0574

Please sign in to comment.