PHP code example of cxx / param-inject

1. Go to this page and download the library: Download cxx/param-inject library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cxx / param-inject example snippets


   use Cxx\ParamInject\Param;
   
   /**
    * 参数类(所有参数类都需要继承 Cxx\ParamInject\Param)
    */
   class Test extends Param
   {
       // 属性访问性必须是 public
       /**
        * @var int
        */
       public $page = 1;
   
       // 注释规则必须要有 @var 后面跟属性类型
       /**
        * @var int
        */
       public $limit = 10;
       
       // 也可以写在行内
       /** @var int */
       public $limit = 10;
       
       // 不带默认值,均为 null
       /** @var int */
       public $limit;
   }
   

   // 注意方法参数类型
   public function index(Test $test)
   {
       dd($test);
   }
   
   

   // 注意匿名函数参数类型
   Route::post('/test', function (Test $test) {
       dd($test);
   });