Name Last Update
examples Loading commit data...
src/BTFlags Loading commit data...
tests Loading commit data...
.gitignore Loading commit data...
README.md Loading commit data...
composer.json Loading commit data...
composer.lock Loading commit data...
phpunit.xml Loading commit data...

BTFlags

Flag Manager for Baytech Sites.

Installation

In your composer.json add:

{
    ...
    "repositories": [
        {
            "type":"vcs",
            "url": "https://gitlab.baytech.ph/janis/btflags.git"
        }
    ],
    "require": {
        ...,
        "btrepo/flags": "dev-master"
    } 
}

On your terminal type:

composer update

Usage

Define Flag Directory

In your constants.php file add:

define('FLAGS_DIR', '<Desired directory to store flags.json file>');

Initialize Flag Manager

$flagManager = new \BTFlags\FlagManager();

Register Flags

$flagManager = new \BTFlags\FlagManager();
$flagManager->register();

Data Structure

$requestData = array(
  'name' => null|string,
  'is_encrypyed' => true|false,
  'is_filtered' => true|false,
  'encrypted_name' => null|string,
  'has_default' => true|false,
  'default' => null|string,
  'accepted_values' => array(
      'value' => null|string,
      'encrypted_value' => null|string,
    ),
);

Tip:

  // application/config/hooks.php
  $hook['post_controller_constructor'][] = array(
    'class' => 'Flag',
    'function' => 'register',
    'filename' => 'Flag.php',
    'filepath' => 'hooks',
  );

  // application/hooks/Flags.php
  class Flag{
    public function register(){
        $flagManager = new \LawFormsUSA\Flags\FlagManager();
        $flagManager->register();
    }
  }

CRUD

// Create a Flag
$created = $flagManager->create($requestData);

// Delete a Flag
$deleted = $flagManager->delete($requestData);

// Update a Flag
$updated = $flagManager->update($requestData);

// Get all Flags
$flags = $flagManager->all();

Retrieving a flag

// Parameters:
// $flagName: String = Name of the flag.
// (Optional) $encrypted: bool = If the inputted $flagName is encrypted, set this to true, otherwise, false.
// (Optional) $default: String = Default value if flag is empty.
// (Option) $driver: String = Driver (cookie or session).
\BTFlags\Flags::get($flagName, [$encrypted, $default, $driver]);

Example Usage:

// Getting an encrypted flag
// Example Flag:
// Name:
//    'mode' => 'edom'
// Accepted Values:
//    'live' => 'prod'
//    'test' => 'dev'
\BTFlags\Flags::get('edom', true);

// Getting a non-encrypted flag
\BTFlags\Flags::get('source');

Tip:

// utility_helper.php
if (!function_exists('flag')){
  function flag($flag, $default = null, $encrypted = false){
    return \BTFlags\Flags::get($flag, $encrypted, $default);
  }
}

// Use anywhere:
flag('mode');
flag('source');
flag('pmt', 'rec');

See examples/ for more snippets.