Skip to content

Commit e605398

Browse files
committed
Init commit
0 parents  commit e605398

24 files changed

Lines changed: 10870 additions & 0 deletions

.ddev/config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# DDEV configuration for b13/db-file-storage development.
2+
#
3+
# Layout:
4+
# / <-- the extension itself (this repo)
5+
# /Build <-- full TYPO3 installation (composer_root)
6+
# /Build/public <-- TYPO3 web root (docroot)
7+
#
8+
# The extension is symlinked into Build/vendor/b13/db-file-storage via the
9+
# composer path repository defined in Build/composer.json.
10+
name: db-file-storage
11+
type: typo3
12+
docroot: Build/public
13+
composer_root: Build
14+
php_version: "8.3"
15+
webserver_type: nginx-fpm
16+
database:
17+
type: mariadb
18+
version: "10.11"
19+
use_dns_when_possible: true
20+
composer_version: "2"
21+
web_environment:
22+
- TYPO3_CONTEXT=Development
23+
24+
# Idempotent bootstrap: composer install + typo3 setup the first time,
25+
# no-op afterwards. Keeps the Build/ installation ready on every `ddev start`.
26+
hooks:
27+
post-start:
28+
- exec: bash /var/www/html/.ddev/scripts/setup-typo3.sh
29+
30+
working_dir:
31+
web: /var/www/html/Build

.ddev/scripts/setup-typo3.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Idempotent bootstrap for the TYPO3 dev installation under Build/.
4+
# Run automatically as a DDEV post-start hook. Safe to re-run at any time.
5+
#
6+
# Steps (each guarded by a marker so repeated runs are no-ops):
7+
# 1. composer install inside Build/
8+
# 2. typo3 setup (non-interactive) against the DDEV database
9+
#
10+
# Environment inside the DDEV web container:
11+
# /var/www/html/ -> project root (the extension)
12+
# /var/www/html/Build/ -> full TYPO3 installation
13+
# db service: host=db user=db pass=db dbname=db port=3306
14+
15+
set -euo pipefail
16+
17+
BUILD_DIR="/var/www/html/Build"
18+
SETTINGS_FILE="${BUILD_DIR}/config/system/settings.php"
19+
20+
cd "${BUILD_DIR}"
21+
22+
if [ ! -f "vendor/autoload.php" ] || [ ! -x "vendor/bin/typo3" ]; then
23+
echo "[db_file_storage] Running composer install in Build/ ..."
24+
composer install --no-interaction --no-progress
25+
else
26+
echo "[db_file_storage] composer dependencies already installed, skipping."
27+
fi
28+
29+
if [ ! -f "${SETTINGS_FILE}" ]; then
30+
echo "[db_file_storage] Running 'typo3 setup' against DDEV database ..."
31+
vendor/bin/typo3 setup \
32+
--driver=mysqli \
33+
--host=db \
34+
--port=3306 \
35+
--dbname=db \
36+
--username=db \
37+
--password=db \
38+
--admin-username=admin \
39+
--admin-user-password='Password.1' \
40+
--admin-email=admin@example.com \
41+
--project-name='db_file_storage dev' \
42+
--server-type=other \
43+
--create-site='https://db-file-storage.ddev.site/' \
44+
--force \
45+
--no-interaction
46+
echo "[db_file_storage] TYPO3 is ready."
47+
echo "[db_file_storage] Backend: https://db-file-storage.ddev.site/typo3"
48+
echo "[db_file_storage] Login: admin / Password.1"
49+
else
50+
echo "[db_file_storage] TYPO3 already set up (${SETTINGS_FILE} exists), skipping."
51+
fi

.github/workflows/ci.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
php-cs-fixer:
10+
name: PHP-CS-Fixer
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: shivammathur/setup-php@v2
15+
with:
16+
php-version: '8.2'
17+
tools: composer
18+
- run: composer install --no-progress --prefer-dist
19+
- run: vendor/bin/php-cs-fixer fix --dry-run --diff
20+
21+
phpstan:
22+
name: PHPStan
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: '8.4'
29+
tools: composer
30+
- run: composer install --no-progress --prefer-dist
31+
- run: vendor/bin/phpstan analyse
32+
33+
tests:
34+
name: Tests (PHP ${{ matrix.php }}, TYPO3 ${{ matrix.typo3 }})
35+
runs-on: ubuntu-latest
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
include:
40+
- php: '8.2'
41+
typo3: '^13.4'
42+
- php: '8.3'
43+
typo3: '^13.4'
44+
- php: '8.3'
45+
typo3: '^14.2'
46+
- php: '8.4'
47+
typo3: '^13.4'
48+
- php: '8.4'
49+
typo3: '^14.2'
50+
- php: '8.5'
51+
typo3: '^14.2'
52+
steps:
53+
- uses: actions/checkout@v4
54+
- uses: shivammathur/setup-php@v2
55+
with:
56+
php-version: ${{ matrix.php }}
57+
extensions: pdo_sqlite, fileinfo
58+
tools: composer
59+
- name: Pin TYPO3 version
60+
run: |
61+
composer require \
62+
typo3/cms-core:${{ matrix.typo3 }} \
63+
typo3/cms-extbase:${{ matrix.typo3 }} \
64+
--no-update
65+
- run: composer install --no-progress --prefer-dist
66+
- name: Functional tests
67+
run: vendor/bin/phpunit -c Tests/phpunit/FunctionalTests.xml
68+
env:
69+
typo3DatabaseDriver: pdo_sqlite

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Build/vendor/
2+
Build/public/
3+
Build/config/
4+
Build/var/
5+
Build/composer.lock
6+
var/
7+
vendor/
8+
public/
9+
10+
# PHPUnit
11+
.phpunit.cache/
12+
.phpunit.result.cache
13+
14+
# PHP-CS-Fixer
15+
.php-cs-fixer.cache
16+
17+
# IDE
18+
.idea/
19+
.vscode/
20+
21+
# OS
22+
.DS_Store

.php-cs-fixer.dist.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
$config = TYPO3\CodingStandards\CsFixerConfig::create();
4+
5+
$config->getFinder()
6+
->in(__DIR__ . '/Classes')
7+
->in(__DIR__ . '/Configuration')
8+
->in(__DIR__ . '/Tests');
9+
10+
return $config;

Build/composer.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "b13/db-file-storage-dev",
3+
"description": "Development TYPO3 installation for working on b13/db-file-storage.",
4+
"type": "project",
5+
"license": "GPL-2.0-or-later",
6+
"require": {
7+
"php": "^8.2",
8+
"typo3/cms-core": "^13.4",
9+
"typo3/cms-backend": "^13.4",
10+
"typo3/cms-frontend": "^13.4",
11+
"typo3/cms-extbase": "^13.4",
12+
"typo3/cms-fluid": "^13.4",
13+
"typo3/cms-install": "^13.4",
14+
"typo3/cms-setup": "^13.4",
15+
"typo3/cms-tstemplate": "^13.4",
16+
"typo3/cms-filelist": "^13.4",
17+
"typo3/cms-info": "^13.4",
18+
"typo3/cms-lowlevel": "^13.4",
19+
"typo3/cms-extensionmanager": "^13.4",
20+
"b13/db-file-storage": "@dev"
21+
},
22+
"require-dev": {
23+
"typo3/testing-framework": "^9.0",
24+
"phpunit/phpunit": "^11.0"
25+
},
26+
"repositories": [
27+
{
28+
"type": "path",
29+
"url": "../",
30+
"options": {
31+
"symlink": true
32+
}
33+
}
34+
],
35+
"config": {
36+
"allow-plugins": {
37+
"typo3/cms-composer-installers": true,
38+
"typo3/class-alias-loader": true
39+
},
40+
"sort-packages": true,
41+
"vendor-dir": "vendor"
42+
},
43+
"extra": {
44+
"typo3/cms": {
45+
"web-dir": "public"
46+
}
47+
},
48+
"scripts": {
49+
"test:functional": [
50+
"TYPO3_PATH_ROOT=$PWD/public typedb=$PWD/../tmp/functional-sqlite-dbs/test_functional.sqlite typo3DatabaseDriver=pdo_sqlite vendor/bin/phpunit -c ../Build/phpunit/FunctionalTests.xml"
51+
]
52+
}
53+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of TYPO3 CMS-based extension "db_file_storage" by b13.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*/
12+
13+
namespace B13\DbFileStorage\Domain\Model;
14+
15+
final class StoredFile
16+
{
17+
public function __construct(
18+
public readonly int $uid,
19+
public readonly string $filename,
20+
public readonly string $mimeType,
21+
public readonly int $size,
22+
public readonly string $sha1,
23+
public readonly string $contents,
24+
public readonly \DateTimeImmutable $createdAt,
25+
) {}
26+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of TYPO3 CMS-based extension "db_file_storage" by b13.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*/
12+
13+
namespace B13\DbFileStorage\Domain\Model;
14+
15+
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
16+
17+
/**
18+
* Extbase entity that maps a row of `tx_dbfilestorage_domain_model_file`.
19+
*
20+
* Use this on the consumer side whenever you want to relate domain models to
21+
* stored files via Extbase MM relations or ObjectStorage<StoredFileReference>
22+
* properties — typical pattern:
23+
*
24+
* // Domain\Model\Model.php
25+
* use B13\DbFileStorage\Domain\Model\StoredFileReference;
26+
*
27+
* class Task extends AbstractEntity
28+
* {
29+
* // @param ObjectStorage<StoredFileReference> $attachments
30+
* public function __construct(
31+
* protected ObjectStorage $attachments,
32+
* // ...
33+
* ) {}
34+
* }
35+
36+
* Note:
37+
* - StoredFile: full data including bytes; what services hand back.
38+
* - StoredFileReference: metadata-only handle; what Extbase relations point at.
39+
*/
40+
class StoredFileReference extends AbstractEntity implements \JsonSerializable
41+
{
42+
protected string $filename = '';
43+
protected string $mimeType = '';
44+
protected int $size = 0;
45+
protected string $sha1 = '';
46+
47+
public function getFilename(): string
48+
{
49+
return $this->filename;
50+
}
51+
52+
public function getMimeType(): string
53+
{
54+
return $this->mimeType;
55+
}
56+
57+
public function getSize(): int
58+
{
59+
return $this->size;
60+
}
61+
62+
public function getSha1(): string
63+
{
64+
return $this->sha1;
65+
}
66+
67+
/**
68+
* @return array<string, mixed>
69+
*/
70+
public function jsonSerialize(): array
71+
{
72+
return [
73+
'uid' => $this->getUid(),
74+
'filename' => $this->filename,
75+
'mimeType' => $this->mimeType,
76+
'size' => $this->size,
77+
'sha1' => $this->sha1,
78+
];
79+
}
80+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of TYPO3 CMS-based extension "db_file_storage" by b13.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*/
12+
13+
namespace B13\DbFileStorage\Domain\Repository;
14+
15+
use B13\DbFileStorage\Domain\Model\StoredFileReference;
16+
use TYPO3\CMS\Extbase\Persistence\Repository;
17+
18+
/**
19+
* @extends Repository<StoredFileReference>
20+
*/
21+
class StoredFileReferenceRepository extends Repository {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of TYPO3 CMS-based extension "db_file_storage" by b13.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*/
12+
13+
namespace B13\DbFileStorage\Exception;
14+
15+
final class FileNotFoundException extends \RuntimeException {}

0 commit comments

Comments
 (0)