解析字符串生成 Task 对象

@param  string $json
@return \Ws\Http\Automated\Task
3673
public static function parse($json)
	{
		// 验证json格式

		$params = json_decode($json, true);

		$obj = new Task();
		$obj->id = $params['id'];
		$obj->name = $params['name'];
		$obj->type = (int) $params['type'];
		$obj->body = TaskBody::parse($params['body']);

		return $obj;
	}
913626
public static function unwrapJSON($json): self {
        if (is_string($json)) {
            $json = json_decode($json, true);
        }
        $recipient = new static;
        $recipient->setEndpoint($json['endpoint']);
        $recipient->setIdentifier(array_reverse(explode('/', $json['endpoint']))[0]);
        $recipient->setAuthKey($json['keys'][static::AUTH_KEY]);
        $recipient->setAuthSecret($json['keys'][static::AUTH_SECRET]);
        return $recipient;
    }
1294186
public static function jsonDeserialize( $json ) {
		$self = new LogList();
		foreach ( $json as $logJson ) {
			$self->addLog( Log::jsonDeserialize( $logJson ) );
		}
		return $self;
	}
220206
public static function set_Json( $json, $inputValidate )
    {
        if( $json instanceof Json ) {
            return $json;
        } elseif( null === $json ) {
            return null;
        } elseif ( !is_string($json) ) {
            return Json::makeFromObject( $json );
        }

        return new Json( $json, $inputValidate );
    }
936827
private static function create($decoded, Json $json)
    {
        $json->validate(
            $json->decodeFile(PHAR_UPDATE_MANIFEST_SCHEMA),
            $decoded
        );

        $updates = array();

        foreach ($decoded as $update) {
            $updates[] = new Update(
                $update->name,
                $update->sha1,
                $update->url,
                Parser::toVersion($update->version),
                isset($update->publicKey) ? $update->publicKey : null
            );
        }

        usort(
            $updates,
            function (Update $a, Update $b) {
                return Comparator::isGreaterThan(
                    $a->getVersion(),
                    $b->getVersion()
                );
            }
        );

        return new static($updates);
    }
1249048
public static function fromJson($json){
    if(is_string($json)){
      $json = json_decode($json);
    }
    
    if(!property_exists($json, 'total')){
      throw new BadResponseException('Required parameter "total" not found');
    }
    if(!property_exists($json, 'fns_site')){
      throw new BadResponseException('Required parameter "fns_site" not found');
    }
    if(!property_exists($json, 'fn_number')){
      throw new BadResponseException('Required parameter "fn_number" not found');
    }
    if(!property_exists($json, 'shift_number')){
      throw new BadResponseException('Required parameter "shift_number" not found');
    }
    if(!property_exists($json, 'receipt_datetime')){
      throw new BadResponseException('Required parameter "receipt_datetime" not found');
    }
    if(!property_exists($json, 'fiscal_receipt_number')){
      throw new BadResponseException('Required parameter "fiscal_receipt_number" not found');
    }
    if(!property_exists($json, 'fiscal_document_number')){
      throw new BadResponseException('Required parameter "fiscal_document_number" not found');
    }
    if(!property_exists($json, 'fiscal_document_attribute')){
      throw new BadResponseException('Required parameter "fiscal_document_attribute" not found');
    }
    if(!property_exists($json, 'ecr_registration_number')){
      throw new BadResponseException('Required parameter "ecr_registration_number" not found');
    }

    return new self(
      $json->total,
      $json->fns_site,
      $json->fn_number,
      $json->shift_number,
      new DateTime($json->receipt_datetime),
      $json->fiscal_receipt_number,
      $json->fiscal_document_number,
      $json->fiscal_document_attribute,
      $json->ecr_registration_number
    );
  }
429355
public static function get_Json( &$json )
    {
        if( $json instanceof Json ) {
            return $json;
        }
        return !is_null($json)
            ? new Json($json)
            : null
            ;
    }
899357
public function toGruntTask($task)
    {
        $workingDirectory = $this->moodle->directory;
        if (is_file($this->plugin->directory.'/Gruntfile.js')) {
            $workingDirectory = $this->plugin->directory;
        }
        $defaultTask = new GruntTaskModel($task, $workingDirectory);

        switch ($task) {
            case 'amd':
                $amdDir = $this->plugin->directory.'/amd';
                if (!is_dir($amdDir)) {
                    return null;
                }

                return new GruntTaskModel($task, $amdDir, 'amd/build');
            case 'shifter':
            case 'yui':
                $yuiDir = $this->plugin->directory.'/yui';
                if (!is_dir($yuiDir)) {
                    return null;
                }

                return new GruntTaskModel($task, $yuiDir.'/src', 'yui/build');
            case 'gherkinlint':
                if ($this->moodle->getBranch() < 33 || !$this->plugin->hasBehatFeatures()) {
                    return null;
                }

                return new GruntTaskModel($task, $this->moodle->directory);
            case 'stylelint:css':
                return $this->plugin->hasFilesWithName('*.css') ? $defaultTask : null;
            case 'stylelint:less':
                return $this->plugin->hasFilesWithName('*.less') ? $defaultTask : null;
            case 'stylelint:scss':
                return $this->plugin->hasFilesWithName('*.scss') ? $defaultTask : null;
            default:
                return $defaultTask;
        }
    }
262349
public function create(Task $task): Task
    {
        $response = $this->client->post($this->prepareUrlForKey('add-task'), [], $task->jsonSerialize());
        $responseData = $response->getDecodedBody();

        return new Task($responseData);
    }
797824
public function build($json)
    {
        $contract = \GuzzleHttp\json_decode($json, true);
        if (!isset($contract['protocol'])) {
            throw new \InvalidArgumentException('Invalid contract; Protocol is not specified');
        }

        return $this->getBuilder($contract['protocol'])->build($contract);
    }
680103
private function createTypedObject(stdClass $json)
    {
        $url = new Url($json->same_as);

        foreach ($this->urlValidators as $urlValidator) {
            $urlValidator->validateUrl($url);
        }

        return new CreateOfferVariation(
            $url,
            new OwnerId($json->owner),
            new Purpose($json->purpose),
            new Description($json->description)
        );
    }
953623
public static function create(array $json)
    {
        $unregisterDeviceResponse = new UnregisterDeviceResponse();
        $unregisterDeviceResponse->setStatusCode($json['status_code']);
        $unregisterDeviceResponse->setStatusMessage($json['status_message']);

        return $unregisterDeviceResponse;
    }
388322
public static function fromJson($json) {
        if (!$json) {
            $json = array();
        }

        if (!is_array($json)) {
            if (is_object($json)) {
                $json = (array) $json;
            } elseif (is_string($json)) {
                $json = json_decode(trim($json) ? $json : '{}', true);
            } else {
                throw new \InvalidArgumentException("JSON must be a string, an array or an object ('" . gettype($json) . "' provided).");
            }
        }

        return new Link(
            isset($json['href'])        ? $json['href']            : null,
            isset($json['templated'])    ? $json['templated']    : null,
            isset($json['type'])        ? $json['type']            : null,
            isset($json['deprecation'])    ? $json['deprecation']    : null,
            isset($json['name'])        ? $json['name']            : null,
            isset($json['profile'])        ? $json['profile']        : null,
            isset($json['title'])        ? $json['title']        : null,
            isset($json['hreflang'])    ? $json['hreflang']        : null
        );
    }
336586
public function json(array $json = [], $assoc = false)
    {
        $this->options['json']       = $json;
        $this->options['json_assoc'] = $assoc;
        return $this;
    }
196277
public function tasks($site)
    {
        $variables = array(
            'site' => $site,
        );
        $request = $this->get(array('{+base_path}/sites/{site}/tasks.json', $variables));
        return new Response\Tasks($request);
    }
962800
public static function fromJson($json){
    if(is_string($json)){
      $json = json_decode($json);
    }

    if (!isset($json->error) || is_null($json->error) ) {
      return new self($json->uuid, new DateTime($json->timestamp), $json->status);
    } else {
      if(!property_exists($json->error, 'code')){
        throw new BadResponseException('Required parameter "error.code" not found');
    }
      throw AbstractReport::errorToException($json->error->code);
    }
  }
214658
public static function make($json)
    {
        $schema = json_decode(
            $json,
            true
        );
        if (!$schema) {
            throw new SchemaException(
                __CLASS__,
                __METHOD__,
                "Error decoding json file while creating schema",
                500
            );
        }

        if (!array_key_exists(
            'properties',
            $schema
        )
        ) {
            throw new SchemaException(
                __CLASS__,
                __METHOD__,
                "'properties' field has not been found for defining schema entry",
                500
            );
        }


        $instance = new self(
            PropertyCotainer::make(
                $schema['properties']
            )
        );

        if (array_key_exists(
            'database',
            $schema
        )
        ) {
            $instance->setDatabaseContainer(
                DatabaseContainer::make(
                    $schema['database'],
                    $instance->getPropertyContainer()
                )
            );
        }

        if (array_key_exists(
            'meta',
            $schema
        )) {
            $instance->setMeta($schema['meta']);
        }

        return $instance;
    }