File tree Expand file tree Collapse file tree 7 files changed +70
-0
lines changed
src/JsPhpize/Compiler/Helpers Expand file tree Collapse file tree 7 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,17 @@ if (!class_exists('JsPhpizeDotCarrier')) {
164
164
return (string) $this ->getValue ();
165
165
}
166
166
167
+ public function __toBoolean ()
168
+ {
169
+ $value = $this ->getValue ();
170
+
171
+ if (method_exists ($value, ' __toBoolean' )) {
172
+ return $value->__toBoolean ();
173
+ }
174
+
175
+ return !!$value;
176
+ }
177
+
167
178
public function __invoke (...$arguments)
168
179
{
169
180
return call_user_func_array ($this ->getCallable (), $arguments);
Original file line number Diff line number Diff line change @@ -167,6 +167,17 @@ if (!class_exists('JsPhpizeDotCarrier')) {
167
167
return (string) $this ->getValue ();
168
168
}
169
169
170
+ public function __toBoolean ()
171
+ {
172
+ $value = $this ->getValue ();
173
+
174
+ if (method_exists ($value, ' __toBoolean' )) {
175
+ return $value->__toBoolean ();
176
+ }
177
+
178
+ return !!$value;
179
+ }
180
+
170
181
public function __invoke (...$arguments)
171
182
{
172
183
return call_user_func_array ($this ->getCallable (), $arguments);
Original file line number Diff line number Diff line change @@ -161,6 +161,17 @@ if (!class_exists('JsPhpizeDotCarrier')) {
161
161
return (string) $this ->getValue ();
162
162
}
163
163
164
+ public function __toBoolean ()
165
+ {
166
+ $value = $this ->getValue ();
167
+
168
+ if (method_exists ($value, ' __toBoolean' )) {
169
+ return $value->__toBoolean ();
170
+ }
171
+
172
+ return !!$value;
173
+ }
174
+
164
175
public function __invoke (...$arguments)
165
176
{
166
177
return call_user_func_array ($this ->getCallable (), $arguments);
Original file line number Diff line number Diff line change @@ -164,6 +164,17 @@ if (!class_exists('JsPhpizeDotCarrier')) {
164
164
return (string) $this ->getValue ();
165
165
}
166
166
167
+ public function __toBoolean ()
168
+ {
169
+ $value = $this ->getValue ();
170
+
171
+ if (method_exists ($value, ' __toBoolean' )) {
172
+ return $value->__toBoolean ();
173
+ }
174
+
175
+ return !!$value;
176
+ }
177
+
167
178
public function __invoke (...$arguments)
168
179
{
169
180
return call_user_func_array ($this ->getCallable (), $arguments);
Original file line number Diff line number Diff line change @@ -243,6 +243,17 @@ if (!class_exists('JsPhpizeDotCarrier')) {
243
243
return (string) $this ->getValue ();
244
244
}
245
245
246
+ public function __toBoolean ()
247
+ {
248
+ $value = $this ->getValue ();
249
+
250
+ if (method_exists ($value, ' __toBoolean' )) {
251
+ return $value->__toBoolean ();
252
+ }
253
+
254
+ return !!$value;
255
+ }
256
+
246
257
public function __invoke (...$arguments)
247
258
{
248
259
return call_user_func_array ($this ->getCallable (), $arguments);
Original file line number Diff line number Diff line change @@ -246,6 +246,17 @@ if (!class_exists('JsPhpizeDotCarrier')) {
246
246
return (string) $this ->getValue ();
247
247
}
248
248
249
+ public function __toBoolean ()
250
+ {
251
+ $value = $this ->getValue ();
252
+
253
+ if (method_exists ($value, ' __toBoolean' )) {
254
+ return $value->__toBoolean ();
255
+ }
256
+
257
+ return !!$value;
258
+ }
259
+
249
260
public function __invoke (...$arguments)
250
261
{
251
262
return call_user_func_array ($this ->getCallable (), $arguments);
Original file line number Diff line number Diff line change @@ -112,15 +112,19 @@ public function __get($name)
112
112
113
113
$ result = $ jsPhpize ->renderCode ('return obj.prop ' , $ data );
114
114
$ this ->assertSame ('' , (string ) $ result );
115
+ $ this ->assertFalse ($ result ->__toBoolean ());
115
116
116
117
$ result = $ jsPhpize ->renderCode ('return obj.other ' , $ data );
117
118
$ this ->assertSame ('else ' , (string ) $ result );
119
+ $ this ->assertTrue ($ result ->__toBoolean ());
118
120
119
121
$ result = $ jsPhpize ->renderCode ('return obj.objectData.foo ' , $ data );
120
122
$ this ->assertSame ('o-bar ' , (string ) $ result );
123
+ $ this ->assertTrue ($ result ->__toBoolean ());
121
124
122
125
$ result = $ jsPhpize ->renderCode ('return obj.arrayData.foo ' , $ data );
123
126
$ this ->assertSame ('a-bar ' , (string ) $ result );
127
+ $ this ->assertTrue ($ result ->__toBoolean ());
124
128
}
125
129
126
130
public function testDollarVariablePrefix ()
You can’t perform that action at this time.
0 commit comments