diff --git a/PhpEcho.php b/PhpEcho.php index 723aa73..1a2ff0b 100644 --- a/PhpEcho.php +++ b/PhpEcho.php @@ -38,6 +38,13 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. + * + * + * @method mixed raw($p) Return the raw value from a PhpEcho block + * @method mixed hsc($p) Escape the value in parameter (scalar, array, stringifyable) + * @method bool isScalar($p) + * @method string selected($p, $ref) Return " selected " if $p == $ref + * @method string checked($p, $ref) Return " checked " if $p == $ref */ class PhpEcho implements ArrayAccess @@ -220,9 +227,6 @@ public function setCode(string $code) public function __invoke(string $helper, ...$args) { if ($helper !== '') { - if ( ! empty(self::$helpers_file_to_inject)) { - self::injectHelpers(); - } if (self::isHelper($helper)) { if (empty($this->bound_helpers)) { $this->bound_helpers = self::bindHelpersTo($this); @@ -243,6 +247,21 @@ public function __invoke(string $helper, ...$args) return null; } + /** + * @param $name + * @param $arguments + */ + public function __call($name, $arguments) + { + if (self::isHelper($name)) { + return $this->__invoke($name, ...$arguments); + } elseif (self::isHelper('$'.$name)) { + return $this->__invoke('$'.$name, ...$arguments); + } else { + return null; + } + } + /** * Magic method that returns a string instead of current instance of the class in a string context */ @@ -354,7 +373,12 @@ public static function getHelperTypes(string $helper_name): array */ public static function isHelper(string $helper_name): bool { - return isset(self::$helpers[$helper_name]); + if (isset(self::$helpers[$helper_name])) { + return true; + } else { + self::injectHelpers(); + return isset(self::$helpers[$helper_name]); + } } /** diff --git a/stdHelpers.php b/stdHelpers.php index ff81836..1b7c7c7 100644 --- a/stdHelpers.php +++ b/stdHelpers.php @@ -29,6 +29,7 @@ return is_scalar($p) || (is_object($p) && method_exists($p, '__toString')); }; $helpers['$is_scalar'] = [$is_scalar, HELPER_RETURN_ESCAPED_DATA]; +$helpers['isScalar'] = $helpers['$is_scalar']; // alias for method call /**