Commit 8ceaade4 authored by Ade Attwood's avatar Ade Attwood

Initial Commit

parents
#
# DATABASE_CONFIG
#
DB_NAME=db
DB_PASSWORD=db
DB_USER=db
DB_HOST=database
#
# Yii config variables
#
YII_ENV=dev
YII_DEBUG=true
YII_COOKIE_KEY="MY_COOKIE_KEY"
YII_FILE_TRANSPORT=true
# Created by https://www.gitignore.io/api/vim,linux,macos,phpunit,windows,composer,phpcodesniffer,dotenv
# Edit at https://www.gitignore.io/?templates=vim,linux,macos,phpunit,windows,composer,phpcodesniffer,dotenv
### Composer ###
composer.phar
/vendor/
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
### dotenv ###
.env
### Linux ###
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### PHPCodeSniffer ###
# CodeSniffer
/vendor/*
/wpcs/*
### PHPUnit ###
# Covers PHPUnit
# Reference: https://phpunit.de/
# Generated files
.phpunit.result.cache
# PHPUnit
/app/phpunit.xml
/phpunit.xml
# Build data
/build/
### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
Sessionx.vim
# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
# Coc configuration directory
.vim
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/vim,linux,macos,phpunit,windows,composer,phpcodesniffer,dotenv
#!/usr/bin/env php
<?php
declare(strict_types = 1);
defined('APP_ENV') or define('APP_ENV', 'console');
$config = include dirname(__DIR__).'/bootstrap.php';
exit((new yii\console\Application($config))->run());
<?php
use Dotenv\Environment\Adapter\ArrayAdapter;
use Dotenv\Environment\DotenvFactory;
use Dotenv\Loader;
include __DIR__ . '/vendor/autoload.php';
if (!function_exists('env')) {
function env(string $var, $default = null)
{
if (!isset($GLOBALS['__dot_env'])) {
$envDir = __DIR__;
if (!is_file($envDir . '/.env')) {
$envDir = dirname($envDir);
}
$loader = new Loader(
[$envDir . '/.env'],
new DotenvFactory([new ArrayAdapter])
);
$loader->load();
$GLOBALS['__dot_env'] = $loader;
} else {
$loader = $GLOBALS['__dot_env'];
}
return $loader->getEnvironmentVariable($var) ?? $default;
}
}
defined('YII_DEBUG') or define('YII_DEBUG', env('YII_DEBUG', false));
defined('YII_ENV') or define('YII_ENV', env('YII_ENV', 'prod'));
if (YII_ENV === 'dev') {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
if (YII_ENV !== 'test') {
include __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
}
return include __DIR__ . '/config.php';
{
"name": "adeattwood/rapid-reset-boilerplate",
"description": "Boilerplate application for a basic rest API using Rapid Rest",
"type": "project",
"minimum-stability": "dev",
"prefer-stable": true,
"authors": [
{
"name": "Ade Attwood",
"email": "code@adeattwood.co.uk"
}
],
"config": {
"store-auths": false,
"process-timeout": 1800,
"fxp-asset": {
"enabled": false
}
},
"repositories": [
{
"url": "https://git.baln.co.uk/rapid-rest/rapid-rest.git",
"type": "git"
},
{
"type": "composer",
"url": "https://asset-packagist.org"
}
],
"require": {
"adeattwood/rapid-rest": "master",
"yiisoft/yii2-swiftmailer": "~2.0.0",
"vlucas/phpdotenv": "^3.6"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"squizlabs/php_codesniffer": "^3.3",
"symfony/var-dumper": "^3.4",
"yiisoft/yii2-debug": "~2.0.0",
"spatie/phpunit-snapshot-assertions": "^2.0"
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
declare(strict_types = 1);
$config = [
'id' => 'rr',
'name' => 'Rapid Rest App',
'basePath' => __DIR__,
'bootstrap' => ['log', 'api'],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
'@web' => '@app/web',
'@webroot' => '@app/web',
'@tests' => '@app/tests',
],
'modules' => [
'api' => ['class' => 'adeattwood\rapid_rest\Module'],
],
'components' => [
'cache' => ['class' => 'yii\caching\FileCache'],
'assetManager' => ['bundles' => false],
'mailer' => [
'class' => 'adeattwood\yii2\mailer\Mailer',
'useFileTransport' => env('YII_FILE_TRANSPORT', false),
],
'log' => [
'traceLevel' => (YII_DEBUG) ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'view' => ['class' => 'yii\web\View'],
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host='.env('DB_HOST', 'localhost').';dbname='.env('DB_NAME'),
'username' => env('DB_USER'),
'password' => env('DB_PASSWORD'),
'enableSchemaCache' => env('DB_CACHE'),
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [],
],
],
'params' => [],
];
if (APP_ENV === 'web') {
$config['components']['request'] = [
'cookieValidationKey' => env('YII_COOKIE_KEY'),
'parsers' => ['application/json' => 'yii\web\JsonParser']
];
$config['components']['errorHandler'] = ['errorAction' => 'api/default/error'];
}
if (APP_ENV === 'console') {
$config['controllerNamespace'] = 'app\commands';
}
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
if (class_exists('yii\debug\Module')) {
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
'allowedIPs' => ['127.0.0.1', '::1', '*'],
];
}
if (class_exists('yii\gii\Module')) {
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
'allowedIPs' => ['127.0.0.1', '::1', '*'],
];
}
}
return $config;
version: '2'
services:
database:
image: mysql:5.7
networks:
- network
ports:
- 3306:3306
environment:
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
volumes:
- data:/var/lib/mysql
nginx:
image: nginx
volumes:
- ./:/var/www
- ./nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- fpm
networks:
- network
ports:
- 8888:80
fpm:
image: registry.gitlab.com/adeattwood/docker-php:7.2-fpm
depends_on:
- database
volumes:
- ./:/var/www
working_dir: /var/www
networks:
- network
php-cli:
image: registry.gitlab.com/adeattwood/docker-php:7.2-cli
depends_on:
- database
volumes:
- ./:/var/www
working_dir: /var/www
networks:
- network
networks:
network:
driver: bridge
volumes:
data:
driver: local
server {
server_name localhost;
listen 80;
charset utf-8;
client_max_body_size 128M;
root /var/www/web;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ ^/assets/.*\.php$ {
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass fpm:9000;
try_files $uri = 404;
}
}
openapi: 3.0.0
info:
version: 1.0.0
title: Rapid Rest Boilerplate
description: Boilerplate application for a basic rest API using Rapid Rest
servers:
- url: 'http://localhost:8888'
description: The local development server
paths:
/api/v1/things:
get:
operationId: getThing
summary: Gets the thing
x-rr-resource: '#/components/schemas/Thing'
responses:
200:
description: Success response
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/RestResponse'
- type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/Thing'
404:
description: Not found
content:
application/json:
schema:
$ref: '#/components/schemas/RestError'
default:
description: Unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/RestError'
components:
schemas:
Thing:
type: object
properties:
id:
type: integer
format: primaryKey
readOnly: true
name:
type: string
RestResponse:
type: object
x-rr-db: false
properties:
_meta:
type: object
properties:
currentPage:
type: number
pageCount:
type: number
perPage:
type: number
totalCount:
type: number
_links:
type: object
properties:
last:
type: object
properties:
href:
type: string
format: url
next:
type: object
properties:
href:
type: string
format: url
self:
type: object
properties:
href:
type: string
format: url
RestError:
type: object
x-rr-db: false
properties:
name:
type: string
message:
type: string
code:
type: integer
status:
type: integer
type:
type: string
RestValidationErrors:
type: array
x-rr-db: false
items:
type: object
properties:
field:
type: string
message:
type: string
*
!.gitignore
\ No newline at end of file
<?php
declare(strict_types = 1);
defined('APP_ENV') or define('APP_ENV', 'web');
$config = include dirname(__DIR__).'/bootstrap.php';
(new yii\web\Application($config))->run();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment