48468437 by Joshua Tundag

update README.md

1 parent 3a9aa681
Showing 1 changed file with 74 additions and 4 deletions
...@@ -3,18 +3,25 @@ Flag Manager for Baytech Sites. ...@@ -3,18 +3,25 @@ Flag Manager for Baytech Sites.
3 3
4 ## Define Flag Directory in your constants.php file 4 ## Define Flag Directory in your constants.php file
5 5
6 ``` 6 ```php
7 define('DEFAULT_PPG', '14'); 7 define('FLAGS_DIR', '<Desired directory to store flags.json file>');
8 ``` 8 ```
9 9
10 ## Initialize Flag Manager 10 ## Initialize Flag Manager
11 11
12 ```php
13 $flagManager = new \BTFlags\FlagManager();
12 ``` 14 ```
15
16 ## Register Flags
17
18 ```php
13 $flagManager = new \BTFlags\FlagManager(); 19 $flagManager = new \BTFlags\FlagManager();
20 $flagManager->register();
14 ``` 21 ```
15 22
16 ### Data Structure 23 ### Data Structure
17 ``` 24 ```php
18 $requestData = array( 25 $requestData = array(
19 'name' => null|string, 26 'name' => null|string,
20 'is_encrypyed' => true|false, 27 'is_encrypyed' => true|false,
...@@ -29,8 +36,28 @@ $requestData = array( ...@@ -29,8 +36,28 @@ $requestData = array(
29 ); 36 );
30 ``` 37 ```
31 38
32 ## CRUD 39 #### Tip:
40
41 ```php
42 // application/config/hooks.php
43 $hook['post_controller_constructor'][] = array(
44 'class' => 'Flag',
45 'function' => 'register',
46 'filename' => 'Flag.php',
47 'filepath' => 'hooks',
48 );
49
50 // application/hooks/Flags.php
51 class Flag{
52 public function register(){
53 $flagManager = new \LawFormsUSA\Flags\FlagManager();
54 $flagManager->register();
55 }
56 }
33 ``` 57 ```
58
59 ## CRUD
60 ```php
34 // Create a Flag 61 // Create a Flag
35 $created = $flagManager->create($requestData); 62 $created = $flagManager->create($requestData);
36 63
...@@ -42,4 +69,47 @@ $updated = $flagManager->update($requestData); ...@@ -42,4 +69,47 @@ $updated = $flagManager->update($requestData);
42 69
43 // Get all Flags 70 // Get all Flags
44 $flags = $flagManager->all(); 71 $flags = $flagManager->all();
72 ```
73
74 ## Retrieving a flag
75
76 ```php
77 // Parameters:
78 // $flagName: String = Name of the flag.
79 // (Optional) $encrypted: bool = If the inputted $flagName is encrypted, set this to true, otherwise, false.
80 // (Optional) $default: String = Default value if flag is empty.
81 // (Option) $driver: String = Driver (cookie or session).
82 \BTFlags\Flags::get($flagName, [$encrypted, $default, $driver]);
83 ```
84
85 #### Example Usage:
86
87 ```php
88 // Getting an encrypted flag
89 // Example Flag:
90 // Name:
91 // 'mode' => 'edom'
92 // Accepted Values:
93 // 'live' => 'prod'
94 // 'test' => 'dev'
95 \BTFlags\Flags::get('edom', true);
96
97 // Getting a non-encrypted flag
98 \BTFlags\Flags::get('source');
99 ```
100
101 #### Tip:
102
103 ```php
104 // utility_helper.php
105 if (!function_exists('flag')){
106 function flag($flag, $default = null, $encrypted = false){
107 return \BTFlags\Flags::get($flag, $encrypted, $default);
108 }
109 }
110
111 // Use anywhere:
112 flag('mode');
113 flag('source');
114 flag('pmt', 'rec');
45 ``` 115 ```
...\ No newline at end of file ...\ No newline at end of file
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!