Creates settings from a JSON-encoded string.
@param string $json
@param string $directory the directory the settings apply to
@return Settings
430136
public static function fromString($json, $directory = ".") {
        $json = json_decode($json, true);
        if (is_null($json))
            throw new SettingsException("invalid json");
        return new static($json, $directory);
    }
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
    );
  }
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;
    }
230037
public function fromJson($json) {
    Helpers::checkType('json', 'string', $json);
    $decoded_value = json_decode($json);
    if ($decoded_value === null && ($json !== 'null' || $json !== '')) {
      throw new \Exception('Invalid JSON.');
    }
    return $this->setValue($decoded_value);
  }
340597
public static function create(array $json)
    {
        $createTargetedMessageResponse = new CreateTargetedMessageResponse();
        $createTargetedMessageResponse->setStatusCode($json['status_code']);
        $createTargetedMessageResponse->setStatusMessage($json['status_message']);
    
        // If a 'response' is provided
        if (array_key_exists('response', $json) && isset($json['response'])) {
            $createTargetedMessageResponseResponse = new CreateTargetedMessageResponseResponse();
    
            // If 'messageCode' is provided
            if (array_key_exists('messageCode', $json['response'])) {
                $createTargetedMessageResponseResponse->setMessageCode($json['response']['messageCode']);
            }
    
            $createTargetedMessageResponse->setResponse($createTargetedMessageResponseResponse);
        }
    
        return $createTargetedMessageResponse;
    }
405956
public static OptimizationConfiguration fromYaml(String json) {
        try {
            return JsonMapper.getYamlMapper().readValue(json, OptimizationConfiguration.class);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
635484
public function setDirectory($directory)
	{
		$this->directory = $directory;

		// Set the finder to use this directory as well
		$this->finder->in($directory);

		return $this;
	}
581555
public static function createFromFile($file) {
    $jsonConfig = json_decode(file_get_contents($file), true);
    return self::createFromConfig($jsonConfig);
  }
1180457
function(object, settings) {
            settings = (settings === undefined) ? {} : settings;

            if(system.isString(settings) || system.isNumber(settings)) {
                settings = { space: settings };
            }

            return JSON.stringify(object, settings.replacer || this.replacer, settings.space || this.space);
        }
828363
private function getThemeInfoForPath($directory)
    {
        $themeJson = new Json($directory);

        $theme = new Theme(
            $themeJson->getJsonAttribute('name'),
            $themeJson->getJsonAttribute('description'),
            $directory,
            $themeJson->getJsonAttribute('parent')
        );
        $theme->version = $themeJson->getJsonAttribute('version');
        $theme->type = ucfirst($themeJson->getJsonAttribute('type'));
        $theme->changelog = $this->getChangelog($directory);
        $theme->active = $this->getStatus($theme);

        return $theme;
    }
558838
public static function import_tour_from_json($json) {
        $tourconfig = json_decode($json);

        // We do not use this yet - we may do in the future.
        unset($tourconfig->version);

        $steps = $tourconfig->steps;
        unset($tourconfig->steps);

        $tourconfig->id = null;
        $tourconfig->sortorder = null;
        $tour = tour::load_from_record($tourconfig, true);
        $tour->persist(true);

        // Ensure that steps are orderered by their sortorder.
        \core_collator::asort_objects_by_property($steps, 'sortorder', \core_collator::SORT_NUMERIC);

        foreach ($steps as $stepconfig) {
            $stepconfig->id = null;
            $stepconfig->tourid = $tour->get_id();
            $step = step::load_from_record($stepconfig, true);
            $step->persist(true);
        }

        return $tour;
    }
62792
public static function readFile($dir, $path)
    {
        if (!pathinfo($path, PATHINFO_EXTENSION)) {
            $path .= '.json';
        }

        if ($path[0] != '/') {
            $path = $dir.DIRECTORY_SEPARATOR.$path;
        }

        if (!is_file($path) || !is_readable($path)) {
            throw new \RuntimeException(sprintf('Unable to load configuration from "%s".', $path));
        }

        $data = json_decode(file_get_contents($path), true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \RuntimeException('Configuration JSON format is invalid.');
        }

        if (isset($data['$extends']) && is_string($data['$extends'])) {
            $extends = static::readFile($dir, $data['$extends']);
            $data = array_replace_recursive($extends, $data);
            unset($data['$extends']);
        }

        return $data;
    }
1364809
public static function fromJson($json)
    {
        if (!is_object($json)) {
            $json = json_decode($json);
        }
        $properties = ['package', 'description', 'url', 'sha1', 'depth'];
        $patch = new static();

        foreach ($properties as $property) {
            if (isset($json->{$property})) {
                $patch->{$property} = $json->{$property};
            }
        }

        return $patch;
    }
368545
public static function fromJson($json)
    {
        $object = json_decode($json);

        $recurrentPayment = new RecurrentPayment();

        if (isset($object->RecurrentPayment)) {
            $recurrentPayment->populate($object->RecurrentPayment);
        }

        return $recurrentPayment;
    }
1052459
private function getTranslations($directory, $language)
    {
        $contentJson = '';

        $directoryJson = ($language == 'en') ? '/en/' : '/../json/';

        $fileJson = $directory.$directoryJson.$language.'.json';

        if (file_exists($fileJson)) {
            $contentJson = json_decode(file_get_contents($fileJson), true);
        }

        return [
            'json'       => $contentJson,
            'auth'       => include($directory.'/'.$language.'/auth.php'),
            'pagination' => include($directory.'/'.$language.'/pagination.php'),
            'passwords'  => include($directory.'/'.$language.'/passwords.php'),
            'validation' => include($directory.'/'.$language.'/validation.php'),
        ];
    }
935459
public static function fromJson($json)
    {
        $object    = \json_decode($json);
        $cardToken = new CreditCard();
        $cardToken->populate($object);

        return $cardToken;
    }
1196679
public function makeJsonFileName($key, $dir = '')
    {
        if (! ends_with($dir, (DIRECTORY_SEPARATOR))) {
            $dir .= DIRECTORY_SEPARATOR;
        }

        return $this->dataDir($this->addSuffix('.json', $this->toDir($dir).strtolower($key)));
    }