Skip to content

Commit

Permalink
ODM Factories (#1)
Browse files Browse the repository at this point in the history
* add necessary factories and tests to create a DocumentManager
* allow PHP 8
* add LICENSE
  • Loading branch information
rieschl authored Aug 1, 2021
1 parent e202e83 commit d814e6a
Show file tree
Hide file tree
Showing 26 changed files with 1,085 additions and 43 deletions.
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.github/ export-ignore
/features/ export-ignore
/tests/ export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/composer-require-checker.json export-ignore
/infection.json export-ignore
/phpcs.xml export-ignore
/phpstan.neon export-ignore
/phpstan-baseline.neon export-ignore
/phpunit.xml export-ignore
/psalm.xml export-ignore
35 changes: 24 additions & 11 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ on: [pull_request]
jobs:
build:

strategy:
matrix:
php: ["7.4", "8.0"]

runs-on: ubuntu-latest
container:
image: eventjet/checks-7.4:latest
image: eventjet/checks-${{ matrix.php }}:latest

steps:
- name: Checkout
Expand All @@ -17,22 +21,30 @@ jobs:
run: |
mkdir -p /root/.ssh
ssh-keyscan -t rsa github.com >> /root/.ssh/known_hosts
echo "COMPOSER_CACHE=$(composer config cache-dir)" >> $GITHUB_ENV
- name: Composer Cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: $(composer config cache-files-dir)
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
path: |
${{ env.COMPOSER_CACHE }}
vendor
key: ${{ runner.os }}-composer

- name: Install dependencies
run: |
composer install --no-progress --no-suggest --no-interaction > /dev/null
composer update --no-progress --no-interaction ${{ matrix.composer_args }} > /dev/null
- name: Static analysis
# composer-require-checker on PHP8 trips on
# doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup/Match.php
# (https://github.com/doctrine/mongodb-odm/issues/2222)
- name: Check Dependencies
if: matrix.php != '8.0'
run: |
composer check-deps
- name: Static analysis
run: |
composer cs-check
composer phpstan -- --no-progress
composer psalm
Expand All @@ -44,9 +56,10 @@ jobs:
- name: Monitor coverage
if: github.event_name == 'pull_request'
uses: slavcodev/coverage-monitor-action@1.1.0
uses: slavcodev/coverage-monitor-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
clover_file: "coverage.xml"
threshold_alert: 99
threshold_warning: 99
comment_context: PHP ${{ matrix.php }}
threshold_alert: 100
threshold_warning: 100
20 changes: 0 additions & 20 deletions .scrutinizer.yml

This file was deleted.

31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog

All notable changes to this project will be documented in this file, in reverse chronological order by release.

File automatically generated with [phly/keep-a-changelog](https://github.com/phly/keep-a-changelog)

## 0.1.0 - 2021-08-01

This first release is actually considered stable, but it uses common factories from `roave/psr-container-doctrine`
which requires `doctrine/orm`. If you use Doctrine ORM anyway or if you don't mind having an unnecessary dependency,
go ahead :)

### Added

- [#1](https://github.com/eventjet/eventjet-psr-container-doctrine-odm/pull/1) adds all factories to create a DocumentManager

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.
31 changes: 31 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
MIT License

Copyright (c) 2020 Eventjet

Parts of the code are derived from roave/psr-container-doctrine and are subject to the BSD 2-Clause license
(https://github.com/Roave/psr-container-doctrine/blob/master/LICENSE).
Copyright 2016-2020 Ben Scholzen
Copyright 2020 Roave

Parts of the code are derived from roave/psr-container-doctrine and are subject to the MIT License
(https://github.com/doctrine/DoctrineMongoODMModule/blob/master/LICENSE).
Copyright (c) 2006-2012 Doctrine Project


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# psr-container-doctrine-odm: Doctrine MongoDB ODM factories for PSR-11 containers

This package provides additional factories for Doctrine MongoDB ODM on top of
[`roave/psr-container-doctrine`](https://github.com/Roave/psr-container-doctrine) to be used with containers
using the PSR-11 standard.

## Installation

```bash
$ composer require eventjet/psr-container-doctrine-odm
```

## Configuration

The most basic way is just defining the factory for the `DocumentManager`. Everything else is taken from the
configuration.

```php
return [
'dependencies' => [
'factories' => [
DocumentManager::class => DocumentManagerFactory::class,
],
],
];
```

### Example Configuration

A full example of the configuration can be found in the [examples](example/full-config.php) folder.

The configuration style is heavily based
on [`roave/psr-container-doctrine`](https://github.com/Roave/psr-container-doctrine/blob/3.1.x/example/full-config.php)
to retain the familiarity. Also, the configuration _should_ be compatible with the
['DoctrineMongoODMModule for Laminas](https://github.com/doctrine/DoctrineMongoODMModule).
20 changes: 13 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@
"description": "Doctrine ODM factory for PSR-11 container",
"license": "MIT",
"require": {
"php": "^7.4"
"php": "^7.4 || ^8.0",
"doctrine/mongodb-odm": "^2.0",
"mongodb/mongodb": "^1.6",
"psr/container": "^1.1 || ^2.0",
"roave/psr-container-doctrine": "^3.0",
"thecodingmachine/safe": "^1.2"
},
"require-dev": {
"eventjet/coding-standard": "^3.1",
"infection/infection": "^0.17.0",
"maglnet/composer-require-checker": "^2.1",
"infection/infection": "^0.24.0",
"laminas/laminas-servicemanager": "^3.4",
"maglnet/composer-require-checker": "^3.3",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.32",
"phpstan/phpstan-phpunit": "^0.12.11",
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpunit/phpunit": "^9.3",
"psalm/plugin-phpunit": "^0.16.1",
"thecodingmachine/phpstan-safe-rule": "^1.0",
"vimeo/psalm": "^3.11"
"vimeo/psalm": "^4.0"
},
"config": {
"sort-packages": true
Expand All @@ -28,17 +35,16 @@
},
"autoload-dev": {
"psr-4": {
"Eventjet\\Test\\Functional\\PsrContainerDoctrineOdm\\": "tests/functional",
"Eventjet\\Test\\Unit\\PsrContainerDoctrineOdm\\": "tests/unit"
"Eventjet\\Test\\Functional\\PsrContainerDoctrineOdm\\": "tests/functional"
}
},
"minimum-stability": "stable",
"scripts": {
"check": [
"@check-deps",
"@cs-check",
"@psalm",
"@phpstan",
"@psalm",
"@phpunit",
"@infection"
],
Expand Down
55 changes: 55 additions & 0 deletions example/full-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* This configuration is based on the config of roave/psr-container-doctrine to retain familiarity with its style.
* Factories which are used from roave/psr-container-doctrine
* (namely the \Roave\PsrContainerDoctrine\EventManagerFactory) have the same configuration except that the default
* 'odm_default' is used.
*
* @see https://github.com/Roave/psr-container-doctrine/blob/3.1.x/example/full-config.php
*/

declare(strict_types=1);

use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository as DefaultDocumentRepository;

return [
'doctrine' => [
'configuration' => [
'odm_default' => [
'metadata_cache' => 'array',
'generate_proxies' => Configuration::AUTOGENERATE_EVAL,
'proxy_dir' => 'data',
'proxy_namespace' => 'DoctrineMongoODMModule\Proxy',
'generate_hydrators' => Configuration::AUTOGENERATE_ALWAYS,
'hydrator_dir' => 'data',
'hydrator_namespace' => 'DoctrineMongoODMModule\Hydrator',
'generate_persistent_collections' => Configuration::AUTOGENERATE_ALWAYS,
'persistent_collection_dir' => 'data',
'persistent_collection_namespace' => 'DoctrineMongoODMModule\PersistentCollection',
'persistent_collection_factory' => null,
'persistent_collection_generator' => null,
'default_db' => null,
'filters' => [],
'class_metadata_factory_name' => null,
'repository_factory' => null,
'types' => [],
'driver' => 'odm_default', // Actually defaults to the configuration config key, not hard-coded
'default_document_repository_class_name' => DefaultDocumentRepository::class,
],
],
'connection' => [
'odm_default' => [
'server' => 'localhost',
'port' => '27017',
'user' => null,
'password' => null,
'dbname' => null,
'connection_string' => null,
'uri_options' => [],
'configuration' => 'odm_default', // Actually defaults to the configuration config key, not hard-coded
],
],
],
];
5 changes: 4 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0"?>
<ruleset name="Eventjet coding standard">
<rule ref="EventjetStrict"/>
<rule ref="EventjetStrict">
<exclude-pattern>tests/functional/TestDouble/DummyRepository.php</exclude-pattern>
</rule>
<file>example</file>
<file>src</file>
<file>tests</file>
</ruleset>
3 changes: 0 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
verbose="true"
>
<testsuites>
<testsuite name="Eventjet\PsrContainerDoctrineOdm\Unit">
<directory>tests/unit</directory>
</testsuite>
<testsuite name="Eventjet\PsrContainerDoctrineOdm\Functional">
<directory>tests/functional</directory>
</testsuite>
Expand Down
9 changes: 8 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<psalm
strictBinaryOperands="true"
errorLevel="1"
errorLevel="2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand All @@ -13,4 +13,11 @@
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<issueHandlers>
<InternalClass errorLevel="info"/>
<InternalMethod errorLevel="info"/>
</issueHandlers>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>
29 changes: 29 additions & 0 deletions src/Service/AbstractOdmFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* The following class was derived from roave/psr-container-doctrine
*
* https://github.com/Roave/psr-container-doctrine/blob/master/src/AbstractFactory.php
*
* Code subject to the BSD 2-Clause license (https://github.com/Roave/psr-container-doctrine/blob/master/LICENSE).
*
* Copyright 2016-2020 Ben Scholzen
* Copyright 2020 Roave
*/

declare(strict_types=1);

namespace Eventjet\PsrContainerDoctrineOdm\Service;

use Psr\Container\ContainerInterface;
use Roave\PsrContainerDoctrine\AbstractFactory;

abstract class AbstractOdmFactory extends AbstractFactory
{
private string $configKey = 'odm_default';

public function __invoke(ContainerInterface $container): object
{
return $this->createWithConfig($container, $this->configKey);
}
}
Loading

0 comments on commit d814e6a

Please sign in to comment.