Skip to content

Commit e79353e

Browse files
authored
feat(new-start): Refactored bundle (#1)
* . * . * . * it works propably * readme updated * removed secrets
1 parent c7745d9 commit e79353e

37 files changed

+4183
-1152
lines changed

.env

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# In all environments, the following files are loaded if they exist,
2+
# the latter taking precedence over the former:
3+
#
4+
# * .env contains default values for the environment variables needed by the app
5+
# * .env.local uncommitted file with local overrides
6+
# * .env.$APP_ENV committed environment-specific defaults
7+
# * .env.$APP_ENV.local uncommitted environment-specific overrides
8+
#
9+
# Real environment variables win over .env files.
10+
#
11+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12+
# https://symfony.com/doc/current/configuration/secrets.html
13+
#
14+
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
15+
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
16+
17+
###> symfony/framework-bundle ###
118
APP_ENV=local
2-
APP_SECRET=mrUNGjJoBIWWDoHLuX9KDpYsAduxugyPtX4STBT2
3-
APP_DEBUG=true
19+
APP_SECRET=$ecretf0rt3st
20+
###< symfony/framework-bundle ###

.env.local.dist

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
APP_ENV=local
2+
APP_DEBUG=true
3+
14
# For debugging with xdebug and vscode
25
#
36
# XDEBUG_MODE=develop,debug
@@ -12,7 +15,7 @@
1215
# "type": "php",
1316
# "request": "launch",
1417
# "port": 5902,
15-
# "hostname": "localhost",
18+
# "hostname": "0.0.0.0",
1619
# "pathMappings": {
1720
# "/app/": "${workspaceRoot}"
1821
# }

.env.test

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# define your env variables for the test env here
2+
KERNEL_CLASS='PBaszak\ExtendedApiDoc\Tests\Kernel'
3+
APP_SECRET='$ecretf0rt3st'
4+
SYMFONY_DEPRECATIONS_HELPER=999999
5+
PANTHER_APP_ENV=panther
6+
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots

.github/workflows/ci.yml

+20-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
name: CI
1+
name: Symfony Application Check
22

3-
on: [push]
3+
on: [push, pull_request]
44

55
jobs:
6-
build-test:
7-
runs-on: ubuntu-latest
6+
build-and-test:
7+
runs-on: ubuntu-latest
88

9-
steps:
10-
- uses: actions/checkout@v3
9+
steps:
10+
- name: Checkout Repository
11+
uses: actions/checkout@v3
1112

12-
- uses: php-actions/composer@v6
13+
- name: Running start.sh Script
14+
run: bash start.sh
1315

14-
- name: PHPUnit Tests
15-
uses: php-actions/phpunit@master
16-
with:
17-
configuration: phpunit.xml.dist
18-
exclude_group: integration, performance
16+
- name: Application Verification
17+
run: docker exec php composer cache:clear
18+
19+
- name: Running PHPStan
20+
run: docker exec php composer code:analyse
21+
22+
- name: Running PHP-CS-Fixer
23+
run: docker exec php composer code:fix -- --dry-run --diff -vvv
24+
25+
- name: Running PHPUnit
26+
run: docker exec php composer test:cc

.gitignore

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# directories
2+
.vscode
3+
node_modules
4+
vendor
5+
app
6+
7+
# files
8+
.dockerfile_checksum
9+
.env.local
110

211
###> symfony/framework-bundle ###
312
/.env.local
@@ -9,22 +18,12 @@
918
/vendor/
1019
###< symfony/framework-bundle ###
1120

12-
/.vscode
13-
/node_modules/
14-
/.dockerfile_checksum
15-
1621
###> friendsofphp/php-cs-fixer ###
1722
/.php-cs-fixer.php
1823
/.php-cs-fixer.cache
1924
###< friendsofphp/php-cs-fixer ###
2025

21-
###> symfony/phpunit-bridge ###
22-
.phpunit.result.cache
23-
/phpunit.xml
24-
###< symfony/phpunit-bridge ###
25-
2626
###> phpunit/phpunit ###
2727
/phpunit.xml
2828
.phpunit.result.cache
29-
/.phpunit.cache/
3029
###< phpunit/phpunit ###

.gitlab-ci.yml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
stages:
2+
- compile
3+
- test
4+
# - deploy
5+
6+
compile:
7+
stage: compile
8+
image: composer:latest
9+
script:
10+
- composer install
11+
artifacts:
12+
when: always
13+
paths:
14+
- vendor/
15+
- var/cache/
16+
expire_in: 10 minutes
17+
only:
18+
- merge_requests
19+
- master
20+
tags:
21+
- docker
22+
23+
code:analyse:
24+
stage: test
25+
image: php:latest
26+
script:
27+
- vendor/bin/phpstan analyse src -c tools/phpstan/fpm-config.neon
28+
only:
29+
- merge_requests
30+
- master
31+
tags:
32+
- docker
33+
needs:
34+
- job: compile
35+
artifacts: true
36+
37+
code:cs-fixer:
38+
stage: test
39+
image: php:latest
40+
script:
41+
- vendor/bin/php-cs-fixer fix --dry-run --diff -vvv
42+
only:
43+
- merge_requests
44+
- master
45+
tags:
46+
- docker
47+
needs:
48+
- job: compile
49+
artifacts: true
50+
51+
code:test:
52+
stage: test
53+
image: php:latest
54+
before_script:
55+
- pecl install xdebug
56+
- docker-php-ext-enable xdebug
57+
- echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
58+
script:
59+
- vendor/bin/phpunit --do-not-cache-result --log-junit var/coverage/phpunit-report.xml --coverage-cobertura var/coverage/phpunit-coverage.xml --coverage-text --colors=never
60+
only:
61+
- merge_requests
62+
- master
63+
tags:
64+
- docker
65+
needs:
66+
- job: compile
67+
artifacts: true
68+
artifacts:
69+
when: always
70+
reports:
71+
junit: var/coverage/phpunit-report.xml
72+
coverage_report:
73+
coverage_format: cobertura
74+
path: var/coverage/phpunit-coverage.xml
75+
coverage: '/^\s*Lines:\s*\d+.\d+\%/'
76+
77+
# deploy:
78+
# stage: deploy
79+
# image: alpine
80+
# script:
81+
# - apk add curl
82+
# - 'curl --header "Job-Token: $CI_JOB_TOKEN" --data tag=$CI_COMMIT_TAG "${CI_API_V4_URL}/projects/$CI_PROJECT_ID/packages/composer"'
83+
# only:
84+
# - tags
85+
# tags:
86+
# - docker

Dockerfile

+22-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,30 @@ FROM php:latest
22

33
RUN apt update \
44
&& apt-get update \
5-
&& apt install -y git unzip
5+
&& apt install -y git jq unzip
66

7-
# install xdebug
7+
## install xdebug extension
88
RUN pecl install xdebug \
99
&& docker-php-ext-enable xdebug
1010

11-
# install composer
11+
## install composer
1212
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
13+
RUN mkdir -p /.composer && chmod -R 777 /.composer
14+
15+
### Setup environment variables
16+
COPY package.json composer.json .gi[t] /tmp/
17+
WORKDIR /tmp
18+
## define app version and store it in environment variable
19+
RUN echo "APP_VERSION=$(jq -r '.version' '/tmp/package.json')" >> /etc/environment
20+
RUN rm -rf /tmp/package.json
21+
## define app commit sha and store it in environment variable
22+
RUN echo "APP_COMMIT_SHA=$(git rev-parse HEAD)" >> /etc/environment
23+
RUN echo "APP_COMMIT_SHA_SHORT=$(git rev-parse --short HEAD)" >> /etc/environment
24+
RUN rm -rf .git
25+
## define app name and store it in environment variable
26+
RUN echo "APP_NAME=$(jq -r '.name' '/tmp/composer.json')" >> /etc/environment
27+
RUN echo "APP_DESCRIPTION=\"$(jq -r '.description' '/tmp/composer.json')\"" >> /etc/environment
28+
RUN echo "APP_TITLE=\"$(jq -r '.title' '/tmp/composer.json')\"" >> /etc/environment
29+
RUN rm -rf /tmp/composer.json
30+
WORKDIR /app
31+
### End of environment variables setup

README.md

+114-19
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,132 @@
11
# Extended Api Doc Bundle #
2-
This package improves the Api Doc Bundle - adding the `#[QueryParameters]` attribute allows you to declare parameters in a separate class instead of in a controller, so you can use it for multiple controllers.
2+
3+
An extension for `nelmio/api-doc-bundle` that improves the sorting of endpoints by tags and provides minor stylistic corrections to the original Nelmio view.
4+
35
## Installation
4-
5-
```sh
6+
7+
Required bundles:
8+
9+
```bash
10+
composer require symfony/asset
11+
composer require symfony/twig-bundle
12+
composer require nelmio/api-doc-bundle
613
composer require pbaszak/extended-api-doc-bundle
714
```
815

16+
Routing Registration:
17+
18+
- /api/doc
19+
- /api/doc.json
20+
- /api/doc.yaml
21+
922
```yaml
1023
# config/routes.yaml
11-
extendend_api_doc:
12-
resource: '@DocumentationBundle/Resources/routes/*'
24+
...
25+
extended_api_doc:
26+
resource: '@ExtendedApiDocBundle/Resources/routes/*'
1327
```
1428
29+
Setup metainfo:
30+
1531
```yaml
16-
# config/packages/nelmio.yaml
32+
# config/packages/nelmio_api_doc.yaml
33+
parameters:
34+
app_title: '%env(APP_TITLE)%'
35+
app_description: '%env(APP_DESCRIPTION)%'
36+
app_version: '%env(APP_VERSION)%'
37+
app_commit_sha_short: '%env(APP_COMMIT_SHA_SHORT)%'
38+
1739
nelmio_api_doc:
1840
documentation:
1941
info:
20-
title: API Service documentation
21-
description: API Service description
22-
version: '%env(APP_VERSION)%' # if You add APP_VERSION env to Your docker image in CD process
23-
areas:
42+
title: '%app_title%'
43+
description: '%app_description%'
44+
version: '%app_version% (%app_commit_sha_short%)'
45+
areas: # to filter documented areas
2446
path_patterns:
2547
- ^/api(?!/doc(.json|.yaml)?$)
2648
```
2749
28-
if `Symfony Security` is used:
29-
```yaml
30-
# config/packages/security.yaml
31-
security:
32-
# ...
33-
access_control:
34-
# ...
35-
- { path: ^\/api\/doc(\.yaml|\.json)?$, methods: [GET], roles: PUBLIC_ACCESS }
36-
# ...
50+
## Usage
51+
52+
Just open `/api/doc` path on Your server and enjoy!
53+
54+
## Development
55+
56+
### How to start
57+
58+
Start local environment using this command:
59+
```sh
60+
bash start.sh
3761
```
62+
63+
### How to use **Standard Version**
64+
65+
If You don't have node_modules directory run:
66+
```sh
67+
npm install
68+
```
69+
70+
`Major`, `Minor`, `Patch` version update:
71+
```sh
72+
npm run version:major
73+
# or
74+
npm run version:minor
75+
# or
76+
npm run version:patch
77+
```
78+
79+
Push tags:
80+
```sh
81+
npm run version:release
82+
# or
83+
npm run release
84+
```
85+
86+
Check `package.json` for understand what commands do.
87+
88+
### How to use **PHPStan**
89+
90+
Main command:
91+
```bash
92+
docker exec php composer code:analyse
93+
```
94+
but, if You need to add errors to ignored:
95+
```bash
96+
docker exec php composer code:analyse:b
97+
```
98+
99+
### How to use **PHP CS Fixer**
100+
101+
```bash
102+
docker exec php composer code:fix
103+
```
104+
105+
### How to use **XDebug** in **Visual Studio Code**
106+
107+
Create new file in Your project: `.vscode/launch.json`
108+
```json
109+
{
110+
"version": "0.2.0",
111+
"configurations": [
112+
{
113+
"name": "Listen for xDebug",
114+
"type": "php",
115+
"request": "launch",
116+
"port": 5902,
117+
"hostname": "0.0.0.0",
118+
"pathMappings": {
119+
"/app/": "${workspaceRoot}"
120+
}
121+
}
122+
]
123+
}
124+
```
125+
126+
Uncomment environments in `.env.local`:
127+
```env
128+
XDEBUG_MODE=develop,debug
129+
XDEBUG_CONFIG=" client_port=5902 idekey=VSCODE client_host=host.docker.internal discover_client_host=0 start_with_request=yes"
130+
```
131+
132+
Type `Ctrl + Shift + D` and run `Listen for xDebug`.

0 commit comments

Comments
 (0)