ironedge/file-utils

dev-master / 1.0.x-dev 2015-12-28 20:43 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:00:56 UTC


README

Build Status Dependency Status Reference Status

描述

此组件允许您以非常简单的方式加载、保存、编码和解码不同类型的文件。

当前支持的格式

  • JSON
  • YAML

查看路线图,了解未来版本中将支持哪些其他文件类型。

用法

要打开文件,请使用以下代码

use IronEdge\Component\FileUtils\File\Factory;

$factory = new Factory();

// $file will be an instance of a subclass of \IronEdge\Component\FileUtils\File\Base .
// It detects the file type by its extension, and creates an instance of the appropiate
// class, if it's available.

$file = $factory->createInstance('/path/to/your/file');

// File contents are lazy loaded and decoded. When you call the "getContents" method, it opens
// the file and decodes its data.

$data = $file->getContents();

// Suppose we've open a JSON file with contents {"myParam": "myValue"}

print_r($data);

// It would print

Array
(
    [myParam] => myValue
)

// If you need to update the file

$data['myParam'] = 'newValue !';

$file->setContents($data);

$file->save();

路线图

  • XML处理。