carlosv2/pocket

小型存储服务

1.0.0 2016-11-17 23:41 UTC

This package is not auto-updated.

Last update: 2024-09-14 20:09:28 UTC


README

小型存储服务

License Build Status SensioLabsInsight

本项目旨在提供快速、简单的文件内持久化功能。

用法

该项目由3个主要类组成

  • ValuePocket:此类仅存储任何类型的一个值。它需要存储数据的文件路径。可选地,您可以传递一个默认值,如果尚未存储任何内容,则返回该值。例如

    use carlosV2\Pocket\ValuePocket;
    
    $pocket = new ValuePocket('/path/to/the/file', 42);
    $pocket->load(); // Returns: 42
    
    $pocket->save(4);
    $pocket->load(); // Returns: 4
  • CollectionPocket:此类存储任何类型的值集合。它需要存储数据的文件路径。例如

    use carlosV2\Pocket\CollectionPocket;
    
    $pocket = new CollectionPocket('/path/to/the/file');
    $pocket->add('a');
    $pocket->add(1);
    $pocket->add(true);
    
    $pocket->getValues(); // Returns: ['a', 1, true]
  • IndexedPocket:此类存储任何类型的索引值集合。它需要存储数据的文件路径。例如

    use carlosV2\Pocket\IndexedPocket;
    
    $pocket = new IndexedPocket('/path/to/the/file');
    $pocket->add('key1', 'a');
    $pocket->add('key2', 1);
    $pocket->add('key3', true);
    
    $pocket->getValues(); // Returns: ['a', 1, true]
    $pocket->getKeys(); // Returns: ['key1', 'key2', 'key3']

此外,还提供了一个管理类,以便只需要单个文件夹路径。文件管理由此类执行。此外,它可以执行维护任务。例如

use carlosV2\Pocket\PocketManager;

$manager = new PocketManager('/path/to/the/folder/');

$manager->getValuePocket(); // Returns an instance of ValuePocket
$manager->getCollectionPocket(); // Returns an instance of CollectionPocket
$manager->getIndexedPocket(); // Returns an instance of IndexedPocket

$manager->clear(); // Removes any file inside /path/to/the/folder/ folder

安装

打开命令行控制台,进入您的项目目录,并执行以下命令以下载本项目的最新稳定版本

$ composer require --dev carlosv2/pocket

此命令要求您全局安装了Composer,如Composer文档中的安装章节中所述。