Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gammamatrix authored Feb 17, 2024
1 parent b91d787 commit b3566f7
Show file tree
Hide file tree
Showing 36 changed files with 302 additions and 1,452 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
with:
level: 9
php_version: "8.2"
path: config/ database/ lang/ src/ tests/Feature/ tests/Unit/
path: config/ database/ src/ tests/Feature/ tests/Unit/
- name: Stopping timer
if: ${{ !cancelled() }}
id: timer_end
Expand Down
102 changes: 7 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

[![Playground CI Workflow](https://github.com/gammamatrix/playground/actions/workflows/ci.yml/badge.svg?branch=develop)](https://raw.githubusercontent.com/gammamatrix/playground/testing/develop/testdox.txt)
[![Test Coverage](https://raw.githubusercontent.com/gammamatrix/playground/testing/develop/coverage.svg)](tests)
[![PHPStan Level 3 src and tests](https://img.shields.io/badge/PHPStan-level%203-brightgreen)](.github/workflows/ci.yml#L120)
[![PHPStan Level 9 src and tests](https://img.shields.io/badge/PHPStan-level%209-brightgreen)](.github/workflows/ci.yml#L120)

This is the base package for Playground.

This package provides controllers, policies, migrations, models, requests, views and more for building [Laravel](https://laravel.com/docs/10.x) packages.
- Playground defaults to using [Laravel ordered UUIDs](https://laravel.com/docs/10.x/strings#method-str-ordered-uuid) for primary keys.
This package provides model handling for [Laravel](https://laravel.com/docs/10.x) packages.
- Playground allows using [Laravel ordered UUIDs](https://laravel.com/docs/10.x/strings#method-str-ordered-uuid) for primary keys.
- The configuration in Playground and subpackages permits defining the user model, table and primary key type: `increments` or `uuid`.
- Packages are compatible and tested with and without: middleware, roles, policies, privileges, Sanctum...

Read more on using Playground with available packages [on the Playground wiki.](https://github.com/gammamatrix/playground/wiki)

Using Blade for the UI is optional, any frontend should be able to work with endpoints using JSON.

## Installation

You can install the package via composer:
Expand All @@ -32,96 +30,16 @@ php artisan vendor:publish --provider="GammaMatrix\Playground\ServiceProvider" -

See the contents of the published config file: [config/playground.php](config/playground.php)

### Environment Variables

#### Authentication and Authorization

| env() | config() |
|-----------------------------------|----------------------------------|
| `PLAYGROUND_USER` | `playground.user` |
| `PLAYGROUND_USER_ID` | `playground.user_id` |
| `PLAYGROUND_USER_TABLE` | `playground.user_table` |
| `PLAYGROUND_AUTH_SANCTUM` | `playground.auth.sanctum` |
| `PLAYGROUND_AUTH_VERIFY` | `playground.auth.verify` |
| `PLAYGROUND_AUTH_HAS_PRIVILEGE` | `playground.auth.hasPrivilege` |
| `PLAYGROUND_AUTH_USER_PRIVILEGES` | `playground.auth.userPrivileges` |
| `PLAYGROUND_AUTH_HAS_ROLE` | `playground.auth.hasRole` |
| `PLAYGROUND_AUTH_USER_ROLE` | `playground.auth.hasRole` |
| `PLAYGROUND_AUTH_USER_ROLES` | `playground.auth.userRoles` |

#### Loading

| env() | config() |
|--------------------------|--------------------------|
| `PLAYGROUND_LOAD_ROUTES` | `playground.load.routes` |
| `PLAYGROUND_LOAD_VIEWS` | `playground.load.views` |

`PLAYGROUND_LOAD_ROUTES` must be enabled to load the routes in the application (unless published to your app - the control for this is in the [ServiceProvider.php](src/ServiceProvider.php))

#### Routes

All routes are disabled by default in the base Playground package.

| env() | config() |
|-------------------------------|-------------------------------|
| `PLAYGROUND_ROUTES_ABOUT` | `playground.routes.about` |
| `PLAYGROUND_ROUTES_BOOTSTRAP` | `playground.routes.bootstrap` |
| `PLAYGROUND_ROUTES_DASHBOARD` | `playground.routes.dashboard` |
| `PLAYGROUND_ROUTES_HOME` | `playground.routes.home` |
| `PLAYGROUND_ROUTES_SITEMAP` | `playground.routes.sitemap` |
| `PLAYGROUND_ROUTES_THEME` | `playground.routes.theme` |
| `PLAYGROUND_ROUTES_WELCOME` | `playground.routes.welcome` |

### UI

| env() | config() |
|-------------------------------|-------------------------------|
| `PLAYGROUND_LAYOUT` | `playground.layout` |
| `PLAYGROUND_VIEW` | `playground.view` |
| `PLAYGROUND_PACKAGES` | `playground.packages` |
| `PLAYGROUND_DASHBOARD_ENABLE` | `playground.dashboard.enable` |
| `PLAYGROUND_DASHBOARD_GUEST` | `playground.dashboard.guest` |
| `PLAYGROUND_DASHBOARD_USER` | `playground.dashboard.user` |
| `PLAYGROUND_DASHBOARD_VIEW` | `playground.dashboard.view` |
| `PLAYGROUND_SITEMAP_ENABLE` | `playground.sitemap.enable` |
| `PLAYGROUND_SITEMAP_GUEST` | `playground.sitemap.guest` |
| `PLAYGROUND_SITEMAP_USER` | `playground.sitemap.user` |
| `PLAYGROUND_SITEMAP_VIEW` | `playground.sitemap.view` |


## UI Layouts

NOTE: Using Blade is not required to use Playground, it just an option, such as Vue, React or TypeScript.

The configuration in [config/playground.php](config/playground.php) has a section for frontend assets. If you would like to add more assets, CSS or JavaScript, publish the configuration and add them to the `libs` section.
## `artisan about`

Assets may be loaded into either head or they will be added to the end of the body.

By default, the following libraries are loaded.

- `favicon`: `/favicon.ico`
- [Nunito](https://fonts.google.com/specimen/Nunito): Loaded from Google Fonts.
- [Bootstrap: 5.3.2](https://getbootstrap.com/docs/5.3/)
- [FontAwesome: 6.4.2](https://fontawesome.com/search?o=r&m=free)
- [Vue 3 - https://unpkg.com/vue@3](https://vuejs.org/)
- `/vendor/playground.js` A small library to be loaded for Blade UI usage. Needs to be published.

Optionally, a page may load:
- [CKEditor 5](https://ckeditor.com/ckeditor-5/) an advanced WYSIWYG editor for forms.


### Assets
Playground provides information in the `artisan about` command.

If you are using the Playground Blade UI, you can publish the JS assets with:
```bash
php artisan vendor:publish --provider="GammaMatrix\Playground\ServiceProvider" --tag="playground-js"
```
- These Javascript assets, [resources/js/playground.js](resources/js/playground.js), provide simple helpers for features such as Bootstrap Form Validation and loading CKEditor for textarea elements on forms.
<img src="resources/docs/artisan-about-playground.png" alt="screenshot of artisan about command with Playground.">


## Migrations

The migrations provided in this package are used for [PHPunit 10](https://docs.phpunit.de/en/10.4/) feature testing with [Orchestra Testbench](https://packages.tools/testbench.html).
The migrations provided in this package are used for [PHPunit 10](https://docs.phpunit.de/en/10.5/) feature testing with [Orchestra Testbench](https://packages.tools/testbench.html).
- They will not be exported in software builds.

## Testing
Expand All @@ -130,12 +48,6 @@ The migrations provided in this package are used for [PHPunit 10](https://docs.p
composer test
```

## About

Playground provides information in the `artisan about` command.

<img src="resources/docs/artisan-about-playground.png" alt="screenshot of artisan about command with Playground.">

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Expand Down
63 changes: 24 additions & 39 deletions config/playground.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,36 @@
<?php

return [
'user' => env('PLAYGROUND_USER', 'App\\Models\\User'),
'user_id' => env('PLAYGROUND_USER_ID', 'uuid'),
'user_table' => env('PLAYGROUND_USER_TABLE', 'users'),
'packages' => is_string(env('PLAYGROUND_PACKAGES', 'playground')) ? array_map('trim', explode(',', env('PLAYGROUND_PACKAGES', 'playground'))) : [],
// 'auth' => [
// /**
// * Privileges checks in this order:
// * - Sanctum: HasApiTokens
// * - method_exists: hasPrivilege
// *
// * @var string $verify roles|privileges
// */
// 'verify' => env('PLAYGROUND_AUTH_VERIFY', 'privileges'),
// // 'verify' => env('PLAYGROUND_AUTH_VERIFY', 'roles'),
// 'token' => [
// 'name' => 'app',
// ],
// 'sanctum' => (bool) env('PLAYGROUND_AUTH_SANCTUM', false),
// 'hasPrivilege' => (bool) env('PLAYGROUND_AUTH_HAS_PRIVILEGE', false),
// 'userPrivileges' => (bool) env('PLAYGROUND_AUTH_USER_PRIVILEGES', false),
// 'hasRole' => (bool) env('PLAYGROUND_AUTH_HAS_ROLE', false),
// 'userRole' => (bool) env('PLAYGROUND_AUTH_USER_ROLE', false),
// 'userRoles' => (bool) env('PLAYGROUND_AUTH_USER_ROLES', false),
// ],
'date' => [
'sql' => env('PLAYGROUND_DATE_SQL', 'Y-m-d H:i:s'),
],
'purifier' => [
'iframes' => env(
'PLAYGROUND_PURIFIER_IFRAMES',
'%^(https?:)?(\/\/www\.youtube(?:-nocookie)?\.com\/embed\/|\/\/player\.vimeo\.com\/)%'
),
'path' => env('PLAYGROUND_PURIFIER_PATH', ''),
],

/*
|--------------------------------------------------------------------------
| Password Settings for Testing
| Packages
|--------------------------------------------------------------------------
|
| The array of packages from PLAYGROUND_PACKAGES will be listed in the
| Playground section in artisan:about.
|
| - These packages will have their respective sitemaps loaded, if applicable.
|
| NOTE: PLAYGROUND_AUTH_PACKAGES may also be defined to load abilities.
|
*/

'testing' => [
'password' => env('PLAYGROUND_TESTING_PASSWORD'),
'hashed' => (bool) env('PLAYGROUND_TESTING_HASHED', false),
],
'packages' => is_string(env('PLAYGROUND_PACKAGES', 'playground')) ? array_map(
'trim',
explode(',', env('PLAYGROUND_PACKAGES', 'playground'))
) : [],

/*
|--------------------------------------------------------------------------
| Date
|--------------------------------------------------------------------------
|
| PLAYGROUND_DATE_SQL is used to format dates for SQL handling. Where possible
| Illuminate\Support\Carbon is use to handle dates, including formatting.
*/

'date' => [
'sql' => env('PLAYGROUND_DATE_SQL', 'Y-m-d H:i:s'),
],
];
12 changes: 10 additions & 2 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ class UserFactory extends Factory
public function definition(): array
{
if (empty(static::$password)) {
$password = config('playground.testing.password');
$password = config('auth.testing.password');
$test_password_hashed = config('auth.testing.hashed');

if (empty($password) || ! is_string($password)) {
$password = md5(Carbon::now()->format('c'));
$test_password_hashed = false;
}

if (! $test_password_hashed) {
$password = Hash::make($password);
}
static::$password = Hash::make($password);

static::$password = $password;
}

return [
Expand Down
27 changes: 0 additions & 27 deletions lang/en/auth.php

This file was deleted.

26 changes: 0 additions & 26 deletions lang/en/pagination.php

This file was deleted.

14 changes: 0 additions & 14 deletions lang/en/playground.php

This file was deleted.

14 changes: 0 additions & 14 deletions lang/en/validation.php

This file was deleted.

1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ parameters:
paths:
- config
- database
- lang
- src
- tests

Expand Down
24 changes: 12 additions & 12 deletions phpunit.xml.dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
stopOnSkipped="false"
Expand Down Expand Up @@ -37,20 +37,20 @@
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
<report>
<clover outputFile="tests/logs/clover.xml"/>
<cobertura outputFile="tests/logs/cobertura.xml"/>
<crap4j outputFile="tests/logs/crap4j.xml" threshold="50"/>
<html outputDirectory="tests/logs/html" lowUpperBound="50" highLowerBound="90"/>
<php outputFile="tests/logs/coverage.php"/>
<text outputFile="tests/logs/coverage.txt" showUncoveredFiles="false" showOnlySummary="true"/>
<xml outputDirectory="tests/logs/xml"/>
<clover outputFile="output/clover.xml" />
<cobertura outputFile="output/cobertura.xml" />
<crap4j outputFile="output/crap4j.xml" threshold="50" />
<html outputDirectory="output/html" lowUpperBound="50" highLowerBound="90" />
<php outputFile="output/coverage.php" />
<text outputFile="output/coverage.txt" showUncoveredFiles="false" showOnlySummary="true" />
<xml outputDirectory="output/xml" />
</report>
</coverage>
<logging>
<junit outputFile="tests/logs/junit.xml"/>
<teamcity outputFile="tests/logs/teamcity.txt"/>
<testdoxHtml outputFile="tests/logs/testdox.html"/>
<testdoxText outputFile="tests/logs/testdox.txt"/>
<junit outputFile="output/junit.xml" />
<teamcity outputFile="output/teamcity.txt" />
<testdoxHtml outputFile="output/testdox.html" />
<testdoxText outputFile="output/testdox.txt" />
</logging>
<source>
<include>
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
stopOnSkipped="false"
Expand Down
Binary file modified resources/docs/artisan-about-playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b3566f7

Please sign in to comment.