Skip to content

Commit 3c17dff

Browse files
Merge pull request #394 from continuouspipe/feature/symfony-flex
Add detection and support for Symfony Flex structure
2 parents 1862f6f + eb805f6 commit 3c17dff

7 files changed

Lines changed: 68 additions & 23 deletions

File tree

php/shared/usr/local/share/env/40-stack

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export XDEBUG_REMOTE_HOST=${XDEBUG_REMOTE_HOST:-sshforward}
4040
export XDEBUG_REMOTE_PORT=${XDEBUG_REMOTE_PORT:-9000}
4141

4242
export WORK_DIRECTORY=${WORK_DIRECTORY:-/app}
43-
export WEB_DIRECTORY=${WEB_DIRECTORY:-web}
4443

4544
export WEB_HOST=${WEB_HOST:-localhost}
4645
export WEB_HTTP_PORT=${WEB_HTTP_PORT:-80}

php/shared/usr/local/share/env/55-stack

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
export WEB_DIRECTORY=${WEB_DIRECTORY:-web}
23

34
# Relative WEB_DIRECTORY converted to absolute path
45
if ! [[ "$WEB_DIRECTORY" =~ ^/ ]]; then

php/shared/usr/local/share/php/common_functions.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,34 @@ do_composer_postinstall_scripts() {
2929
}
3030

3131
has_composer_package() {
32-
if [ ! -f "composer.lock" ]; then
32+
if [ ! -f "${WORK_DIRECTORY}/composer.lock" ]; then
3333
return
3434
fi
3535

36-
is_true "$(jq -c '(.packages + .["packages-dev"])[] | select(.name == "'"$1"'") | has("name")' composer.lock)"
36+
is_true "$(jq -c '(.packages + .["packages-dev"])[] | select(.name == "'"$1"'") | has("name")' "${WORK_DIRECTORY}/composer.lock")"
37+
return "$?"
38+
}
39+
40+
composer_package_version() {
41+
local -r PACKAGE_VERSION="$(jq -c '(.packages + .["packages-dev"])[] | select(.name == "'"$1"'") | .version' "${WORK_DIRECTORY}/composer.lock" | sed 's/^"v\?\(.*\)"/\1/')"
42+
43+
if [ -z "${PACKAGE_VERSION}" ]; then
44+
return 1
45+
fi
46+
47+
echo "${PACKAGE_VERSION}"
48+
}
49+
50+
composer_package_compare() {
51+
local -r PACKAGE="$1"
52+
local -r RELATION="$2"
53+
local -r COMPARE_VERSION="$3"
54+
local -r PACKAGE_VERSION="$(composer_package_version "${PACKAGE}")"
55+
56+
if [ -z "${PACKAGE_VERSION}" ]; then
57+
return 1
58+
fi
59+
60+
dpkg --compare-versions "${PACKAGE_VERSION}" "${RELATION}" "${COMPARE_VERSION}"
3761
return "$?"
3862
}

symfony/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Variable | Description | Expected values | Default
7272
--- | --- | --- | ----
7373
SYMFONY_DOCTRINE_MODE | Whether to use Doctrine migrations, schema update or nothing. Automatically detected based on installed composer packages by default | auto/migrations/schema/off | auto
7474
SYMFONY_ENV | The Symfony env to use, when the app reads this variable | string | prod
75+
SYMFONY_FLEX | Whether the project uses the symfony/flex component and folder structure | true/false | autodetected based on whether in composer.lock
7576
SYMFONY_MAJOR_VERSION | The major version of Symfony that will be used | 2, 3 | auto-detected based on location of console script
7677
SYMFONY_CONSOLE | The location of the Symfony console script | file path | auto-detected
7778
SYMFONY_WEB_APP_ENV_REWRITE | Whether to use web/app_*.php when SYMFONY_ENV != prod | true, false | false

symfony/usr/local/share/env/30-framework

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,10 @@ export PHP_MEMORY_LIMIT=${PHP_MEMORY_LIMIT:-256M}
44
export PHP_OPCACHE_MAX_ACCELERATED_FILES=${PHP_OPCACHE_MAX_ACCELERATED_FILES:-20000}
55
export PHP_REALPATH_CACHE_SIZE=${PHP_REALPATH_CACHE_SIZE:-4096K}
66
export PHP_REALPATH_CACHE_TTL=${PHP_REALPATH_CACHE_TTL:-600}
7-
SYMFONY_WEB_APP_ENV_REWRITE=${SYMFONY_WEB_APP_ENV_REWRITE:-false}
8-
SYMFONY_WEB_APP_ENV_REWRITE="$(convert_to_boolean_string "$SYMFONY_WEB_APP_ENV_REWRITE")"
7+
export SYMFONY_DOCTRINE_MODE=auto
8+
SYMFONY_WEB_APP_ENV_REWRITE="$(convert_to_boolean_string "${SYMFONY_WEB_APP_ENV_REWRITE:-false}")"
99
export SYMFONY_WEB_APP_ENV_REWRITE
1010

11-
if [ -n "${SYMFONY_APP_ENDPOINT}" ]; then
12-
echo "deprecated: SYMFONY_APP_ENDPOINT is deprecated. Please rename to APP_ENDPOINT." >&2
13-
fi
14-
15-
if [ "$SYMFONY_ENV" == "prod" ] || [ "$SYMFONY_WEB_APP_ENV_REWRITE" != "true" ]; then
16-
DEFAULT_APP_ENDPOINT=/app.php
17-
else
18-
DEFAULT_APP_ENDPOINT=/app_${SYMFONY_ENV}.php
19-
fi
20-
21-
export APP_ENDPOINT_STRICT=${APP_ENDPOINT_STRICT:-true}
22-
export APP_ENDPOINT=${SYMFONY_APP_ENDPOINT:-${APP_ENDPOINT:-${DEFAULT_APP_ENDPOINT}}}
11+
deprecate_env_var SYMFONY_APP_ENDPOINT APP_ENDPOINT
2312

2413
export TIDEWAYS_FRAMEWORK=${TIDEWAYS_FRAMEWORK:-symfony}

symfony/usr/local/share/env/45-framework

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
11
#!/bin/bash
22

3-
if [ -f "${WORK_DIRECTORY}/bin/console" ]; then
3+
if has_composer_package 'symfony/symfony'; then
4+
SYMFONY_MAJOR_VERSION_GUESS="$(composer_package_version 'symfony/symfony' | cut -d '.' -f 1)"
5+
elif has_composer_package 'symfony/framework-bundle'; then
6+
SYMFONY_MAJOR_VERSION_GUESS="$(composer_package_version 'symfony/framework-bundle' | cut -d '.' -f 1)"
7+
elif [ -f "${WORK_DIRECTORY}/bin/console" ]; then
48
SYMFONY_MAJOR_VERSION_GUESS=3
5-
SYMFONY_CONSOLE_DEFAULT=${WORK_DIRECTORY}/bin/console
69
else
710
SYMFONY_MAJOR_VERSION_GUESS=2
8-
SYMFONY_CONSOLE_DEFAULT=${WORK_DIRECTORY}/app/console
911
fi
1012

1113
export SYMFONY_MAJOR_VERSION=${SYMFONY_MAJOR_VERSION:-${SYMFONY_MAJOR_VERSION_GUESS}}
14+
15+
if has_composer_package 'symfony/flex'; then
16+
SYMFONY_FLEX="$(convert_to_boolean_string "${SYMFONY_FLEX:-true}")"
17+
else
18+
SYMFONY_FLEX="$(convert_to_boolean_string "${SYMFONY_FLEX:-false}")"
19+
fi
20+
export SYMFONY_FLEX
21+
22+
if is_true "${SYMFONY_FLEX}"; then
23+
DEFAULT_APP_ENDPOINT=/index.php
24+
export WEB_DIRECTORY=${WEB_DIRECTORY:-public}
25+
26+
if is_true "$SYMFONY_WEB_APP_ENV_REWRITE"; then
27+
echo 'warning: SYMFONY_WEB_APP_ENV_REWRITE is ignored when using Symfony 4+ folder structure' >&2
28+
fi
29+
elif [ "$SYMFONY_ENV" == "prod" ] || is_false "$SYMFONY_WEB_APP_ENV_REWRITE"; then
30+
DEFAULT_APP_ENDPOINT=/app.php
31+
else
32+
DEFAULT_APP_ENDPOINT=/app_${SYMFONY_ENV}.php
33+
fi
34+
35+
export APP_ENDPOINT_STRICT=${APP_ENDPOINT_STRICT:-true}
36+
export APP_ENDPOINT=${SYMFONY_APP_ENDPOINT:-${APP_ENDPOINT:-${DEFAULT_APP_ENDPOINT}}}
37+
38+
if [ "${SYMFONY_MAJOR_VERSION}" -ge 3 ]; then
39+
SYMFONY_CONSOLE_DEFAULT=${WORK_DIRECTORY}/bin/console
40+
else
41+
SYMFONY_CONSOLE_DEFAULT=${WORK_DIRECTORY}/app/console
42+
fi
43+
1244
export SYMFONY_CONSOLE=${SYMFONY_CONSOLE:-${SYMFONY_CONSOLE_DEFAULT}}
13-
export SYMFONY_DOCTRINE_MODE=auto

symfony/usr/local/share/symfony/symfony_functions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
do_symfony_config_create() {
44
# Prepare a default parameters.yml. incenteev/parameters-handler can still update it
5-
if [ ! -f /app/app/config/parameters.yml ]; then
5+
if is_false "${SYMFONY_FLEX}" && [ ! -f /app/app/config/parameters.yml ]; then
6+
mkdir -p /app/app/config
67
echo 'parameters: {}' > /app/app/config/parameters.yml
78
fi
89
}
@@ -11,7 +12,6 @@ do_symfony_directory_create() {
1112
if [ "$SYMFONY_MAJOR_VERSION" -eq 2 ]; then
1213
mkdir -p /app/app/{cache,logs}
1314
fi
14-
mkdir -p /app/app/config
1515
mkdir -p /app/var
1616
}
1717

0 commit comments

Comments
 (0)