<?php


namespace app\api\service;
use app\request\Test;

class TestService extends Test implements \JsonSerializable
{
    private $a;
    private $b;

    /**
     * Doc constructor.
     */
    public function __construct(){}


    /**
     * @return mixed
     */
    public function getA()
    {
        return $this->a;
    }

    /**
     * @param mixed $a
     */
    public function setA($a)
    {
        $this->a = $a;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getB()
    {
        return $this->b;
    }

    /**
     * @param mixed $b
     */
    public function setB($b)
    {
        $this->b = $b;
        return $this;
    }


    /**
     * Specify data which should be serialized to JSON
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
     * @return mixed data which can be serialized by <b>json_encode</b>,
     * which is a value of any type other than a resource.
     * @since 5.4.0
     */
    public function jsonSerialize()
    {
        $json = array();
        foreach ($this as $key => $value) {
            if($value===null) {
                continue;
            }
            $json[$key] = $value;
        }
        return $json;
    }
  
  function bulid(){

  }
}

  

<?php
namespace app\request;

use ReflectionClass;

abstract class Test
{
    private $reqType;
    private $url;
    public function execute(){

        try {
            $reflectionClass = new ReflectionClass($this);
        } catch (\ReflectionException $e) {
        }
        $build=$reflectionClass->getMethod("build");

        $build->invoke($this);
        $paramStr=json_encode($this,JSON_UNESCAPED_SLASHES);

        if($paramStr=="[]"){
            $paramStr='{}';
        }
    
      return $paramStr;
      //todo      return bb::aa($paramStr); } abstract function build(); }

  

        $new = new TestService();
        $new->setA(100);
        $new->setB(100);

      dd($new->execute());

  

 

版权声明:本文为叫我亚庆原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/jwyq/p/16563002.html