Constructor.
@access		public
@param		string		$filePath		Path to JSON file
@param		mixed		$value			Value to write into JSON file
@param		bool		$format			Flag: format JSON serial
@return		int			Number of written bytes
497296
public static function save( $filePath, $value, $format = FALSE )
	{
		$writer	= new FS_File_JSON_Writer( $filePath );
		return $writer->write( $value, $format );
	}
149401
public static function getInstance($filePath = "/data/config/", $fileExt = "json")
    {
        if (!self::$instance) {
            self::$instance = new self($filePath, $fileExt);
        }

        return self::$instance;
    }
1256228
protected function dumpJsonFile()
    {
        $jsonPath = $this->config->getJsonPath();
        $this->logger->info(sprintf('Dump submitting json file: %s', $jsonPath));

        $this->api->dumpJsonFile();

        $filesize = number_format(filesize($jsonPath) / 1024, 2); // kB
        $this->logger->info(sprintf('File size: <info>%s</info> kB', $filesize));

        return $this;
    }
22581
public static function isTrue($value, $format, $args = null, $_ = null) {
        if (!$value) {
            self::vfail($format, array_slice(func_get_args(), 2));
        }
        return $value;
    }
744929
function Json(filepath) {
  this.filepath = filepath;
  this.dirname = undefined;
  this.json = undefined;
  this.realpath = undefined;
}
395990
static public function file($value, $message = null, $propertyPath = null)
        {
            static::string($value, $message);
            static::notEmpty($value, $message);

            if ( ! is_file($value)) {
                $message = $message ?: sprintf(
                    'File "%s" was expected to exist.',
                    static::stringify($value)
                );

                throw static::createException($value, $message, static::INVALID_FILE, $propertyPath);
            }
        }
449919
public static function format($value, $format)
    {
        // Verificar se value eh um array
        if (is_array($value)) {
            return array_map(function ($val) use ($format) {
                return sprintf($format, $val);
            }, $value);
        }

        return sprintf($format, $value);
    }
155042
protected function coerceArrayValue(string $format, $value): array
    {
        switch ($format) {
            case 'csv':
                return explode(',', $value);
            case 'ssv':
                return explode(' ', $value);
            case 'tsv':
                return explode("\t", $value);
            case 'pipes':
                return explode('|', $value);
            default:
                throw new \RuntimeException(
                    "Array 'collectionFormat' '$format' is not currently supported"
                );
        }
    }
317673
protected function importFromJson($filePath)
    {

        $this->sourceData = $json = $this->readJson($filePath);
        $data = [];
        $docs = [];
        $methods = [];
        $operations = [];

        if (!empty($json)) {

            $globalInfo = $this->readGlobalInfo($json);
            $globalTitle = $this->readGlobalTitle($globalInfo);

            $items = $json['item'];

            foreach ($items as $itemIndex => $apiGroup) {
                $apiGroupName = $this->applyFilter('GroupName', $apiGroup['name']);
                $apiGroupDescription = $this->applyFilter('GroupDescription', $apiGroup['description']);
                if (empty($docs[$apiGroupName])) {
                    $docs[$apiGroupName] = ['description' => $apiGroupDescription, 'items' => []];
                } else {
                    // group already exists
                }

                $apiGroupItems = $apiGroup['item'];
                foreach ($apiGroupItems as $apiIndex => $api) {
                    $api = $this->preProcessApi($api);

                    $commonParams = compact('api', 'apiIndex',
                        'apiGroupItems', 'apiGroup', 'operations') +
                            [
                                'groupIndex' => $itemIndex,
                                'info' => $globalInfo,
                                'allItems' => $items
                            ];

                    $operation = $this->readOperationItem($commonParams);
                    $commonParams['operation'] = $operation;

                    $commonParams['apiName'] = $apiName = $this->readApiName($commonParams);
                    $skipConfig = $this->deliberateSkips($commonParams);
                    if (($skipConfig['operation']  ?? true) !== false) {
                        $operations[$apiName] = $operation;
                    }

                    if (($skipConfig['phpDoc']  ?? ($skipConfig['docs']  ?? true)) !== false) {
                        $commonParams['phpDocMethod'] = $methods[$apiName] = $this->readPhpDocMethodItem($commonParams);
                    }
                    if (($skipConfig['mdDoc']  ?? ($skipConfig['docs']  ?? true)) !== false) {
                        $docs[$apiGroupName]['items'][$apiName] = $this->readMarkdownItem($commonParams);
                    }
                }
            }

            if (!empty($operations)) {
                $data = compact('operations');
                $data['models'] = $this->getOperationModels($operations);
            }

            $this->mdDocsData = ['title' => $globalTitle, 'groups' => $docs];
            $this->methodData = $methods;
        }

        return $data;
    }
1260058
static function format($value,$format)
    {
        $f = Utility::get($format, "format", true);
        if ($f===false) {
            return $value;
        }
        
        $type = Utility::get($format, "type", "unknown");
        switch($type)
        {
        case "number":
            $decimals = Utility::get($format, "decimals", 0);
            $dec_point = Utility::get(
                $format,
                "decPoint",
                Utility::get(
                    $format,
                    "decimalPoint",
                    Utility::get(
                        $format,
                        "dec_point",
                        "."
                    )
                )
            );

            $thousand_sep = Utility::get(
                $format,
                "thousandSep",
                Utility::get(
                    $format,
                    "thousandSeparator",
                    Utility::get(
                        $format,
                        "thousand_sep",
                        ","
                    )
                )
            );
            $prefix = Utility::get($format, "prefix", "");
            $suffix = Utility::get($format, "suffix", "");
            return $prefix
                .number_format($value, $decimals, $dec_point, $thousand_sep)
                .$suffix;
            break;
        case "string":
            $prefix = Utility::get($format, "prefix", "");
            $suffix = Utility::get($format, "suffix", "");
            return $prefix.$value.$suffix;
            break;
        case "datetime":
            $dateFormat = Utility::get($format, "format", "Y-m-d H:i:s");
        case "date":
            $dateFormat = isset($dateFormat)
                ?$dateFormat
                :Utility::get($format, "format", "Y-m-d");
        case "time":
            $dateFormat = isset($dateFormat)
                ?$dateFormat
                :Utility::get($format, "format", "H:i:s");
            $displayFormat = Utility::get($format, "displayFormat");
            if ($displayFormat && $value) {
                if ($fvalue = \DateTime::createFromFormat($dateFormat, $value)) {
                    return $fvalue->format($displayFormat);
                }
            }
            break;
        }
        return $value;
    }
304456
protected function readTypeFromJsonFileUniversal($filePath, $fileBaseName)
    {
        $fName       = $filePath . DIRECTORY_SEPARATOR . $fileBaseName . '.min.json';
        $fJson       = fopen($fName, 'r');
        $jSonContent = fread($fJson, filesize($fName));
        fclose($fJson);
        return json_decode($jSonContent, true);
    }
1208297
function readJSON(filepath){
	var buffer = {};
	try{
		buffer = JSON.parse(fs.readFileSync(filepath, { encoding:'utf8' }));
	} catch(error){}
	return buffer;
}
1058367
public function save($path, $format)
	{
		switch ($format) {
			case phpGPX::XML_FORMAT:
				$document = $this->toXML();
				$document->save($path);
				break;
			case phpGPX::JSON_FORMAT:
				file_put_contents($path, $this->toJSON());
				break;
			default:
				throw new \RuntimeException("Unsupported file format!");
		};
	}
1345483
protected static function parseDateValue($value, $format, $timeZone)
    {
        $date = DateTime::createFromFormat($format, $value, new DateTimeZone($timeZone));
        $errors = DateTime::getLastErrors();
        if ($date === false || $errors['error_count'] || $errors['warning_count']) {
            return false;
        } else {
            // if no time was provided in the format string set time to 0 to get a simple date timestamp
            if (strpbrk($format, 'UHhGgis') === false) {
                $date->setTime(0, 0, 0);
            }
            return $date;
        }
    }
1343916
public static function safeFileWrite($filepath, $str = '', $opts = array())
	{
		$return = false;
		$opts = array_merge(array(
			'est_size' => strlen($str),
		), $opts);
		$fh = self::safeFopen($filepath, $opts);
		if ($fh) {
			if (fwrite($fh, $str) !== false) {
				$return = true;
			} else {
				trigger_error('Error writing to '.$filepath, E_USER_ERROR);
			}
			self::safeFclose($fh);
		}
		return $return;
	}
206628
protected function formatValue($value)
    {
        if (PHP_VERSION_ID < 50400) {
            return str_replace('\/', '/', json_encode($value));
        }

        return json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    }
449364
protected function formatValue($format, $value)
    {
        // TODO : Put in parameters
        $decimals = 2;
        $dec_point = ',';
        $thousands_sep = ' ';

        switch ($format) {
            case Format::DATE:
                if ($value instanceof \DateTime) {
                    return $value->format('d/m/Y');
                }
                break;

            case Format::DATETIME:
                if ($value instanceof \DateTime) {
                    return $value->format('d/m/Y H:i:s');
                }
                break;

            case Format::FLOAT2:
                return str_replace($dec_point."00", "",number_format(floatval($value), $decimals, $dec_point, $thousands_sep));

            case Format::INTEGER:
                return number_format(intval($value), 0, $dec_point, $thousands_sep);

            case Format::PCT:
                return $this->formatValue(Format::INTEGER, $value*100)."%";

            case Format::PCT2:
                return $this->formatValue(Format::FLOAT2, $value*100)."%";

            case Format::MONEY:
                return $this->formatValue(Format::INTEGER, $value)."€";

            case Format::MONEY2:
                return $this->formatValue(Format::FLOAT2, $value)."€";
        }

        return $value;
    }