Skip to content

Commit

Permalink
Merge pull request #47 from coenjacobs/config-value-object
Browse files Browse the repository at this point in the history
Config value object instead of manually reading the file
  • Loading branch information
coenjacobs authored Sep 11, 2024
2 parents f5c71c1 + 6cf4b13 commit fb98a64
Show file tree
Hide file tree
Showing 36 changed files with 1,077 additions and 512 deletions.
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

0 comments on commit fb98a64

Please sign in to comment.