Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Jan 10, 2024
0 parents commit 95188b3
Show file tree
Hide file tree
Showing 102 changed files with 7,030 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; top-most EditorConfig file
root = true

; Unix-style newlines
[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true

[*.{php,html,twig}]
indent_style = space
indent_size = 4

[*.md]
max_line_length = 80

[COMMIT_EDITMSG]
max_line_length = 0
65 changes: 65 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Test

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

strategy:
matrix:
operating-system: [ubuntu-latest]
php: [ '8.2', '8.3' ]
symfony: [ '6.*', '7.*' ]
dep: [highest,lowest]

runs-on: ${{ matrix.operating-system }}

name: Symfony ${{ matrix.symfony }}, ${{ matrix.dep }} deps, PHP ${{ matrix.php }}, ${{ matrix.operating-system }}

steps:
- uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: intl
tools: flex

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dep }}
composer-options: --prefer-dist --no-progress --ignore-platform-reqs
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}

- name: Run psalm
run: vendor/bin/psalm

- name: Run phpstan
run: vendor/bin/phpstan analyse

- name: Run phpunit
run: |
export SYMFONY_DEPRECATIONS_HELPER='max[direct]=0'
vendor/bin/phpunit --testdox -v
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
composer.lock
vendor/
.phpunit.cache
tools
.php-cs-fixer.cache
var
4 changes: 4 additions & 0 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="php-cs-fixer" version="^3.42.0" installed="3.42.0" location="./tools/php-cs-fixer" copy="false"/>
</phive>
44 changes: 44 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->in(__DIR__ . '/config')
;

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],

// imports
'fully_qualified_strict_types' => true,
'global_namespace_import' => [
'import_classes' => false,
'import_constants' => false,
'import_functions' => false,
],
'no_leading_import_slash' => true,
'no_unneeded_import_alias' => true,
'no_unused_imports' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => ['const', 'class', 'function']
],
'single_line_after_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'declare_strict_types' => true,
'header_comment' => [
'header' => <<<EOF
This file is part of rekalogika/mapper package.
(c) Priyadi Iman Nurcahyo <https://rekalogika.dev>
For the full copyright and license information, please view the LICENSE file
that was distributed with this source code.
EOF,
]
])
->setFinder($finder)
;
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# CHANGELOG

18 changes: 18 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright (c) 2024-present Priyadi Iman Nurcahyo

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.
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.PHONY: test
test: dump phpstan psalm phpunit

.PHONY: dump
dump:
composer dump-autoload --optimize

.PHONY: phpstan
phpstan:
vendor/bin/phpstan analyse

.PHONY: psalm
psalm:
vendor/bin/psalm

.PHONY: phpunit
phpunit:
$(eval c ?=)
vendor/bin/phpunit --testdox -v $(c)

.PHONY: php-cs-fixer
php-cs-fixer: tools/php-cs-fixer
$< fix --config=.php-cs-fixer.dist.php --verbose --allow-risky=yes

.PHONY: tools/php-cs-fixer
tools/php-cs-fixer:
phive install php-cs-fixer
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# rekalogika/mapper

An object mapper (also called automapper) for PHP and Symfony. It maps an object
to another object. Primarily used to map an entity to a DTO, but also useful for
other mapping purposes.

## Installation

```bash
composer require rekalogika/mapper
```
## Usage

In Symfony projects, simply autowire `MapperInterface`. In non Symfony projects,
instantiate a `MapperFactory`, and use `getMapper()` to get an instance of
`MapperInterface`.

To map objects, you can use the `map()` method of `MapperInterface`.

```php
use Rekalogika\Mapper\MapperInterface;

/** @var MapperInterface $mapper */

$book = new Book();
$result = $mapper->map($book, BookDto::class);

// or map to an existing object

$book = new Book();
$bookDto = new BookDto();
$mapper->map($book, $bookDto);
```
## License

MIT
57 changes: 57 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "rekalogika/mapper",
"description": "An object mapper for PHP and Symfony. Maps an object to another object. Primarily used for transforming an entity to a DTO and vice versa.",
"homepage": "https://rekalogika.dev/mapper",
"type": "symfony-bundle",
"license": "MIT",
"keywords": [
"mapper",
"automapper",
"dto",
"transformation",
"mapping",
"api",
"symfony",
"api-platform"
],
"authors": [
{
"name": "Priyadi Iman Nurcahyo",
"email": "[email protected]"
}
],
"require": {
"psr/container": "^2.0",
"symfony/clock": "^6.4",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/property-access": "^6.4",
"symfony/property-info": "^6.4",
"symfony/serializer": "^6.4"
},
"require-dev": {
"bnf/phpstan-psr-container": "^1.0",
"doctrine/collections": "^2.1",
"ekino/phpstan-banned-code": "^1.0",
"phpstan/phpstan": "^1.10.50",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^9.6",
"psalm/plugin-phpunit": "^0.18.4",
"symfony/framework-bundle": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/phpunit-bridge": "^6.4",
"symfony/var-dumper": "^6.4",
"vimeo/psalm": "^5.18"
},
"autoload": {
"psr-4": {
"Rekalogika\\Mapper\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Rekalogika\\Mapper\\Tests\\": "tests/"
}
}
}
Loading

0 comments on commit 95188b3

Please sign in to comment.