Skip to content

Commit

Permalink
Merge pull request #1 from netgen/symfony-skeleton-test
Browse files Browse the repository at this point in the history
NGSTACK-886 add symfony skeleton recipe
  • Loading branch information
emodric authored Nov 8, 2024
2 parents fa394c3 + 1188733 commit 28b266f
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/callable-flex-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
id: checkout
with:
fetch-depth: 0
Expand Down
68 changes: 68 additions & 0 deletions netgen/symfony-skeleton/1.0/config/.htaccess_dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex index.php

# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks

# Disabling MultiViews prevents unwanted negotiation, e.g. "/app" should not resolve
# to the front controller "/app.php" but be rewritten to "/app.php/app".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On

# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]

# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Rewrite all other queries to the front controller.
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /index.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
1 change: 1 addition & 0 deletions netgen/symfony-skeleton/1.0/config/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v21
54 changes: 54 additions & 0 deletions netgen/symfony-skeleton/1.0/config/.php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PER' => true,
'@PER:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,

// Overrides for rules included in PhpCsFixer rule sets
'concat_space' => ['spacing' => 'one'],
'fully_qualified_strict_types' => ['phpdoc_tags' => []],
'method_chaining_indentation' => false,
'multiline_whitespace_before_semicolons' => false,
'native_function_invocation' => ['include' => ['@all']],
'no_superfluous_phpdoc_tags' => false,
'no_unset_on_property' => false,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'alpha'],
'php_unit_internal_class' => false,
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'php_unit_test_class_requires_covers' => false,
'phpdoc_align' => false,
'phpdoc_order' => ['order' => ['param', 'throws', 'return']],
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'single_line_comment_style' => false,
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'match', 'parameters']],
'yoda_style' => false,

// Additional rules
'date_time_immutable' => true,
'declare_strict_types' => true,
'global_namespace_import' => [
'import_classes' => null,
'import_constants' => true,
'import_functions' => true,
],
'heredoc_indentation' => ['indentation' => 'same_as_start'],
'mb_str_functions' => true,
'native_constant_invocation' => true,
'nullable_type_declaration_for_default_null_value' => true,
'static_lambda' => true,
'ternary_to_null_coalescing' => true,
'use_arrow_functions' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in(['src', 'tests'])
->notPath(['Kernel.php', 'bootstrap.php']),
)
;
87 changes: 87 additions & 0 deletions netgen/symfony-skeleton/1.0/config/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
APP_ENV = dev
PHP_VERSION = php8.2
PHP_RUN = /usr/bin/env $(PHP_VERSION)
COMPOSER_PATH = /usr/local/bin/composer2
ifeq ("$(wildcard $(COMPOSER_PATH))","")
COMPOSER_PATH = /usr/local/bin/composer
endif
COMPOSER_RUN = $(PHP_RUN) $(COMPOSER_PATH)
CACHE_POOL = cache.redis
STASH_HASH := $(shell git stash create)

.PHONY: help
help: ## List of all available commands
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help

.PHONY: php-version
php-version: ## See PHP version needed for this project
@echo $(PHP_VERSION)

COMPOSER_INSTALL_PARAMETERS =
ifeq ($(APP_ENV), prod)
COMPOSER_INSTALL_PARAMETERS = --no-dev -o
endif

.PHONY: vendor
vendor: ## Run composer install
$(COMPOSER_RUN) install $(COMPOSER_INSTALL_PARAMETERS)

.PHONY: assets
.ONESHELL:
assets: ## Build frontend assets for DEV environment
. ${NVM_DIR}/nvm.sh && nvm use || nvm install $(cat .nvmrc)
yarn install
yarn build:dev

.PHONY: assets-prod
.ONESHELL:
assets-prod: ## Build frontend assets for PROD environment
. ${NVM_DIR}/nvm.sh && nvm use || nvm install $(cat .nvmrc)
yarn install
yarn build:prod

.PHONY: assets-watch
.ONESHELL:
assets-watch: ## Watch frontend assets (during development)
. ${NVM_DIR}/nvm.sh && nvm use || nvm install $(cat .nvmrc)
yarn install
yarn watch

.PHONY: clear-cache
clear-cache: ## Clear caches for specified environment (default: APP_ENV=dev)
$(PHP_RUN) bin/console cache:clear --env=$(APP_ENV)

.PHONY: clear-all-cache
clear-all-cache: ## Clear all caches for specified environment (including eg. Redis) (default: APP_ENV=dev)
@$(MAKE) -s clear-cache
$(PHP_RUN) bin/console cache:pool:clear $(CACHE_POOL) --env=$(APP_ENV)

.PHONY: migrations
migrations: ## Run Doctrine migrations for specified environment (default: APP_ENV=dev)
$(PHP_RUN) bin/console doctrine:migration:migrate --allow-no-migration --env=$(APP_ENV)

.PHONY: build
build: ## Build the project (install vendor, migrations, build assets, clear cache) for specified environment (default: APP_ENV=dev)
@$(MAKE) -s vendor
@$(MAKE) -s migrations
ifeq ($(APP_ENV), prod)
$(MAKE) -s assets-prod
else
$(MAKE) -s assets
endif
@$(MAKE) -s clear-cache

.PHONY: update-code
update-code: ## Pull the latest code from the repository (on the current branch)
ifeq ($(STASH_HASH),)
git pull --rebase
else
git stash && git pull --rebase && git stash pop
endif

.PHONY: refresh
refresh: ## Fetch latest changes and build the project for specified environment (default: APP_ENV=dev)
@$(MAKE) -s update-code
@$(MAKE) -s build
92 changes: 92 additions & 0 deletions netgen/symfony-skeleton/1.0/config/captainhook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\Netgen\\GitHooks\\Action\\Regex",
"options": {
"regex": "/^[A-Z0-9]+-\\d+:?\\s/",
"error": "Your commit message MUST start with a ticket ID"
}
}
]
},
"pre-push": {
"enabled": false,
"actions": []
},
"pre-commit": {
"enabled": true,
"actions": [
{
"action": "\\Netgen\\GitHooks\\Action\\CheckForBlockedWords",
"options": {
"extensions": ["php"],
"keyword_blocklist": ["var_dump", "dump", "dd"],
"excluded_files": []
}
},
{
"action": "\\Netgen\\GitHooks\\Action\\CheckForBlockedWords",
"options": {
"extensions": ["twig"],
"keyword_blocklist": ["dump"],
"excluded_files": []
}
},
{
"action": "\\CaptainHook\\App\\Hook\\Composer\\Action\\CheckLockFile"
},
{
"action": "\\Netgen\\GitHooks\\Action\\PHPCSFixer",
"options": {
"excluded_files": ["deploy.php", "/^deploy.*/", "config/bundles.php"],
"fixer_path": "vendor/bin/php-cs-fixer"
}
},
{
"action": "\\Netgen\\GitHooks\\Action\\PHPStan",
"options": {
"excluded_files": ["/^deploy.*/"]
}
},
{
"action": "\\Netgen\\GitHooks\\Action\\JSLinter",
"options": {
"excluded_files": []
}
},
{
"action": "\\Netgen\\GitHooks\\Action\\JSPrettier",
"options": {
"excluded_files": []
}
},
{
"action": "\\Netgen\\GitHooks\\Action\\CheckLockFileCommitted",
"options": {
"enabled": true
}
}
]
},
"prepare-commit-msg": {
"enabled": false,
"actions": []
},
"post-commit": {
"enabled": false,
"actions": []
},
"post-merge": {
"enabled": false,
"actions": []
},
"post-checkout": {
"enabled": false,
"actions": []
},
"config": {
"php-path": "/usr/bin/env php8.2"
}
}
12 changes: 12 additions & 0 deletions netgen/symfony-skeleton/1.0/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"copy-from-recipe": {
"config/captainhook.json": "captainhook.json",
"config/Makefile": "Makefile",
"config/.nvmrc": ".nvmrc",
"config/.php-cs-fixer.php": ".php-cs-fixer.php",
"config/.htaccess_dev": "public/.htaccess_dev"
},
"env": {
"CACHE_DSN": "redis://localhost"
}
}

0 comments on commit 28b266f

Please sign in to comment.