Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config value object instead of manually reading the file #47

Merged
merged 29 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
34434e5
Basic data store value object for config file
coenjacobs May 23, 2020
a1c9467
Logic uses new config value object
coenjacobs May 23, 2020
ef05be4
Static method to directly load a config from a file
coenjacobs May 23, 2020
3921bc0
Load config from file directly where possible
coenjacobs May 23, 2020
13d7920
Fix config object namespace
coenjacobs May 23, 2020
6bfeea0
Merge branch 'master' into config-value-object
coenjacobs Jul 23, 2024
5c08c14
Fix config object implementations
coenjacobs Jul 23, 2024
18ddaa2
Coding standards line length fixes
coenjacobs Jul 23, 2024
9594421
Require jsonmapper to automate reading Composer config
coenjacobs Sep 6, 2024
187e1f6
Added xdebug and config to builder Docker image
coenjacobs Sep 6, 2024
eb99bd7
Implement new config object based on mapped json
coenjacobs Sep 6, 2024
c906eeb
Updated and expanded automated tests to cover config object
coenjacobs Sep 6, 2024
5d346df
Coding standards fixes
coenjacobs Sep 6, 2024
3c3b120
Fixed generic ArrayObject types setting
coenjacobs Sep 6, 2024
59f1f69
Fixed missing trailing directory separator on dependency directory
coenjacobs Sep 7, 2024
87ac263
Test to verify excluded package classes aren't rewritten in included …
coenjacobs Sep 7, 2024
e34a170
Method to always suffix trailing directory separator after classmap path
coenjacobs Sep 7, 2024
cb12e04
Merge main Composer config and Package file into one
coenjacobs Sep 8, 2024
394fdd6
Merge branch 'master' into config-value-object
coenjacobs Sep 9, 2024
1257e9e
Cap PHP version compatibility to 8.0-8.3 for now
coenjacobs Sep 9, 2024
0ac0e87
Make sure config reading returns requested object
coenjacobs Sep 9, 2024
98831c9
Put Package class in Config namespace
coenjacobs Sep 9, 2024
595138b
Abstract direct accessors to config values via methods
coenjacobs Sep 9, 2024
6e2aeeb
Abstract away direct package slugs string access into methods
coenjacobs Sep 9, 2024
15a5bcb
Abstract direct package name method away
coenjacobs Sep 9, 2024
2cbde92
Simplify getting target namespace by including appending \
coenjacobs Sep 9, 2024
8b453e2
ConfigAccessor has now been made redundant by explicit getters and se…
coenjacobs Sep 9, 2024
57c0b61
Cleanup of unused logic and code standards
coenjacobs Sep 9, 2024
6cf4b13
Rewritten logic to load packages and their dependencies
coenjacobs Sep 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
FROM composer:2.7.7
FROM php:8.3.9-cli-alpine AS base

FROM base as builder
FROM base AS builder
RUN apk update && apk add git
RUN apk add --update linux-headers
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug-3.3.2 \
&& docker-php-ext-enable xdebug
COPY ./docker/php/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
COPY ./docker/php/error_reporting.ini /usr/local/etc/php/conf.d/error_reporting.ini
COPY --from=composer /usr/bin/composer /usr/bin/composer
COPY ./ /mozart/
WORKDIR /mozart/
RUN composer install

FROM builder as packager
FROM builder AS packager
RUN rm -rf vendor
RUN composer install --no-dev -o

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"prefer-stable": true,
"license": "MIT",
"require": {
"php": "^8.0"
"php": "^8.0",
"netresearch/jsonmapper": "^4.4"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.4'
services:
builder:
build:
Expand Down
1 change: 1 addition & 0 deletions docker/php/error_reporting.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error_reporting=E_ALL
6 changes: 6 additions & 0 deletions docker/php/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
zend_extension=xdebug

[xdebug]
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<rule ref="PSR2"/>

<rule ref="PHPCompatibility"/>
<config name="testVersion" value="8.0-"/>
<config name="testVersion" value="8.0-8.3"/>

<file>./src</file>
</ruleset>
7 changes: 5 additions & 2 deletions src/Composer/Autoload/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

interface Autoloader
{
public function processConfig($autoloadConfig);
public function getSearchNamespace();
/**
* @param mixed $autoloadConfig
*/
public function processConfig($autoloadConfig): void;
public function getSearchNamespace(): string;
}
36 changes: 0 additions & 36 deletions src/Composer/Autoload/Classmap.php

This file was deleted.

32 changes: 16 additions & 16 deletions src/Composer/Autoload/NamespaceAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ abstract class NamespaceAutoloader implements Autoloader
*
* e.g. src/
*
* @var string[]
* @var array<string>
*/
public $paths = [];

/**
* A package's composer.json config autoload key's value, where $key is `psr-1`|`psr-4`|`classmap`.
*
* @param $autoloadConfig
*
* @return void
*/
public function processConfig($autoloadConfig)
public function processConfig($autoloadConfig): void
{
foreach ($autoloadConfig as $key => $value) {
$this->namespace = $key;
array_push($this->paths, $value);
if (is_array($autoloadConfig)) {
foreach ($autoloadConfig as $path) {
array_push($this->paths, $path);
}
} else {
array_push($this->paths, $autoloadConfig);
}
}

/**
* @return string
*/
public function getSearchNamespace()
public function getNamespace(): string
{
return $this->namespace;
return rtrim($this->namespace, '\\') . '\\';
}

/**
* @return string
*/
public function getNamespacePath()
public function getSearchNamespace(): string
{
return rtrim($this->namespace, '\\');
}

public function getNamespacePath(): string
{
return '';
}
Expand Down
7 changes: 0 additions & 7 deletions src/Composer/Autoload/Psr0.php

This file was deleted.

22 changes: 0 additions & 22 deletions src/Composer/Autoload/Psr4.php

This file was deleted.

69 changes: 0 additions & 69 deletions src/Composer/Package.php

This file was deleted.

67 changes: 67 additions & 0 deletions src/Config/Autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace CoenJacobs\Mozart\Config;

use CoenJacobs\Mozart\Composer\Autoload\Autoloader;
use stdClass;

class Autoload
{
/** @var array<Autoloader> */
public array $autoloaders = [];

public function setupAutoloaders(stdClass $autoloadData): void
{
$autoloaders = [];

if (isset($autoloadData->{'psr-4'})) {
$psr4Autoloaders = (array) $autoloadData->{'psr-4'};
foreach ($psr4Autoloaders as $key => $value) {
$autoloader = new Psr4();
$autoloader->namespace = $key;
$autoloader->processConfig($value);
$autoloaders[] = $autoloader;
}
}

if (isset($autoloadData->{'psr-0'})) {
$psr0Autoloaders = (array) $autoloadData->{'psr-0'};
foreach ($psr0Autoloaders as $key => $value) {
$autoloader = new Psr0();
$autoloader->namespace = $key;
$autoloader->processConfig($value);
$autoloaders[] = $autoloader;
}
}

if (isset($autoloadData->classmap)) {
$autoloader = new Classmap();
$autoloader->processConfig($autoloadData->classmap);
$autoloaders[] = $autoloader;
}

$this->setAutoloaders($autoloaders);
}

/**
* @param array<Autoloader> $autoloaders
*/
public function setAutoloaders(array $autoloaders): void
{
foreach ($autoloaders as $autoloader) {
if (! $autoloader instanceof Autoloader) {
continue;
}

array_push($this->autoloaders, $autoloader);
}
}

/**
* @return Autoloader[]
*/
public function getAutoloaders(): array
{
return $this->autoloaders;
}
}
37 changes: 37 additions & 0 deletions src/Config/Classmap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace CoenJacobs\Mozart\Config;

use CoenJacobs\Mozart\Composer\Autoload\Autoloader;
use Exception;

class Classmap implements Autoloader
{
/** @var string[] */
public $files = [];

/** @var string[] */
public $paths = [];

/**
* @inheritdoc
*/
public function processConfig($autoloadConfig): void
{
foreach ($autoloadConfig as $value) {
if ('.php' == substr($value, -4, 4)) {
array_push($this->files, $value);
} else {
array_push($this->paths, $value);
}
}
}

/**
* @throws Exception
*/
public function getSearchNamespace(): string
{
throw new Exception('Classmap autoloaders do not contain a namespace and this method can not be used.');
}
}
13 changes: 13 additions & 0 deletions src/Config/Extra.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace CoenJacobs\Mozart\Config;

class Extra
{
public ?Mozart $mozart = null;

public function getMozart(): ?Mozart
{
return $this->mozart;
}
}
Loading
Loading