Skip to content

Commit c3ab321

Browse files
authored
Merge pull request #5 from clearlyip/feature/v3
2 parents e23f43f + c8c9692 commit c3ab321

38 files changed

+1436
-296
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/tests export-ignore
2+
/workbench export-ignore

.gitignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
/vendor/
1+
vendor
2+
# Before you hate on me for this https://stackoverflow.com/a/21589454
23
composer.lock
3-
package-lock.json
4-
/node_modules/
4+
node_modules
5+
output
6+
.env
7+
.phpunit.cache
8+
package-lock.json

.prettierrc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
{
2-
"trailingCommaPHP": true,
3-
"singleQuote": true,
4-
"useTabs": false,
5-
"braceStyle": "psr-2"
2+
"tabWidth": 4,
3+
"singleQuote": true,
4+
"useTabs": false,
5+
"plugins": ["@prettier/plugin-php"],
6+
"overrides": [
7+
{
8+
"files": ["*.php"],
9+
"options": {
10+
"parser": "php",
11+
"phpVersion": "8.2",
12+
"trailingCommaPHP": true,
13+
"braceStyle": "psr-2"
14+
}
15+
}
16+
]
617
}

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Listen for XDebug",
9+
"type": "php",
10+
"request": "launch",
11+
"port": 9001
12+
}
13+
]
14+
}

.vscode/settings.json

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
{
2-
// I recommend to disable VS Code's built-in PHP IntelliSense by setting php.suggest.basic to false to avoid duplicate suggestions.
3-
"php.suggest.basic": false,
4-
"editor.formatOnSave": true,
5-
"[php]": {
6-
"editor.defaultFormatter": "esbenp.prettier-vscode"
7-
},
8-
"workbench.colorCustomizations": {},
9-
"taskExplorer.pathToMake": "make",
10-
"coverage-gutters.showLineCoverage": true,
11-
"coverage-gutters.showRulerCoverage": true,
2+
// I recommend to disable VS Code's built-in PHP IntelliSense by setting php.suggest.basic to false to avoid duplicate suggestions.
3+
"php.suggest.basic": false,
4+
"editor.formatOnSave": true,
5+
"[php]": {
6+
"editor.defaultFormatter": "esbenp.prettier-vscode"
7+
},
8+
"workbench.colorCustomizations": {},
9+
"psalm.configPaths": ["psalm.xml"],
10+
"psalm.psalmScriptPath": "vendor/bin/psalm-language-server",
11+
"phpCodeSniffer.exec.linux": "vendor/bin/phpcs",
12+
"phpCodeSniffer.standard": "Custom",
13+
"phpCodeSniffer.standardCustom": "phpcs.xml",
14+
"psalm.psalmScriptArgs": [
15+
"--on-change-debounce-ms=500",
16+
"--show-diagnostic-warnings=false"
17+
],
18+
"editor.rulers": [80],
19+
"intelephense.environment.phpVersion": "8.2.0",
20+
"coverage-gutters.showLineCoverage": true,
21+
"coverage-gutters.showRulerCoverage": true,
22+
"coverage-gutters.coverageBaseDir": "output/**",
23+
"coverage-gutters.remotePathResolve": ["./"],
24+
"prettier.documentSelectors": ["**/*.php", "**/*.blade.php"]
1225
}

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ Laravel-flagsmith was created by, and is maintained by **[Andrew Nagy](https://g
1010

1111
## Features
1212

13-
- Provides a trait to be able to get features based on Laravel Users ([Flagsmith Identities](https://docs.flagsmith.com/basic-features/managing-identities))
14-
- Utilizes [Laravel's Queue](https://laravel.com/docs/8.x/queues) system to update features in the background
15-
- Utilizes [Laravel's Cache](https://laravel.com/docs/8.x/cache) system to store features in a cache for quick access
16-
- Utilizes [Laravel's Task Scheduling](https://laravel.com/docs/8.x/scheduling) system to update features on a schedule
17-
- Adds a route to utilize [Flagsmith's webhooks](https://docs.flagsmith.com/advanced-use/system-administration) to update the cache when features change
13+
- Provides a trait to be able to get flags based on Laravel Users ([Flagsmith Identities](https://docs.flagsmith.com/basic-features/managing-identities))
14+
- Utilizes [Laravel's Queue](https://laravel.com/docs/8.x/queues) system to update flags in the background
15+
- Utilizes [Laravel's Cache](https://laravel.com/docs/8.x/cache) system to store flags in a cache for quick access
16+
- Utilizes [Laravel's Task Scheduling](https://laravel.com/docs/8.x/scheduling) system to update flags on a schedule
17+
- Adds a route to utilize [Flagsmith's webhooks](https://docs.flagsmith.com/advanced-use/system-administration) to update the cache when flags change
1818

1919
## Installation & Usage
2020

21-
> **Requires [PHP 7.4+](https://php.net/releases/)**
21+
> **Requires [PHP 8.2+](https://php.net/releases/)**
2222
2323
Require Laravel-flagsmith using [Composer](https://getcomposer.org):
2424

@@ -32,46 +32,48 @@ composer require clearlyip/laravel-flagsmith
3232
| :------ | :---------------- |
3333
| 8.x | 1.x |
3434
| 9.x | 2.x |
35-
| 10.x | 2.1.x |
35+
| 10.x | 3.x |
3636

3737
## Usage
3838

3939
### Configuration Files
4040

41-
- Publish the Laravel Flagsmith configuration file using the `vendor:publish` Artisan command. The `flagsmith` configuration file will be placed in your `config` directory (Use `--force` to overwrite your existing `clearly` config file):
42-
- `php artisan vendor:publish --tag="flagsmith" [--force]`
41+
- Publish the Laravel Flagsmith configuration file using the `vendor:publish` Artisan command. The `flagsmith` configuration file will be placed in your `config` directory (Use `--force` to overwrite your existing `clearly` config file):
42+
- `php artisan vendor:publish --tag="flagsmith" [--force]`
4343

4444
All options are fully documented in the configuration file
4545

4646
### User
4747

48-
It's advised to add the trait `Clearlyip\LaravelFlagsmith\Concerns\HasFeatures` to your user model. This will give you the ability to access features directly from your user object.
48+
It's advised to add the interface `Clearlyip\LaravelFlagsmith\Contracts\UserFlags` to your user model. This will give you the ability to access flags directly from your user object.
4949

50-
During inital login user features are synced through a queue which keeps them as up to date as possible
50+
You can add the following trait `Clearlyip\LaravelFlagsmith\Concerns\HasFlagss` to your user model to fulfill the requirements of `UserFlags`
5151

52-
#### List All Features for a User
52+
During initial login user flags are synced through a queue which keeps them as up to date as possible
53+
54+
#### Get All Flags for a User
5355

5456
```php
5557
$user = Auth::user();
56-
$features = $user->getFeatures();
58+
$flags = $user->getFlags();
5759
```
5860

59-
### Check if feature is enabled for a user
61+
### Check if flag is enabled for a user
6062

61-
An optional second parameter can be added as the default if the feature does not exist
63+
An optional second parameter can be added as the default if the flag does not exist
6264

6365
```php
6466
$user = Auth::user();
65-
$features = $user->isFeatureEnabled('foo');
67+
$flags = $user->isFlagEnabled('foo');
6668
```
6769

68-
#### Get a Features value for a User
70+
#### Get a Flag value for a User
6971

70-
An optional second parameter can be added as the default if the feature does not exist
72+
An optional second parameter can be added as the default if the flag does not exist
7173

7274
```php
7375
$user = Auth::user();
74-
$features = $user->getFeatureValue('foo');
76+
$vakue = $user->getFlagValue('foo');
7577
```
7678

7779
### Accessing

composer.json

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=7.4",
14-
"laravel/framework": ">=8.0",
15-
"flagsmith/flagsmith-php-client": "^2.0"
13+
"php": "^8.2",
14+
"laravel/framework": "^10.44.0 || ^11.0",
15+
"flagsmith/flagsmith-php-client": "^4.2.0"
1616
},
1717
"extra": {
1818
"laravel": {
1919
"providers": [
2020
"Clearlyip\\LaravelFlagsmith\\ServiceProvider"
21-
]
21+
],
22+
"aliases": {
23+
"Flag": "Clearlyip\\LaravelFlagsmith\\Facades\\Flag"
24+
}
2225
}
2326
},
2427
"autoload": {
@@ -27,7 +30,43 @@
2730
}
2831
},
2932
"require-dev": {
30-
"guzzlehttp/psr7": "^2.1",
31-
"guzzlehttp/guzzle": "^7.4"
33+
"guzzlehttp/psr7": "^2.6.2",
34+
"guzzlehttp/guzzle": "^7.8.1",
35+
"orchestra/testbench": "^8.22.0",
36+
"phpunit/phpunit": "^10.5.13",
37+
"vimeo/psalm": "^5.23.1",
38+
"squizlabs/php_codesniffer": "^3.9.0"
39+
},
40+
"config": {
41+
"allow-plugins": {
42+
"php-http/discovery": true
43+
}
44+
},
45+
"autoload-dev": {
46+
"psr-4": {
47+
"CIP\\Tests\\": "tests/",
48+
"Workbench\\App\\": "workbench/app/",
49+
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
50+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
51+
}
52+
},
53+
"scripts": {
54+
"post-autoload-dump": [
55+
"@clear",
56+
"@prepare"
57+
],
58+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
59+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
60+
"build": "@php vendor/bin/testbench workbench:build --ansi",
61+
"serve": [
62+
"Composer\\Config::disableProcessTimeout",
63+
"@build",
64+
"@php vendor/bin/testbench serve"
65+
],
66+
"test": "XDEBUG_MODE=coverage phpunit --configuration phpunit.xml",
67+
"test:filter": "XDEBUG_MODE=coverage,debug phpunit --configuration phpunit.xml --filter",
68+
"psalm": "psalm",
69+
"phpcs": "phpcs --standard=phpcs.xml",
70+
"phpcbf": "phpcbf --standard=phpcs.xml"
3271
}
3372
}

package.json

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
{
2-
"name": "@clearlyip/laravel-flagsmith",
3-
"version": "1.0.0",
4-
"main": "index.js",
5-
"directories": {
6-
"test": "tests"
7-
},
8-
"private": true,
9-
"repository": {
10-
"type": "git",
11-
"url": "ssh://[email protected]:clearlyip/laravel-flagsmith.git"
12-
},
13-
"author": "",
14-
"license": "BSD 3-Clause",
15-
"dependencies": {
16-
"@prettier/plugin-php": "^0.14.3",
17-
"prettier": "^2.1.2"
2+
"devDependencies": {
3+
"@prettier/plugin-php": "^0.21.0",
4+
"prettier": "^3.1.0"
185
}
196
}

phpcs.xml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Custom Standard" namespace="MyProject\CS\Standard">
3+
<!-- https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset -->
4+
<description>ClearlyIP coding standards</description>
5+
<file>./src</file>
6+
<exclude-pattern>*/data/*</exclude-pattern>
7+
<exclude-pattern>*/node_modules/*</exclude-pattern>
8+
<exclude-pattern>*/vendor/*</exclude-pattern>
9+
<exclude-pattern>*/tests/*</exclude-pattern>
10+
<arg value="sp"/>
11+
12+
<rule ref="PSR12"/>
13+
14+
<!-- This option is good for inspecting extended methods, however using ReflectionClass may cause phpcs crashes while editing (not possible to catch FatalError). -->
15+
<!-- <autoload>./vendor/autoload.php</autoload> -->
16+
<!-- https://github.com/gskema/phpcs-type-sniff -->
17+
<!--
18+
<rule ref="./vendor/gskema/phpcs-type-sniff/src/Sniffs/CompositeCodeElementSniff.php">
19+
<properties>
20+
<property name="useReflection" value="true"/>
21+
</properties>
22+
<exclude name="Gskema.Sniffs.CompositeCodeElement.FqcnMethodSniff"/>
23+
<exclude name="Gskema.Sniffs.CompositeCodeElement.FqcnConstSniff"/>
24+
</rule>
25+
-->
26+
27+
<rule ref="Generic.Files.LineLength.TooLong">
28+
<!-- This is enforced by prettier -->
29+
<exclude name="Generic.Files.LineLength.TooLong"/>
30+
</rule>
31+
32+
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration">
33+
<!-- This will break as a result of prettier so dont enforce it -->
34+
<exclude name="Squiz.ControlStructures.ForEachLoopDeclaration.SpacingBeforeAs" />
35+
</rule>
36+
37+
<rule ref="Squiz.ControlStructures.ControlSignature">
38+
<!-- This will break as a result of prettier so dont enforce it -->
39+
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace" />
40+
</rule>
41+
42+
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration">
43+
<!-- This will break as a result of prettier so dont enforce it -->
44+
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.OneParamPerLine" />
45+
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.UseOneParamPerLine" />
46+
</rule>
47+
48+
<rule ref="Generic.WhiteSpace.DisallowTabIndent">
49+
<exclude name="Generic.WhiteSpace.DisallowTabIndent.TabsUsed" />
50+
</rule>
51+
52+
53+
</ruleset>

phpunit.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" failOnRisky="true" failOnWarning="true" colors="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false" beStrictAboutCoverageMetadata="false">
3+
<testsuites>
4+
<testsuite name="default">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<coverage>
9+
<report>
10+
<clover outputFile="output/coverage/cov.xml"/>
11+
<html outputDirectory="output/coverage/html"/>
12+
<text outputFile="php://stdout" showUncoveredFiles="false"/>
13+
</report>
14+
</coverage>
15+
<logging>
16+
<testdoxHtml outputFile="output/logging/testsDox.html"/>
17+
<testdoxText outputFile="output/logging/testsDox.txt"/>
18+
</logging>
19+
<source>
20+
<include>
21+
<directory suffix=".php">src</directory>
22+
</include>
23+
</source>
24+
<php>
25+
<server name="APP_ENV" value="testing"/>
26+
<server name="BCRYPT_ROUNDS" value="4"/>
27+
<server name="CACHE_DRIVER" value="array"/>
28+
<server name="MAIL_MAILER" value="array"/>
29+
<server name="QUEUE_CONNECTION" value="sync"/>
30+
<server name="SESSION_DRIVER" value="array"/>
31+
<server name="TELESCOPE_ENABLED" value="false"/>
32+
<server name="DB_CONNECTION" value="testing"/>
33+
<server name="REDIS_CLIENT" value="mock"/>
34+
<server name="APP_KEY" value="base64:+E3QzOdQTPu20d4VY93Oh99eVFhZmbA8D+mpj+r7wJs=" />
35+
</php>
36+
</phpunit>

0 commit comments

Comments
 (0)