Skip to content

Commit

Permalink
Updates code so it complies with PHP 8.3
Browse files Browse the repository at this point in the history
This includes some refactoring and bumping up libraries.
  • Loading branch information
fizk committed Jul 5, 2024
1 parent 261b1c9 commit 5224a4d
Show file tree
Hide file tree
Showing 194 changed files with 4,121 additions and 4,545 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,5 @@ $RECYCLE.BIN/
tests/docs
.composer
.bash_history
coverage/*
!coverage/.gitkeep
43 changes: 20 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM php:8.1.8-apache-bullseye
FROM php:8.3.8-apache-bookworm

ARG ENV
ENV PATH="/var/www/alias:/var/www/bin:${PATH}"

EXPOSE 80

Expand Down Expand Up @@ -44,17 +43,25 @@ RUN echo "[PHP]\n\
memory_limit = 2048M \n\
upload_max_filesize = 512M \n\
expose_php = Off \n\n\
date.timezone = Atlantic/Reykjavik \n" >> /usr/local/etc/php/conf.d/php.ini; \
echo "<VirtualHost *:80>\n\
DocumentRoot /var/www/public\n\
ErrorLog \${APACHE_LOG_DIR}/error.log\n\
CustomLog \${APACHE_LOG_DIR}/access.log combined\n\
RewriteEngine On\n\
RewriteRule ^index\.php$ - [L]\n\
RewriteCond %{REQUEST_FILENAME} !-f\n\
RewriteCond %{REQUEST_FILENAME} !-d\n\
RewriteRule . /index.php [L]\n\
</VirtualHost>\n" > /etc/apache2/sites-available/000-default.conf;
date.timezone = Atlantic/Reykjavik \n" >> /usr/local/etc/php/conf.d/php.ini;

RUN echo "<VirtualHost *:80> \n\
ServerAdmin webmaster@localhost \n\
DocumentRoot /var/www/public \n\
ErrorLog \${APACHE_LOG_DIR}/error.log \n\
CustomLog \${APACHE_LOG_DIR}/access.log combined \n\
<Directory /var/www/public/> \n\
Options Indexes FollowSymLinks \n\
AllowOverride None \n\
Require all granted \n\n\
\
RewriteEngine on \n\
RewriteCond %{REQUEST_FILENAME} !-d \n\
RewriteCond %{REQUEST_FILENAME} !-f \n\
RewriteRule . index.php [L] \n\
</Directory> \n\
</VirtualHost>" > /etc/apache2/sites-available/000-default.conf;


# If Production, configures PHP's JIT
# environment and sets a resonable buffer size and memory.
Expand Down Expand Up @@ -88,16 +95,6 @@ RUN if [ "$ENV" != "production" ] ; then \
# That is the user that is already configured to run Apache
WORKDIR /var/www

# If not Production, add scripts to run `phpunit` and `cover`
RUN if [ "$ENV" != "production" ] ; then \
mkdir -p /var/www/alias; \
echo "#!/bin/bash\n/var/www/vendor/bin/phpunit \$@" >> /var/www/alias/phpunit; \
chmod u+x /var/www/alias/phpunit; \
echo "#!/bin/bash\nXDEBUG_MODE=coverage /var/www/vendor/bin/phpunit --coverage-html=/var/www/tests/docs" >> /var/www/alias/cover; \
chmod u+x /var/www/alias/cover; \
fi ;


# Copy dependenices for Composer into container
# Install Composer and then install Coposer dependencies
# based off of it the mode is Production or Development
Expand Down
20 changes: 16 additions & 4 deletions bin/database-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@
/** @var PDO */
$pdo = $serviceManager->get(PDO::class);

// $statement = new class {
// public function execute(){}
// public function rowCount(){return rand(0,1);}
// };

echo "Starting database migration " . PHP_EOL;
// $pdo = new class ($statement) {
// public function __construct(private $statement){}
// public function prepare(){
// return $this->statement;
// }
// public function exec() {}
// };

$scriptPaths = array_map(
fn (string $path) => new SplFileInfo(realpath("$scriptDirectory/$path")),
scandir(realpath($scriptDirectory))
);

echo "\e[1;33mStarting database migration from ".realpath($scriptDirectory)."\e[0m\n";

foreach ($scriptPaths as $fileInfo) {
if ($fileInfo->getExtension() !== 'sql') {
continue;
Expand All @@ -39,11 +51,11 @@
$resultCount = $statusStatement->rowCount();

if ($resultCount !== 0) {
echo "Skipping " . $fileInfo->getFilename() . PHP_EOL;
echo "\e[0;31mSkipping\e[0m\t" . $fileInfo->getFilename() . PHP_EOL;
continue;
}

echo "Processing " . $fileInfo->getFilename() . PHP_EOL;
echo "\e[0;32mProcessing\e[0m\t" . $fileInfo->getFilename() . PHP_EOL;

$script = file_get_contents($fileInfo->getPathname());
$pdo->exec($script);
Expand All @@ -55,4 +67,4 @@
}
}

echo "Ending database migration " . PHP_EOL;
echo "\e[1;33mEnding database migration\e[0m\n";
82 changes: 38 additions & 44 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
{
"name": "fizk/althingi-source",
"description": "API and main data-store for the Loggjafarthing system",
"type": "project",
"license": "BSD-3-Clause",
"keywords": [],
"homepage": "https://github.com/fizk/althingi-source",
"repositories": [],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"league/html-to-markdown": "^5.1",
"monolog/monolog": "^3.6",
"zeptech/annotations": "^1.2",
"laminas/laminas-diactoros": "^3.3",
"laminas/laminas-httphandlerrunner": "^2.10",
"laminas/laminas-inputfilter": "^2.30",
"laminas/laminas-hydrator": "^4.15",
"league/event": "^3.0",
"laminas/laminas-stdlib": "^3.19",
"laminas/laminas-servicemanager": "3.21",
"fizk/library": "^0.2"
},
"scripts": {
"sniff": "./vendor/bin/phpcs --standard=PSR12 ./config ./src ./tests",
"fix": "./vendor/bin/phpcbf --standard=PSR12 ./config ./src ./tests",
"test": "./vendor/bin/phpunit --colors=always ./tests",
"cover": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html=coverage --coverage-filter=./src --coverage-filter=./tests",
"db-migrate": "./bin/database-migration.php"
},
"autoload": {
"psr-4": {
"Althingi\\": "src/"
"name": "fizk/althingi-source",
"description": "API and main data-store for the Loggjafarthing system",
"type": "project",
"license": "BSD-3-Clause",
"keywords": [],
"homepage": "https://github.com/fizk/althingi-source",
"repositories": [],
"minimum-stability": "dev",
"require": {
"fizk/library": "^0.3",
"laminas/laminas-httphandlerrunner": "2.11.x-dev",
"league/event": "^3.0@dev",
"monolog/monolog": "^3.0@dev",
"league/html-to-markdown": "^5.2@dev",
"zeptech/annotations": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^11.3@dev",
"mockery/mockery": "2.0.x-dev",
"squizlabs/php_codesniffer": "4.0.x-dev",
"kornrunner/dbunit": "^9.0"
},
"scripts": {
"sniff": "./vendor/bin/phpcs --standard=PSR12 ./config ./src ./tests",
"fix": "./vendor/bin/phpcbf --standard=PSR12 ./config ./src ./tests",
"test": "./vendor/bin/phpunit --colors=always ./tests",
"cover": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html=./coverage --coverage-filter=./src ./tests",
"db-migrate": "./bin/database-migration.php"
},
"autoload": {
"psr-4": {
"Althingi\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Althingi\\": "tests/"
}
}
},
"autoload-dev": {
"psr-4": {
"Althingi\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^10.5",
"mockery/mockery": "^1.6",
"squizlabs/php_codesniffer": "^3.10",
"kornrunner/dbunit": "^9.0"
}
}
Loading

0 comments on commit 5224a4d

Please sign in to comment.