godbout/alfred-workflow-config 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

godbout/alfred-workflow-config

最新稳定版本:1.8.0

Composer 安装命令:

composer require godbout/alfred-workflow-config

包简介

Manage settings easily for your Alfred 3 or 4 Workflows.

README 文档

README

Latest Stable Version Build Status Quality Score Code Coverage Total Downloads

Easily read and write config settings for your Alfred 3 or 4 Workflow. We took care of the boring stuff for you.

Installation

composer require godbout/alfred-workflow-config

Usage

Import the class:

require 'vendor/autoload.php';

use Godbout\Alfred\Workflow\Config;

Then you can start save settings. Use dot notation for nested settings:

Config::write('language', 'english');

Config::write('workflow.user.name', 'Guill');

Read settings:

$language = Config::read('language');

$userName = Config::read('workflow.user.name');

You can provide a default config for your workflow. It will only be saved if no config is found:

Config::ifEmptyStartWith(['version' => 1.0, 'enabled' => true]);

Usage in your tests

Set the Alfred Workflow Data environment variable

The package uses an environment variable set by Alfred to determine where to create and store your data. If you are not using this Config class through a script that is called by Alfred (like in your tests, for example), then you need to set that environment variable. Use putenv("alfred_workflow_data=./where_you_want_to_store_alfred_data"); before writing or reading your settings.

Destroy the Config between tests

The Config class is a singleton. This allows me to provide you with a very simple and nice to use API. It works great when being used by Alfred calling your Workflow script, but not so much with testing. If you're using the Config class in your own tests, you have to destroy the singleton between each test. You can do it easily like this:

protected function tearDown(): void
{
    parent::tearDown();

    Config::destroy();
}

This will make sure that your next test starts with a virgin Config.

ArrayAccess

There is none. We don't keep an array of settings internally, so there's no way to implement completely ArrayAccess. You could read settings through an array notation but not add a new setting, so the whole ArrayAccess implementation has been put to sleep.

Behind the scenes

  1. We create the Alfred Workflow Data folder if it doesn't exist.
  2. We create a config.json file and store the settings, well, in pretty json.
  3. We directly read and write to the config file, so even if your workflow crashes after, your settings will be saved as soon as you call the method.

统计信息

  • 总下载量: 2.4k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-22