-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # CHANGELOG.md
- Loading branch information
Showing
73 changed files
with
2,826 additions
and
995 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
language: php | ||
php: | ||
- 7.0 | ||
- 5.6 | ||
- 5.5 | ||
- 7.1 | ||
install: | ||
- composer install | ||
services: | ||
|
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
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 was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
namespace Corma\DataObject\Factory; | ||
|
||
use Corma\DataObject\Hydrator\ObjectHydratorInterface; | ||
|
||
abstract class BaseObjectFactory implements ObjectFactoryInterface | ||
{ | ||
protected $reflectionClasses = []; | ||
|
||
/** | ||
* @var ObjectHydratorInterface | ||
*/ | ||
protected $hydrator; | ||
|
||
|
||
public function __construct(ObjectHydratorInterface $hydrator) | ||
{ | ||
$this->hydrator = $hydrator; | ||
} | ||
|
||
public function create($class, array $dependencies = [], array $data = []) | ||
{ | ||
if (empty($dependencies)) { | ||
$object = new $class; | ||
} else { | ||
$reflectionClass = $this->getReflectionClass($class); | ||
$object = $reflectionClass->newInstanceArgs($dependencies); | ||
} | ||
|
||
if (!empty($data)) { | ||
$this->hydrator->hydrate($object, $data); | ||
} | ||
return $object; | ||
} | ||
|
||
protected function getReflectionClass($class) | ||
{ | ||
if (isset($this->reflectionClasses[$class])) { | ||
return $this->reflectionClasses[$class]; | ||
} | ||
return $this->reflectionClasses[$class] = new \ReflectionClass($class); | ||
} | ||
} |
Oops, something went wrong.