Skip to content

Commit

Permalink
Merge pull request #1 from sunrise-php/release/v1.19.0
Browse files Browse the repository at this point in the history
v1.19.0
  • Loading branch information
fenric authored May 10, 2021
2 parents d2d892b + d0f40c0 commit 78dc567
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Autorus Ltd.
Copyright (c) 2019 Sunrise // PHP

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
## Doctrine Bridge for PHP 7.2+ (incl. PHP 8) based on PHP-DI

[![Build Status](https://circleci.com/gh/autorusltd/doctrine-bridge.svg?style=shield)](https://circleci.com/gh/autorusltd/doctrine-bridge)
[![Code Coverage](https://scrutinizer-ci.com/g/autorusltd/doctrine-bridge/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/autorusltd/doctrine-bridge/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/autorusltd/doctrine-bridge/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/autorusltd/doctrine-bridge/?branch=master)
[![Total Downloads](https://poser.pugx.org/arus/doctrine-bridge/downloads)](https://packagist.org/packages/arus/doctrine-bridge)
[![Latest Stable Version](https://poser.pugx.org/arus/doctrine-bridge/v/stable)](https://packagist.org/packages/arus/doctrine-bridge)
[![License](https://poser.pugx.org/arus/doctrine-bridge/license)](https://packagist.org/packages/arus/doctrine-bridge)
[![Build Status](https://circleci.com/gh/sunrise-php/doctrine-bridge.svg?style=shield)](https://circleci.com/gh/sunrise-php/doctrine-bridge)
[![Code Coverage](https://scrutinizer-ci.com/g/sunrise-php/doctrine-bridge/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/doctrine-bridge/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sunrise-php/doctrine-bridge/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/doctrine-bridge/?branch=master)
[![Total Downloads](https://poser.pugx.org/sunrise/doctrine-bridge/downloads)](https://packagist.org/packages/sunrise/doctrine-bridge)
[![Latest Stable Version](https://poser.pugx.org/sunrise/doctrine-bridge/v/stable)](https://packagist.org/packages/sunrise/doctrine-bridge)
[![License](https://poser.pugx.org/sunrise/doctrine-bridge/license)](https://packagist.org/packages/sunrise/doctrine-bridge)

---

## Installation

```bash
composer require 'arus/doctrine-bridge:^1.18'
composer require 'sunrise/doctrine-bridge:^1.19'
```

## Examples of using
Expand Down Expand Up @@ -200,4 +200,6 @@ $hydrator->hydrate(Entity::class, [
]);
```

Based on:

* https://github.com/pmill/doctrine-array-hydrator
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "arus/doctrine-bridge",
"homepage": "https://github.com/autorusltd/doctrine-bridge",
"description": "Arus // Doctrine Bridge for PHP 7.2+ (incl. PHP 8) based on PHP-DI",
"name": "sunrise/doctrine-bridge",
"homepage": "https://github.com/sunrise-php/doctrine-bridge",
"description": "Sunrise // Doctrine Bridge for PHP 7.2+ (incl. PHP 8) based on PHP-DI",
"license": "MIT",
"keywords": [
"arus",
Expand All @@ -25,8 +25,8 @@
"symfony/string": "^5.0"
},
"require-dev": {
"sunrise/coding-standard": "1.0.0",
"phpunit/phpunit": "7.5.20|9.5.0",
"arus/php-coding-standard": "^1.0",
"php-di/php-di": "^6.0",
"doctrine/orm": "^2.7",
"doctrine/migrations": "^2.2",
Expand Down
4 changes: 2 additions & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset name="Arus Coding Standard">
<rule ref="./vendor/arus/php-coding-standard/ruleset.xml"/>
<ruleset name="Sunrise Coding Standard">
<rule ref="./vendor/sunrise/php-coding-standard/ruleset.xml"/>

<file>src</file>
<file>tests</file>
Expand Down
28 changes: 28 additions & 0 deletions src/ArrayHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,34 @@
class ArrayHydrator extends BaseArrayHydrator
{

/**
* {@inheritDoc}
*/
protected function hydrateToOneAssociation($entity, $propertyName, $mapping, $value)
{
$entityRef = new ReflectionClass($entity);

$setterRef = $this->findSetterForPropertyName($propertyName, $entityRef);
if (null === $setterRef) {
return $entity;
}

if (null === $value) {
$setterRef->invoke($entity, null);
return $entity;
}

$targetEntity = is_array($value) ?
$this->hydrate($mapping['targetEntity'], $value) :
$this->fetchAssociationEntity($mapping['targetEntity'], $value);

if ($targetEntity instanceof $mapping['targetEntity']) {
$setterRef->invoke($entity, $targetEntity);
}

return $entity;
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 78dc567

Please sign in to comment.