Skip to content

Commit 91f530c

Browse files
committed
initial commit
1 parent b0933a7 commit 91f530c

26 files changed

+281
-515
lines changed

.github/CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
Please read and understand the contribution guide before creating an issue or pull request.
6+
7+
## Etiquette
8+
9+
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10+
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11+
extremely unfair for them to suffer abuse or anger for their hard work.
12+
13+
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14+
world that developers are civilized and selfless people.
15+
16+
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17+
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18+
19+
## Viability
20+
21+
When requesting or submitting new features, first consider whether it might be useful to others. Open
22+
source projects are used by many developers, who may have entirely different needs to your own. Think about
23+
whether or not your feature is likely to be used by other users of the project.
24+
25+
## Procedure
26+
27+
Before filing an issue:
28+
29+
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30+
- Check to make sure your feature suggestion isn't already present within the project.
31+
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32+
- Check the pull requests tab to ensure that the feature isn't already in progress.
33+
34+
Before submitting a pull request:
35+
36+
- Check the codebase to ensure that your feature doesn't already exist.
37+
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38+
39+
## Requirements
40+
41+
If the project maintainer has any additional requirements, you will find them listed here.
42+
43+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The standard can be enforced by running the `composer lint` console command.
44+
45+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46+
47+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48+
49+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
50+
51+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52+
53+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54+
55+
**Happy coding**!

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: [fabio-ivona, defstudio]
2+
custom: ["https://paypal.me/bdmstore"]

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: Ask a question
4-
url: https://github.com/:vendor_name/:package_name/discussions/new?category=q-a
4+
url: https://github.com/defstudio/enum-features/discussions/new?category=q-a
55
about: Ask the community for help
66
- name: Request a feature
7-
url: https://github.com/:vendor_name/:package_name/discussions/new?category=ideas
7+
url: https://github.com/defstudio/enum-features/discussions/new?category=ideas
88
about: Share ideas for new features
99
- name: Report a security issue
10-
url: https://github.com/:vendor_name/:package_name/security/policy
10+
url: https://github.com/defstudio/enum-features/security/policy
1111
about: Learn how to notify us for sensitive bugs

.github/SECURITY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Security Policy
2+
3+
If you have found any issue regarding security, please send an email [report@defstudio.it](mailto:report@defstudio.it) instead of using the issue tracker and we will quickly work on it.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Changelog
22

3-
All notable changes to `:package_name` will be documented in this file.
3+
All notable changes to `enum-features` will be documented in this file.

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) :vendor_name <author@domain.com>
3+
Copyright (c) defstudio <fabio.ivona@defstudio.it>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 88 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,111 @@
1-
# :package_description
2-
3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
4-
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain)
5-
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
6-
[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
7-
<!--delete-->
8-
---
9-
This repo can be used to scaffold a Laravel package. Follow these steps to get started:
10-
11-
1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton.
12-
2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files.
13-
3. Have fun creating your package.
14-
4. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course.
15-
---
16-
<!--/delete-->
17-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
1+
# Enum Features
182

19-
## Support us
20-
21-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/:package_name.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/:package_name)
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/defstudio/enum-features.svg?style=flat-square)](https://packagist.org/packages/defstudio/enum-features)
4+
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/defstudio/enum-features/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/defstudio/enum-features/actions?query=workflow%3Arun-tests+branch%3Amain)
5+
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/defstudio/enum-features/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/defstudio/enum-features/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/defstudio/enum-features.svg?style=flat-square)](https://packagist.org/packages/defstudio/enum-features)
7+
[![License](https://img.shields.io/packagist/l/defstudio/telegraph?style=flat&cacheSeconds=3600)](https://packagist.org/packages/defstudio/enum-features)
8+
[![Twitter Follow](https://img.shields.io/twitter/follow/FabioIvona?label=Follow&style=social)](https://twitter.com/FabioIvona?ref_src=twsrc%5Etfw)
229

23-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
10+
A simple trait to enable a feature system using Enums:
2411

25-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
12+
```php
13+
if(AppFeature::welcome_email->enabled()){
14+
Mail::to($newUser)->send(new WelcomeEmail($newUser));
15+
}
16+
```
2617

2718
## Installation
2819

2920
You can install the package via composer:
3021

3122
```bash
32-
composer require :vendor_slug/:package_slug
23+
composer require defstudio/enum-features
3324
```
3425

35-
You can publish and run the migrations with:
26+
## Usage
3627

37-
```bash
38-
php artisan vendor:publish --tag=":package_slug-migrations"
39-
php artisan migrate
40-
```
28+
Features can be enabled on any enum by using the `DefinesFeatures` trait:
29+
30+
```php
31+
use DefStudio\EnumFeatures\EnumFeatures;
4132

42-
You can publish the config file with:
33+
enum AppFeature
34+
{
35+
use DefinesFeatures; // ← simply add this
4336

44-
```bash
45-
php artisan vendor:publish --tag=":package_slug-config"
37+
case multi_language;
38+
case impersonate;
39+
case welcome_email;
40+
}
4641
```
4742

48-
This is the contents of the published config file:
43+
and each feature can then added to the Laravel application in its `configs/app.php` file:
4944

5045
```php
46+
// config/app.php
47+
5148
return [
52-
];
49+
//..
50+
51+
'features' => [
52+
AppFeature::multi_language,
53+
AppFeature::welcome_email,
54+
]
55+
]
56+
5357
```
5458

55-
Optionally, you can publish the views using
59+
then, in code, a feature could be checked to be enabled:
5660

57-
```bash
58-
php artisan vendor:publish --tag=":package_slug-views"
61+
```php
62+
if(AppFeature::multi_language->enabled()){
63+
//.. multi language specific code
64+
}
5965
```
6066

61-
## Usage
67+
or be disabled
6268

6369
```php
64-
$variable = new VendorName\Skeleton();
65-
echo $variable->echoPhrase('Hello, VendorName!');
70+
if(AppFeature::impersonate->disabled()){
71+
throw(new Exception("Impersonate feature is not enabled"));
72+
}
6673
```
6774

75+
or enforced
76+
77+
```php
78+
79+
AppFeature::impersonate->enforce(); //throws "Feature [impersonate] is not enabled"
80+
81+
```
82+
83+
### Customizing where and how to store enabled features
84+
85+
Enabled features are usually stored in config('app.features'), but this behaviour can be customized by
86+
overriding the `enabledFeatures()` static method inside the enum class:
87+
88+
89+
```php
90+
use DefStudio\EnumFeatures\EnumFeatures;
91+
92+
enum AppFeature
93+
{
94+
use DefinesFeatures; // ← simply add this
95+
96+
case multi_language;
97+
case impersonate;
98+
case welcome_email;
99+
100+
public static function enabledFeatures(): array
101+
{
102+
return config('my_package.features', []); //or load from DB, or every other method
103+
}
104+
}
105+
106+
```
107+
**note:** changing how enabled features are checked makes this package framework agnostic and it can be used in any php applicaiton
108+
68109
## Testing
69110

70111
```bash
@@ -73,21 +114,26 @@ composer test
73114

74115
## Changelog
75116

76-
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
117+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. [Follow Us](https://twitter.com/FabioIvona) on Twitter for more updates about this package.
77118

78119
## Contributing
79120

80-
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
121+
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
81122

82123
## Security Vulnerabilities
83124

84125
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
85126

86127
## Credits
87128

88-
- [:author_name](https://github.com/:author_username)
129+
- [Fabio Ivona](https://github.com/defstudio)
130+
- [def:studio team](https://github.com/defstudio)
89131
- [All Contributors](../../contributors)
90132

91133
## License
92134

93135
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
136+
137+
## Support us
138+
139+
We at [def:studio](https://github.com/defstudio) strongly believe that open source is the foundation of all our business and we try to contribute to it by helping other projects to grow along with developing and maintaining our packages. You can support our work by sponsoring us on [github](https://github.com/sponsors/defstudio)!

composer.json

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
{
2-
"name": ":vendor_slug/:package_slug",
3-
"description": ":package_description",
2+
"name": "defstudio/enum-features",
3+
"description": "A simple trait to enable a feature system using Enums",
44
"keywords": [
5-
":vendor_name",
5+
"defstudio",
66
"laravel",
7-
":package_slug"
7+
"enum-features",
8+
"enums",
9+
"feature"
810
],
9-
"homepage": "https://github.com/:vendor_slug/:package_slug",
11+
"homepage": "https://github.com/defstudio/enum-features",
1012
"license": "MIT",
1113
"authors": [
1214
{
13-
"name": ":author_name",
14-
"email": "author@domain.com",
15+
"name": "Fabio Ivona",
16+
"email": "fabio.ivona@defstudio.it",
1517
"role": "Developer"
1618
}
1719
],
1820
"require": {
1921
"php": "^8.1",
2022
"spatie/laravel-package-tools": "^1.14.0",
21-
"illuminate/contracts": "^10.0"
2223
},
2324
"require-dev": {
2425
"laravel/pint": "^1.0",
@@ -30,18 +31,16 @@
3031
"pestphp/pest-plugin-laravel": "^2.0",
3132
"phpstan/extension-installer": "^1.1",
3233
"phpstan/phpstan-deprecation-rules": "^1.0",
33-
"phpstan/phpstan-phpunit": "^1.0",
34-
"spatie/laravel-ray": "^1.26"
34+
"phpstan/phpstan-phpunit": "^1.0"
3535
},
3636
"autoload": {
3737
"psr-4": {
38-
"VendorName\\Skeleton\\": "src/",
39-
"VendorName\\Skeleton\\Database\\Factories\\": "database/factories/"
38+
"DefStudio\\EnumFeatures\\": "src/"
4039
}
4140
},
4241
"autoload-dev": {
4342
"psr-4": {
44-
"VendorName\\Skeleton\\Tests\\": "tests/"
43+
"DefStudio\\EnumFeatures\\Tests\\": "tests/"
4544
}
4645
},
4746
"scripts": {
@@ -58,16 +57,6 @@
5857
"phpstan/extension-installer": true
5958
}
6059
},
61-
"extra": {
62-
"laravel": {
63-
"providers": [
64-
"VendorName\\Skeleton\\SkeletonServiceProvider"
65-
],
66-
"aliases": {
67-
"Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton"
68-
}
69-
}
70-
},
7160
"minimum-stability": "dev",
7261
"prefer-stable": true
7362
}

config/skeleton.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)