Skip to content

Commit

Permalink
Update Package
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhall17 committed Aug 6, 2020
1 parent 9f0ac8d commit a3fce95
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 91 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Check & fix styling

on: [push]

jobs:
style:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Fix style
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs --allow-risky=yes

- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch

- name: Commit changes
uses: stefanzweifel/[email protected]
with:
commit_message: Fix styling
branch: ${{ steps.extract_branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45 changes: 45 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Run tests

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [7.2, 7.3, 7.4]
laravel: [6.*, 7.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 7.*
testbench: 5.*
- laravel: 6.*
testbench: 4.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ composer.lock
docs
vendor
coverage
.phpunit.result.cache
.phpunit.result.cache
node_modules
.idea
38 changes: 38 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->notPath('bootstrap/*')
->notPath('storage/*')
->notPath('storage/*')
->notPath('resources/view/mail/*')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline_array' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
]
])
->setFinder($finder);
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to `laravel-setting` will be documented in this file

## 1.0.7 - 2020-04-07

- Models into Models folder
- GitHub Actions for tests and format
- Updated Docs

## 1.0.6 - 2020-04-07

- Allow PHP 7.2
Expand Down
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
# Laravel Setting Package

Setting boilerplate
## Configs in the databsae

![Header Image](https://github.com/MacsiDigital/repo-design/raw/master/laravel-setting/header.png)

<p align="center">
<a href="https://github.com/MacsiDigital/laravel-setting/actions?query=workflow%3Atests"><img src="https://github.com/MacsiDigital/laravel-setting/workflows/Run%20tests/badge.svg" style="max-width:100%;"></a>
<a href="https://packagist.org/packages/macsidigital/laravel-setting"><img src="https://img.shields.io/packagist/v/macsidigital/laravel-setting.svg?style=flat-square"/></a>
<a href="https://packagist.org/packages/macsidigital/laravel-setting"><img src="https://img.shields.io/packagist/dt/macsidigital/laravel-setting.svg?style=flat-square"/></a>
</p>

A setting package to save settings to teh db and access them through config.

## Installation

This package can be used in Laravel 6.0 or higher.

You can install the package via composer:

```bash
composer require macsidigital/laravel-setting
```

You must publish the migration with:

``` bash
php artisan vendor:publish --tag="setting-migrations"
```

## Usage

You can save groups and settings like so
Expand Down Expand Up @@ -38,15 +56,7 @@ foreach(Group::where('identifier', 'membership')->first()->items){
}
```

To set in config do the following

``` php
foreach(Group::where('identifier', 'membership')->first()->items as $item){
config(['membership.'.$item->key => $item->value]);
}
```

#### Autoloading
## Autoloading

There is also an autoload field which if set will automatically load the settings into config

Expand All @@ -57,10 +67,11 @@ $group = Group::create([
'description' => "Test Settings and other things",
'autoload' => true
]);
$item = Item::make(['key' => 'mailchimp.api', 'name' => 'Mailchimp Key', 'description' => 'Your Mailchimp API key so we can enable communication with your Mailchimp account']);
$item = Item::make(['key' => 'mailchimp.api', 'name' => 'Mailchimp Key', 'description' => 'Your Mailchimp API key so we can enable communication with your Mailchimp account', 'autoload' => true]);
$group->items()->save($item);

Item::create(['key' => 'mailchimp.api', 'name' => 'Mailchimp Key', 'description' => 'Your Mailchimp API key so we can enable communication with your Mailchimp account', 'autoload' => true]);
// Access with
config('test.mailchimp.api');
```

These will be automatically loaded when the Setting Service Provider is run.
Expand All @@ -82,4 +93,4 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "",
"keywords": [
"macsidigital",
"laravel-setting"
"laravel-setting",
"settings",
"configs"
],
"homepage": "https://github.com/macsidigital/laravel-setting",
"type": "library",
Expand All @@ -19,8 +21,11 @@
"illuminate/support": "^6.0|^7.0"
},
"require-dev": {
"orchestra/testbench": "^5.0",
"phpunit/phpunit": "^9.0"
"friendsofphp/php-cs-fixer": "^2.16",
"orchestra/testbench": "^4.0|^5.0",
"phpunit/phpunit": "^8.0|^9.0",
"psalm/plugin-laravel": "^1.2",
"vimeo/psalm": "^3.11"
},
"autoload": {
"psr-4": {
Expand All @@ -33,9 +38,10 @@
}
},
"scripts": {
"psalm": "vendor/bin/psalm",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"

"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
},
"setting": {
"sort-packages": true
Expand Down
6 changes: 3 additions & 3 deletions config/setting.php → config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
return [
'models' => [

'group' => Setting\Group::class,
'group' => Setting\Models\Group::class,

'item' => Setting\Item::class,
'item' => Setting\Models\Item::class,

],
'table_names' => [
Expand All @@ -26,4 +26,4 @@

'items' => 'setting_items',
]
];
];
4 changes: 2 additions & 2 deletions database/factories/GroupFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Setting\Group;
use Setting\Models\Group;
use Illuminate\Support\Str;
use Faker\Generator as Faker;

Expand All @@ -11,4 +11,4 @@
'description' => $faker->sentence,
'autoload' => false
];
});
});
4 changes: 2 additions & 2 deletions database/factories/ItemFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Setting\Item;
use Setting\Models\Item;
use Illuminate\Support\Str;
use Faker\Generator as Faker;

Expand All @@ -13,4 +13,4 @@
'value' => $faker->word,
'autoload' => false
];
});
});
6 changes: 1 addition & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<testsuite name="Laravel Setting Test">
<directory>tests</directory>
</testsuite>
</testsuites>
Expand All @@ -19,10 +19,6 @@
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
</logging>
<php>
<env name="DB_CONNECTION" value="testing" />
</php>
Expand Down
25 changes: 25 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<psalm
errorLevel="5"
findUnusedVariablesAndParams="false"
findUnusedCode="false"
resolveFromConfigFile="true"
useDocblockPropertyTypes="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>

<issueHandlers>
</issueHandlers>

<plugins>
<pluginClass class="Psalm\LaravelPlugin\Plugin"/>
</plugins>
</psalm>
4 changes: 2 additions & 2 deletions src/Contracts/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

interface Group
{
public function items();
}
public function items();
}
4 changes: 2 additions & 2 deletions src/Contracts/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

interface Item
{
public function group();
}
public function group();
}
1 change: 0 additions & 1 deletion src/Facades/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class Group extends Facade
{

protected static function getFacadeAccessor()
{
return 'setting.group';
Expand Down
1 change: 0 additions & 1 deletion src/Facades/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class Item extends Facade
{

protected static function getFacadeAccessor()
{
return 'setting.item';
Expand Down
Loading

0 comments on commit a3fce95

Please sign in to comment.