-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix warning issue for returning entities without results
- Loading branch information
Kazuhiko TAMURA
committed
Jul 6, 2015
1 parent
4a46ba4
commit 57c4d62
Showing
3 changed files
with
106 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,78 @@ | ||
<?php | ||
|
||
namespace Omelet\Domain; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
class ObjectDomain extends DomainBase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $type; | ||
/** | ||
* @var NamedDomain[] | ||
*/ | ||
private $fields; | ||
|
||
public function __construct($type, array $fields) | ||
{ | ||
$this->type = $type; | ||
$this->fields = $fields; | ||
} | ||
|
||
public function getChildren() | ||
{ | ||
return $this->fields; | ||
} | ||
|
||
protected function expandTypesInternal($name, $val) | ||
{ | ||
return $this->expand( | ||
$name, $val, | ||
function ($field, $k, $v) { | ||
return $field->expandTypes($k, $v); | ||
} | ||
); | ||
} | ||
|
||
protected function expandValuesInternal($name, $val) | ||
{ | ||
return $this->expand( | ||
$name, $val, | ||
function ($field, $k, $v) { | ||
return $field->expandValues($k, $v); | ||
} | ||
); | ||
} | ||
|
||
protected function convertResultsInternal($results, AbstractPlatform $platform) | ||
{ | ||
if (is_int(key($results))) { | ||
$results = current($results); | ||
} | ||
|
||
$class = $this->type; | ||
|
||
$obj = new $class(); | ||
|
||
foreach ($this->fields as $name => $domain) { | ||
$obj->{$name} = $domain->convertResults($results, $platform); | ||
} | ||
|
||
return $obj; | ||
} | ||
|
||
private function expand($name, $val, callable $fn) | ||
{ | ||
return array_reduce( | ||
array_keys($this->fields), | ||
function (array &$tmp, $k) use ($name, $val, $fn) { | ||
$n = $name !== '' ? "{$name}_{$k}" : $k; | ||
|
||
return $tmp + [$k => $fn($this->fields[$k], $n, $val->{$k})]; | ||
}, | ||
[] | ||
); | ||
} | ||
|
||
public static function __set_state($values) | ||
{ | ||
return new ObjectDomain($values['type'], $values['fields']); | ||
} | ||
} | ||
<?php | ||
|
||
namespace Omelet\Domain; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
class ObjectDomain extends DomainBase { | ||
/** | ||
* @var string | ||
*/ | ||
private $type; | ||
/** | ||
* @var NamedDomain[] | ||
*/ | ||
private $fields; | ||
|
||
public function __construct($type, array $fields) { | ||
$this->type = $type; | ||
$this->fields = $fields; | ||
} | ||
|
||
public function getChildren() { | ||
return $this->fields; | ||
} | ||
|
||
protected function expandTypesInternal($name, $val) { | ||
return $this->expand( | ||
$name, $val, | ||
function ($field, $k, $v) { | ||
return $field->expandTypes($k, $v); | ||
} | ||
); | ||
} | ||
|
||
protected function expandValuesInternal($name, $val) { | ||
return $this->expand( | ||
$name, $val, | ||
function ($field, $k, $v) { | ||
return $field->expandValues($k, $v); | ||
} | ||
); | ||
} | ||
|
||
protected function convertResultsInternal($results, AbstractPlatform $platform) { | ||
if ($results === false) { | ||
return null; | ||
} | ||
|
||
if (is_int(key($results))) { | ||
$results = current($results); | ||
} | ||
|
||
$class = $this->type; | ||
|
||
$obj = new $class(); | ||
|
||
foreach ($this->fields as $name => $domain) { | ||
$obj->{$name} = $domain->convertResults($results, $platform); | ||
} | ||
|
||
return $obj; | ||
} | ||
|
||
private function expand($name, $val, callable $fn) { | ||
return array_reduce( | ||
array_keys($this->fields), | ||
function (array &$tmp, $k) use($name, $val, $fn) { | ||
$n = $name !== "" ? "{$name}_{$k}" : $k; | ||
return $tmp + [$k => $fn($this->fields[$k], $n, $val->{$k})]; | ||
}, | ||
[] | ||
); | ||
} | ||
|
||
public static function __set_state($values) { | ||
return new ObjectDomain($values['type'], $values['fields']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters