9
9
// See the Mulan PSL v2 for more details.
10
10
11
11
use phper:: {
12
+ arrays:: ZArray ,
12
13
classes:: { ClassEntity , Interface , InterfaceEntity , StateClass , Visibility } ,
13
14
functions:: { Argument , ReturnType } ,
14
15
modules:: Module ,
15
16
types:: { ArgumentTypeHint , ReturnTypeHint } ,
16
17
values:: ZVal ,
17
18
} ;
19
+ use std:: convert:: Infallible ;
18
20
19
21
const I_FOO : & str = r"IntegrationTest\TypeHints\IFoo" ;
20
22
@@ -26,6 +28,45 @@ pub fn integrate(module: &mut Module) {
26
28
module. add_class ( make_arg_typehint_class ( ) ) ;
27
29
module. add_class ( make_return_typehint_class ( ) ) ;
28
30
module. add_class ( make_arg_default_value_class ( ) ) ;
31
+ module
32
+ . add_function (
33
+ "integration_function_return_bool" ,
34
+ |_| -> Result < bool , Infallible > { Ok ( true ) } ,
35
+ )
36
+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Bool ) ) ;
37
+ module
38
+ . add_function (
39
+ "integration_function_return_int" ,
40
+ |_| -> Result < i64 , Infallible > { Ok ( 42 ) } ,
41
+ )
42
+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Int ) ) ;
43
+ module
44
+ . add_function (
45
+ "integration_function_return_float" ,
46
+ |_| -> Result < f64 , Infallible > { Ok ( 1.234 ) } ,
47
+ )
48
+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Float ) ) ;
49
+ module
50
+ . add_function (
51
+ "integration_function_return_string" ,
52
+ |_| -> Result < & ' static str , Infallible > { Ok ( "phper" ) } ,
53
+ )
54
+ . return_type ( ReturnType :: new ( ReturnTypeHint :: String ) ) ;
55
+ module
56
+ . add_function (
57
+ "integration_function_return_array" ,
58
+ |_| -> Result < ZArray , Infallible > { Ok ( ZArray :: new ( ) ) } ,
59
+ )
60
+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Array ) ) ;
61
+ module
62
+ . add_function (
63
+ "integration_function_return_mixed" ,
64
+ |_| -> Result < ZVal , Infallible > { Ok ( ZVal :: from ( 1.23 ) ) } ,
65
+ )
66
+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Mixed ) ) ;
67
+ module
68
+ . add_function ( "integration_function_return_void" , |_| phper:: ok ( ( ) ) )
69
+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Void ) ) ;
29
70
module
30
71
. add_function ( "integration_function_typehints" , |_| phper:: ok ( ( ) ) )
31
72
. argument (
@@ -455,11 +496,9 @@ fn make_return_typehint_class() -> ClassEntity<()> {
455
496
. return_type ( ReturnType :: new ( ReturnTypeHint :: Null ) ) ;
456
497
457
498
class
458
- . add_method (
459
- "returnString" ,
460
- Visibility :: Public ,
461
- move |_, _| phper:: ok ( ( ) ) ,
462
- )
499
+ . add_method ( "returnString" , Visibility :: Public , move |_, _| {
500
+ phper:: ok ( "phper" )
501
+ } )
463
502
. return_type ( ReturnType :: new ( ReturnTypeHint :: String ) ) ;
464
503
465
504
class
@@ -469,7 +508,9 @@ fn make_return_typehint_class() -> ClassEntity<()> {
469
508
. return_type ( ReturnType :: new ( ReturnTypeHint :: String ) . allow_null ( ) ) ;
470
509
471
510
class
472
- . add_method ( "returnBool" , Visibility :: Public , move |_, _| phper:: ok ( ( ) ) )
511
+ . add_method ( "returnBool" , Visibility :: Public , move |_, _| {
512
+ phper:: ok ( true )
513
+ } )
473
514
. return_type ( ReturnType :: new ( ReturnTypeHint :: Bool ) ) ;
474
515
475
516
class
@@ -479,7 +520,7 @@ fn make_return_typehint_class() -> ClassEntity<()> {
479
520
. return_type ( ReturnType :: new ( ReturnTypeHint :: Bool ) . allow_null ( ) ) ;
480
521
481
522
class
482
- . add_method ( "returnInt" , Visibility :: Public , move |_, _| phper:: ok ( ( ) ) )
523
+ . add_method ( "returnInt" , Visibility :: Public , move |_, _| phper:: ok ( 42 ) )
483
524
. return_type ( ReturnType :: new ( ReturnTypeHint :: Int ) ) ;
484
525
485
526
class
@@ -489,7 +530,9 @@ fn make_return_typehint_class() -> ClassEntity<()> {
489
530
. return_type ( ReturnType :: new ( ReturnTypeHint :: Int ) . allow_null ( ) ) ;
490
531
491
532
class
492
- . add_method ( "returnFloat" , Visibility :: Public , move |_, _| phper:: ok ( ( ) ) )
533
+ . add_method ( "returnFloat" , Visibility :: Public , move |_, _| {
534
+ phper:: ok ( 1.234 )
535
+ } )
493
536
. return_type ( ReturnType :: new ( ReturnTypeHint :: Float ) ) ;
494
537
495
538
class
@@ -499,7 +542,9 @@ fn make_return_typehint_class() -> ClassEntity<()> {
499
542
. return_type ( ReturnType :: new ( ReturnTypeHint :: Float ) . allow_null ( ) ) ;
500
543
501
544
class
502
- . add_method ( "returnArray" , Visibility :: Public , move |_, _| phper:: ok ( ( ) ) )
545
+ . add_method ( "returnArray" , Visibility :: Public , move |_, _| {
546
+ phper:: ok ( ZArray :: new ( ) )
547
+ } )
503
548
. return_type ( ReturnType :: new ( ReturnTypeHint :: Array ) ) ;
504
549
505
550
class
0 commit comments