Skip to content

Commit

Permalink
📝 docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gfazioli committed Sep 19, 2024
1 parent 0e3c3e7 commit de4a2e3
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 20 deletions.
104 changes: 84 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# Flags for WP Bones


[![Latest Stable Version](https://poser.pugx.org/wpbones/flags/v/stable)](https://packagist.org/packages/wpbones/flags)
[![Total Downloads](https://poser.pugx.org/wpbones/flags/downloads)](https://packagist.org/packages/wpbones/flags)
[![License](https://poser.pugx.org/wpbones/flags/license)](https://packagist.org/packages/wpbones/flags)

Flags for [WP Bones](https://wpbones.vercel.app) is a PHP package designed for the WP Bones framework, allowing you to enable or disable features in plugins using [YAML](https://yaml.org/) configuration files.
This approach simplifies feature management and makes the plugin more flexible and easy to configure, even for non-technical users.


## Key features
- Enable and Disable Features: Using flags, you can easily activate or deactivate specific plugin features.
- YAML Configuration: YAML files are easy to read and modify, and can be used to configure various plugin options.
- Flexibility: The path and name of the YAML file can be customized through the plugin configuration.
• Reusability: The same YAML file can be used across different plugins, improving code consistency and maintenance.

- Reusability: The same YAML file can be used across different plugins, improving code consistency and maintenance.

## Installation

Expand Down Expand Up @@ -48,16 +45,6 @@ and run
composer install
```

## Why use Flags instead the PHP code?

Flags is able to read the [YAML](https://yaml.org/) files:

- It's easier to understand and modify
- You can provide this file to your clients or users, and they can easily change the behavior of the plugin
- You can use the same file in different plugins
- The path and name of the file can be changed in the plugin configuration
- You could use one or more [YAML](https://yaml.org/) files in the plugin

## YAML file example

```yaml
Expand Down Expand Up @@ -90,24 +77,101 @@ config/flags.yaml
You can set the path and filename in the plugin configuration by adding the following line in the `config/plugin.php` file of your plugin:

```php
'flags' => [
'path' => 'config/flags.yaml',
],
<?php
if (!defined('ABSPATH')) {
exit();
}
return [
/*
|--------------------------------------------------------------------------
| Logging Configuration
|--------------------------------------------------------------------------
|
| Here you may configure the log settings for your plugin.
|
| Available Settings: "single", "daily", "errorlog".
|
| Set to false or 'none' to stop logging.
|
*/
'log' => 'errorlog',
'log_level' => 'debug',
/*
|--------------------------------------------------------------------------
| Flags package path Configuration
|--------------------------------------------------------------------------
|
| Here you may configure the flags path for your plugin.
|
*/
'flags' => [
'path' => 'config/flags.yaml',
],
...
```

## Basic usage

You can use the `wpbones_flags` helper function to get the value of a flag:

```php
wpbones_flags()->get('example.enabled', false);
```

The first parameter is the flag name, and the second parameter is the default value if the flag is not found.

You may also use the class directly:

```php
use WpBones\Flags\Flags;
$flags = new Flags();
$flags->get('example.enabled', false);
```

or by using the static method:

```php
use WpBones\Flags\Flags;
Flags::get('example.enabled', false);
```

### Set the flags path by method

You may also set/change the path by using:

```php
wpbones_flags('config/flags.yaml')->get('logger.enabled', false);
wpbones_flags('config/flags.yaml')->get('logger.enabled', false);
```

or the fluent method `withPath`:

```php
wpbones_flags()->withPath('config/flags.yaml')->get('logger.enabled', false);
wpbones_flags()->withPath('config/flags.yaml')->get('logger.enabled', false);
```

## Basic usage
by using the class directly:

```php
use WpBones\Flags\Flags;
$flags = new Flags();
$flags->withPath('config/flags.yaml')->get('logger.enabled', false);
```

or by using the static method:

```php
use WpBones\Flags\Flags;
Flags::withPath('config/flags.yaml')->get('logger.enabled', false);
```



12 changes: 12 additions & 0 deletions src/Flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ private function callableGet($key, $default = null)
{
return $this->flags($key, $default);
}

/**
* Set the path to the flags file.
*
* @param string $path The path to the flags file.
*
* @return $this
*/
private function callabeWithPath($path)
{
return $this->withPath($path);
}
}

0 comments on commit de4a2e3

Please sign in to comment.