Skip to content

Commit dfb1cba

Browse files
committed
Refactor ddev installer of testing version: a) not create endless symlinks of itself a) add local extension for testing EventListeners.
1 parent dab176d commit dfb1cba

File tree

7 files changed

+214
-5
lines changed

7 files changed

+214
-5
lines changed

.ddev/commands/web/install-v12

+16-5
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ BASE_PATH=/var/www/html/.test/$VERSION
1111
TYPO3_BIN=$BASE_PATH/vendor/bin/typo3
1212
DATABASE=database_$VERSION
1313

14-
[ -L /var/www/html/.test/t3api ] || ln -sr /var/www/html/ /var/www/html/.test/t3api
1514
rm -rf $BASE_PATH
16-
mkdir -p $BASE_PATH
15+
16+
mkdir -p $BASE_PATH/src/$EXTENSION_KEY
17+
for item in /var/www/html/*; do
18+
base_name=$(basename "$item")
19+
if [[ $base_name != .* ]]; then
20+
ln -sr "$item" "$BASE_PATH/src/$EXTENSION_KEY/$base_name"
21+
fi
22+
done
1723

1824
mysql -uroot -proot -e "DROP DATABASE IF EXISTS $DATABASE"
1925

2026
composer init --name=sourcebroker/typo3$VERSION --description=TYPO3$VERSION --no-interaction --working-dir $BASE_PATH
2127
composer config extra.typo3/cms.web-dir public --working-dir $BASE_PATH
22-
composer config repositories.$EXTENSION_KEY path ../$EXTENSION_KEY --working-dir $BASE_PATH
28+
composer config repositories.src path 'src/*' --working-dir $BASE_PATH
2329
composer config --no-interaction allow-plugins.typo3/cms-composer-installers true --working-dir $BASE_PATH
2430
composer config --no-interaction allow-plugins.typo3/class-alias-loader true --working-dir $BASE_PATH
2531
composer req typo3/minimal:'^12.4' typo3/cms-recycler:'^12.4' typo3/cms-tstemplate:'^12.4' typo3/cms-info:'^12.4' typo3/cms-lowlevel:'^12.4' \
@@ -40,8 +46,13 @@ $TYPO3_BIN configuration:set 'MAIL/transport_smtp_server' 'localhost:1025'
4046
$TYPO3_BIN configuration:set 'GFX/processor' 'ImageMagick'
4147
$TYPO3_BIN configuration:set 'GFX/processor_path' '/usr/bin/'
4248

43-
cp -r "$BASE_PATH/../$EXTENSION_KEY/.ddev/data-init/$VERSION/files/"* "$BASE_PATH/"
44-
mysql -uroot -proot $DATABASE < "$BASE_PATH/../$EXTENSION_KEY/.ddev/data-init/$VERSION/database.sql"
49+
ln -sr ".ddev/data-init/$VERSION/files/src/site/" $BASE_PATH/src/site
50+
rm -rf $BASE_PATH/public/fileadmin/user_upload && ln -srf ".ddev/data-init/$VERSION/files/public/fileadmin/user_upload/" $BASE_PATH/public/fileadmin/user_upload
51+
ln -srf ".ddev/data-init/v12/files/config/sites/main/config.yaml" $BASE_PATH/config/sites/main/config.yaml
52+
53+
mysql -uroot -proot $DATABASE < ".ddev/data-init/$VERSION/database.sql"
54+
55+
composer req v/site:'^1.0.0' --working-dir $BASE_PATH
4556

4657
$TYPO3_BIN database:updateschema
4758
$TYPO3_BIN cache:flush
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace V\Site\EventListener;
4+
5+
use SourceBroker\T3api\Event\AfterCreateContextForOperationEvent;
6+
use V\Site\Logger\HtmlFileLogger;
7+
8+
class AfterCreateContextForOperationEventListener
9+
{
10+
public function __construct(
11+
private readonly HtmlFileLogger $logger,
12+
) {
13+
}
14+
15+
public function __invoke(AfterCreateContextForOperationEvent $event): void
16+
{
17+
$operation = $event->getOperation();
18+
$logMessage = sprintf(
19+
'
20+
<strong>Operation processed:</strong> %s<br>
21+
<strong>Method:</strong> %s<br>
22+
<strong>Path:</strong> %s
23+
',
24+
get_class($operation),
25+
$operation->getMethod(),
26+
$operation->getPath()
27+
);
28+
29+
$logContext = [
30+
'operation' => $operation,
31+
'request' => $event->getRequest(),
32+
'context' => $event->getContext(),
33+
];
34+
35+
$this->logger->warning($logMessage, $logContext);
36+
}
37+
}
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace V\Site\EventListener;
4+
5+
use SourceBroker\T3api\Event\AfterProcessOperationEvent;
6+
use V\Site\Logger\HtmlFileLogger;
7+
8+
class AfterProcessOperationEventListener
9+
{
10+
public function __construct(
11+
private readonly HtmlFileLogger $logger,
12+
) {
13+
}
14+
15+
public function __invoke(AfterProcessOperationEvent $event): void
16+
{
17+
$operation = $event->getOperation();
18+
$logMessage = sprintf(
19+
'
20+
<strong>Operation processed:</strong> %s<br>
21+
<strong>Method:</strong> %s<br>
22+
<strong>Path:</strong> %s
23+
',
24+
get_class($operation),
25+
$operation->getMethod(),
26+
$operation->getPath()
27+
);
28+
29+
$logContext = [
30+
'operation' => $operation,
31+
'result' => $event->getResult(),
32+
];
33+
34+
$this->logger->warning($logMessage, $logContext);
35+
}
36+
}
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace V\Site\Logger;
4+
5+
use Psr\Log\AbstractLogger;
6+
use Stringable;
7+
use TYPO3\CMS\Core\Core\Environment;
8+
use TYPO3\CMS\Core\Utility\GeneralUtility;
9+
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
10+
11+
class HtmlFileLogger extends AbstractLogger
12+
{
13+
private static int $logCalls = 0;
14+
15+
public function __construct()
16+
{
17+
$directoryPath = Environment::getPublicPath() . '/logs/';
18+
if (!is_dir($directoryPath)) {
19+
GeneralUtility::mkdir_deep($directoryPath);
20+
}
21+
}
22+
23+
public function log($level, Stringable|string $message, array $context = []): void
24+
{
25+
self::$logCalls++;
26+
27+
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
28+
$normalizedClassName = ltrim(str_replace(['\\', '/'], '_', $backtrace[2]['class']), '_');
29+
30+
$logEntry = '<h3><strong>Message:</strong></h3>';
31+
$logEntry .= '<p>' . $message . '</p>';
32+
$logEntry .= '<h3>Data:</h3>';
33+
$logEntry .= '<hr>';
34+
if (self::$logCalls > 1) {
35+
$logEntry .= $this->getDebuggerUtilityCss();
36+
}
37+
38+
$logEntry .= DebuggerUtility::var_dump($context, null, 20, false, false, true);
39+
GeneralUtility::writeFile(
40+
Environment::getPublicPath() . '/logs/' . $normalizedClassName . '.html',
41+
$logEntry
42+
);
43+
}
44+
45+
/*
46+
* DebuggerUtility::var_dump does add css ony once on first call. But we need to add it every time because we store output in separate files.
47+
*/
48+
protected function getDebuggerUtilityCss(): string
49+
{
50+
return '
51+
<style>
52+
.extbase-debugger-tree{position:relative}
53+
.extbase-debugger-tree input{position:absolute !important;float: none !important;top:0;left:0;height:14px;width:14px;margin:0 !important;cursor:pointer;opacity:0;z-index:2}
54+
.extbase-debugger-tree input~.extbase-debug-content{display:none}
55+
.extbase-debugger-tree .extbase-debug-header:before{position:relative;top:3px;content:"";padding:0;line-height:10px;height:12px;width:12px;text-align:center;margin:0 3px 0 0;background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkViZW5lXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMTIgMTIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDEyIDEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj4uc3Qwe2ZpbGw6Izg4ODg4ODt9PC9zdHlsZT48cGF0aCBpZD0iQm9yZGVyIiBjbGFzcz0ic3QwIiBkPSJNMTEsMTFIMFYwaDExVjExeiBNMTAsMUgxdjloOVYxeiIvPjxnIGlkPSJJbm5lciI+PHJlY3QgeD0iMiIgeT0iNSIgY2xhc3M9InN0MCIgd2lkdGg9IjciIGhlaWdodD0iMSIvPjxyZWN0IHg9IjUiIHk9IjIiIGNsYXNzPSJzdDAiIHdpZHRoPSIxIiBoZWlnaHQ9IjciLz48L2c+PC9zdmc+);display:inline-block}
56+
.extbase-debugger-tree input:checked~.extbase-debug-content{display:inline}
57+
.extbase-debugger-tree input:checked~.extbase-debug-header:before{background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkViZW5lXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMTIgMTIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDEyIDEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj4uc3Qwe2ZpbGw6Izg4ODg4ODt9PC9zdHlsZT48cGF0aCBpZD0iQm9yZGVyIiBjbGFzcz0ic3QwIiBkPSJNMTEsMTFIMFYwaDExVjExeiBNMTAsMUgxdjloOVYxeiIvPjxnIGlkPSJJbm5lciI+PHJlY3QgeD0iMiIgeT0iNSIgY2xhc3M9InN0MCIgd2lkdGg9IjciIGhlaWdodD0iMSIvPjwvZz48L3N2Zz4=)}
58+
.extbase-debugger{display:block;text-align:left;background:#2a2a2a;border:1px solid #2a2a2a;box-shadow:0 3px 0 rgba(0,0,0,.5);color:#000;margin:20px;overflow:hidden;border-radius:4px}
59+
.extbase-debugger-floating{position:relative;z-index:99990}
60+
.extbase-debugger-top{background:#444;font-size:12px;font-family:monospace;color:#f1f1f1;padding:6px 15px}
61+
.extbase-debugger-center{padding:0 15px;margin:15px 0;background-image:repeating-linear-gradient(to bottom,transparent 0,transparent 20px,#252525 20px,#252525 40px)}
62+
.extbase-debugger-center,.extbase-debugger-center .extbase-debug-string,.extbase-debugger-center a,.extbase-debugger-center p,.extbase-debugger-center pre,.extbase-debugger-center strong{font-size:12px;font-weight:400;font-family:monospace;line-height:20px;color:#f1f1f1}
63+
.extbase-debugger-center pre{background-color:transparent;margin:0;padding:0;border:0;word-wrap:break-word;color:#999}
64+
.extbase-debugger-center .extbase-debug-string{color:#ce9178;white-space:normal}
65+
.extbase-debugger-center .extbase-debug-type{color:#569CD6;padding-right:4px}
66+
.extbase-debugger-center .extbase-debug-unregistered{background-color:#dce1e8}
67+
.extbase-debugger-center .extbase-debug-filtered,.extbase-debugger-center .extbase-debug-proxy,.extbase-debugger-center .extbase-debug-ptype,.extbase-debugger-center .extbase-debug-visibility,.extbase-debugger-center .extbase-debug-uninitialized,.extbase-debugger-center .extbase-debug-scope{color:#fff;font-size:10px;line-height:12px;padding:2px 4px;margin-right:2px;position:relative;top:-1px}
68+
.extbase-debugger-center .extbase-debug-scope{background-color:#497AA2}
69+
.extbase-debugger-center .extbase-debug-ptype{background-color:#698747}
70+
.extbase-debugger-center .extbase-debug-visibility{background-color:#6c0787}
71+
.extbase-debugger-center .extbase-debug-uninitialized{background-color:#698747}
72+
.extbase-debugger-center .extbase-debug-dirty{background-color:#FFFFB6}
73+
.extbase-debugger-center .extbase-debug-filtered{background-color:#4F4F4F}
74+
.extbase-debugger-center .extbase-debug-seeabove{text-decoration:none;font-style:italic}
75+
.extbase-debugger-center .extbase-debug-property{color:#f1f1f1}
76+
.extbase-debugger-center .extbase-debug-closure{color:#9BA223;}
77+
</style>';
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deny from all
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
_defaults:
3+
autowire: true
4+
autoconfigure: true
5+
public: false
6+
7+
V\Site\:
8+
resource: '../Classes/*'
9+
10+
V\Site\EventListener\AfterProcessOperationEventListener:
11+
tags:
12+
- name: 'event.listener'
13+
event: 'SourceBroker\T3api\Event\AfterProcessOperationEvent'
14+
15+
V\Site\EventListener\AfterCreateContextForOperationEventListener:
16+
tags:
17+
- name: 'event.listener'
18+
event: 'SourceBroker\T3api\Event\AfterCreateContextForOperationEvent'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "v/site",
3+
"description": "T3api testing",
4+
"license": "GPL-2.0-or-later",
5+
"type": "typo3-cms-extension",
6+
"authors": [
7+
{
8+
"name": "",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"suggest": {},
13+
"conflict": {},
14+
"extra": {
15+
"typo3/cms": {
16+
"extension-key": "site"
17+
}
18+
},
19+
"version": "1.0.0",
20+
"autoload": {
21+
"psr-4": {
22+
"V\\Site\\": "Classes/"
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)