openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 62a4e7aeac4519ca018a276acb769fc2170dc731
parent c3abad3747ecad38601e9f7c8e452dd7cdfe7a69
Author: Jan Dankert <develop@jandankert.de>
Date:   Fri,  1 Jul 2022 18:26:28 +0200

New: length properties for DSL objects; support for float values.

Diffstat:
Mmodules/dsl/ast/DslExpression.class.php | 4++++
Mmodules/dsl/standard/Number.class.php | 8++++++--
Mmodules/dsl/standard/StandardArray.class.php | 3+++
Mmodules/dsl/standard/StandardString.class.php | 8+++++---
4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/modules/dsl/ast/DslExpression.class.php b/modules/dsl/ast/DslExpression.class.php @@ -262,6 +262,10 @@ class DslExpression extends DslElement implements DslStatement return new Number($value); } + elseif ( is_float( $value ) ) { + + return new Number($value); + } elseif ( is_string( $value ) ) { return new StandardString($value); diff --git a/modules/dsl/standard/Number.class.php b/modules/dsl/standard/Number.class.php @@ -32,11 +32,15 @@ class Number extends BaseScriptableObject { return new Number( $value ); } - public function parseFloat() + + public function parseFloat( $num ) { + return floatval($num ); } - public function parseInt() + + public function parseInt( $num ) { + return intval($num); } public function toFixed( $digits ) diff --git a/modules/dsl/standard/StandardArray.class.php b/modules/dsl/standard/StandardArray.class.php @@ -6,6 +6,7 @@ use dsl\context\BaseScriptableObject; class StandardArray extends BaseScriptableObject { private $value; + public $length = 0; /** * StandardArray constructor. @@ -14,6 +15,8 @@ class StandardArray extends BaseScriptableObject public function __construct($value=null) { $this->value = $value; + if ( $value ) + $this->length = sizeof( $this->value ); } diff --git a/modules/dsl/standard/StandardString.class.php b/modules/dsl/standard/StandardString.class.php @@ -27,6 +27,8 @@ class StandardString extends BaseScriptableObject elseif ( is_callable( $value ) ) $this->value = 'function'; + elseif ( is_bool( $value ) ) + $this->value = $value ? 'true' : 'false'; else $this->value = (string) $value; @@ -131,8 +133,8 @@ class StandardString extends BaseScriptableObject return strtoupper($this->value); } - public function length() { - return strlen($this->value); - } +// public function length() { +// return strlen($this->value); +// } } \ No newline at end of file