Skip to content

Commit 1547b59

Browse files
committed
Added standalone app. Cleaned up.
1 parent 276ecba commit 1547b59

File tree

7 files changed

+91
-14
lines changed

7 files changed

+91
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
- [PR-3](https://github.com/itk-dev/tidy-feedback/pull/3)
11-
Added translations
11+
Added translations and standalone app
1212
- [PR-5](https://github.com/itk-dev/tidy-feedback/pull/5)
1313
Add styling. Make region and form draggable
1414

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ drush tidy-feedback:doctrine:schema-update
2424

2525
### Symfony
2626

27-
Create `config/routes/tidy_feedback.yaml`:
27+
Create `config/routes/tidy_feedback.yaml` (or copy
28+
[`resources/config/routes/tidy_feedback.yaml`](resources/config/routes/tidy_feedback.yaml)):
2829

2930
``` yaml
3031
#config/routes/tidy_feedback.yaml
@@ -34,7 +35,8 @@ tidy_feedback:
3435
```
3536
3637
> [!NOTE]
37-
> You can use any `prefix`, but for consistency with the Drupal version of Tidy feedback you should use `/tidy-feedback`.
38+
> You can use any path as `prefix`, but for consistency with the Drupal version of Tidy feedback you should use
39+
> `/tidy-feedback`.
3840

3941
If [Symfony Flex](https://symfony.com/doc/current/setup/flex.html) hasn't already done so, you must enable the
4042
TidyFeedbackBundle bundle:
@@ -60,14 +62,14 @@ in the environment variable `TIDY_FEEDBACK_DATABASE_URL`, e.g.
6062
``` dotenv
6163
# .env
6264
# See https://www.doctrine-project.org/projects/doctrine-dbal/en/4.2/reference/configuration.html#connecting-using-a-url for details.
63-
TIDY_FEEDBACK_DATABASE_URL="pdo-sqlite:////app/tidy-feedback.sqlite"
65+
TIDY_FEEDBACK_DATABASE_URL=pdo-sqlite://localhost//app/tidy-feedback.sqlite
6466
```
6567

6668
As an alternative for Drupal you can set `TIDY_FEEDBACK_DATABASE_URL` in `settings.local.php`:
6769

6870
``` php
6971
# web/sites/default/settings.local.php
70-
putenv('TIDY_FEEDBACK_DATABASE_URL=pdo-sqlite:////app/tidy-feedback.sqlite');
72+
putenv('TIDY_FEEDBACK_DATABASE_URL=pdo-sqlite://localhost//app/tidy-feedback.sqlite');
7173
```
7274

7375
`TIDY_FEEDBACK_USERS='{"admin": "password"}'`
@@ -118,3 +120,17 @@ In order to make this behave as both a Drupal module and a Synfony bundle, we us
118120
### Twig
119121

120122
We use a watered-down instance of Twig with only a `trans` filter and a `path` function.
123+
124+
### Development app
125+
126+
For development, you can start a Symfony app with Tidy feedback installed:
127+
128+
``` shell
129+
task app:start
130+
```
131+
132+
Run `task app:stop` to stop the app.
133+
134+
> [!TIP]
135+
> Use `tidy-feedback-show=form` in the query string, e.g. `/tidy-feedback/test?tidy-feedback-show=form`, to
136+
> automatically show the feedback form when loading a page.

Taskfile.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ dotenv: [".env.local", ".env"]
55

66
vars:
77
DOCKER_COMPOSE: '{{.TASK_DOCKER_COMPOSE | default "docker compose"}}'
8+
APP_DOCKER_COMPOSE: docker compose --profile app
89

910
tasks:
1011
compose:
@@ -157,3 +158,35 @@ tasks:
157158
cmds:
158159
- task --list-all
159160
silent: true
161+
162+
app:start:
163+
desc: Start Symfony app with Tity feedback installed
164+
cmds:
165+
- |
166+
echo ------------------------------------------------------------------------------------------------
167+
echo For reasons yet unknown, you may have to run this command 2 or 3 times to make everything work …
168+
echo ------------------------------------------------------------------------------------------------
169+
170+
- task app:compose -- pull
171+
- task app:compose -- up --detach --remove-orphans --wait
172+
173+
- task app:compose -- exec symfony composer config repositories.tidy-feedback path /app
174+
# https://github.com/itk-dev/tidy-feedback?tab=readme-ov-file#installation
175+
- task app:compose -- exec symfony composer require itk-dev/tidy-feedback:dev-main
176+
177+
# https://github.com/itk-dev/tidy-feedback?tab=readme-ov-file#symfony
178+
- task app:compose -- exec symfony cp /app/resources/config/routes/tidy_feedback.yaml config/routes/
179+
- task app:compose -- exec symfony bin/console cache:clear
180+
181+
- task app:compose -- exec symfony bin/console tidy-feedback:doctrine:schema-update
182+
- open "http://$(task app:compose -- port symfony 80)/tidy-feedback/test?tidy-feedback-show=form"
183+
silent: true
184+
185+
app:stop:
186+
desc: Stop Symfony app
187+
cmds:
188+
- task app:compose -- down --remove-orphans
189+
190+
app:compose:
191+
cmds:
192+
- "{{.APP_DOCKER_COMPOSE}} {{.CLI_ARGS}}"

compose.yaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,23 @@ services:
4545
symfony:
4646
# https://hub.docker.com/r/shinsenter/symfony
4747
image: shinsenter/symfony:latest
48-
# command: sh -c "
49-
# composer require symfony/translation
50-
# "
48+
# For some reason it takes a while before composer.json appear in the project root
49+
# @todo Investigate why
50+
healthcheck:
51+
test: ["CMD", "test", "-f", "composer.json"]
52+
interval: 2s
53+
timeout: 60s
54+
retries: 20
5155
volumes:
5256
- ./:/app
5357
profiles:
5458
- dev
59+
- app
60+
ports:
61+
- "80"
62+
environment:
63+
APP_ENV: dev
64+
# Needed to run without requiring a cache
65+
TIDY_FEEDBACK_DEV_MODE: true
66+
TIDY_FEEDBACK_DEBUG: true
67+
TIDY_FEEDBACK_DATABASE_URL: pdo-sqlite://localhost//app/app-tidy-feedback.sqlite

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"doctrine/dbal": "^3 || ^4",
88
"doctrine/orm": "^2.8 || ^3",
99
"symfony/cache": "^6 || ^7",
10+
"symfony/http-kernel": "^6 || ^7",
1011
"twig/twig": "^3"
1112
},
1213
"require-dev": {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tidy_feedback:
2+
resource: "@TidyFeedbackBundle/config/routes.php"
3+
prefix: /tidy-feedback

src/TidyFeedbackHelper.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private function trans(string $text, array $context = []): string
9191
}
9292

9393
// @todo Get the locale from some context …
94-
$locale = static::getConfig('default_locale');
94+
$locale = self::getConfig('default_locale');
9595
$fallbackLocale = 'en';
9696

9797
return self::$translations[$locale][$text] ?? self::$translations[$fallbackLocale][$text] ?? $text;
@@ -105,11 +105,13 @@ private function trans(string $text, array $context = []): string
105105
public static function getEntityManager(): EntityManagerInterface
106106
{
107107
if (empty(self::$entityManager)) {
108-
$config = ORMSetup::createAttributeMetadataConfiguration(
108+
$config = ORMSetup::createAttributeMetadataConfig(
109109
paths: [__DIR__.'/Model'],
110+
isDevMode: (bool) ($_ENV['TIDY_FEEDBACK_DEV_MODE'] ?? false),
110111
);
112+
$config->enableNativeLazyObjects(true);
111113

112-
$dsn = static::getConfig('database_url');
114+
$dsn = self::getConfig('database_url');
113115
$connectionParams = (new DsnParser())->parse($dsn);
114116
$connection = DriverManager::getConnection($connectionParams, $config);
115117

@@ -127,13 +129,22 @@ public function createAssetResponse(string $asset): Response
127129
throw new NotFoundHttpException();
128130
}
129131

130-
return new BinaryFileResponse($filename, headers: [
132+
$response = new BinaryFileResponse($filename, headers: [
131133
'content-type' => match (pathinfo($filename, PATHINFO_EXTENSION)) {
132134
'css' => 'text/css',
133135
'js' => 'text/javascript',
134136
default => throw new NotFoundHttpException(),
135137
},
136-
]);
138+
],
139+
autoEtag: true, autoLastModified: true
140+
);
141+
142+
if (self::getConfig('debug')) {
143+
// setExpires(null) does not seem to work as advertised, so we use a date in the far past.
144+
$response->setExpires(new \DateTimeImmutable('2001-01-01'));
145+
}
146+
147+
return $response;
137148
}
138149

139150
public static function updateSchema(OutputInterface $output): bool
@@ -214,7 +225,7 @@ public function onKernelResponse(ResponseEvent $event): void
214225
$response->setContent($content);
215226
}
216227
} catch (\Throwable $throwable) {
217-
if (static::getConfig('debug')) {
228+
if (self::getConfig('debug')) {
218229
throw $throwable;
219230
}
220231
// Ignore all errors!

0 commit comments

Comments
 (0)