Skip to content

Commit

Permalink
ability to use contructors in entities
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy-j committed May 3, 2019
1 parent 41ed269 commit feacab4
Show file tree
Hide file tree
Showing 229 changed files with 1,094 additions and 867 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"spiral/database": "^2.1",
"doctrine/inflector": "^1.3",
"doctrine/collections": "^1.5",
"doctrine/instantiator": "^1.2",
"zendframework/zend-hydrator": "^2.4"
},
"require-dev": {
Expand Down
7 changes: 6 additions & 1 deletion src/Mapper/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Cycle\ORM\ORMInterface;
use Cycle\ORM\Schema;
use Doctrine\Instantiator;
use Zend\Hydrator;

/**
Expand All @@ -31,6 +32,9 @@ class Mapper extends DatabaseMapper
/** @var Hydrator\HydratorInterface */
protected $hydrator;

/** @var Instantiator\InstantiatorInterface */
protected $instantiator;

/**
* @param ORMInterface $orm
* @param string $role
Expand All @@ -44,6 +48,7 @@ public function __construct(ORMInterface $orm, string $role)

// mappers can request custom hydrator using constructor dependency
$this->hydrator = new Hydrator\Reflection();
$this->instantiator = new Instantiator\Instantiator();
}

/**
Expand All @@ -53,7 +58,7 @@ public function init(array $data): array
{
$class = $this->resolveClass($data);

return [new $class, $data];
return [$this->instantiator->instantiate($class), $data];
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/ORM/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Cycle\ORM\Promise\PromiseFactory;
use Cycle\ORM\Promise\PromiseInterface;
use Cycle\ORM\Relation\Pivoted\PivotedCollectionInterface;
use Cycle\ORM\Relation\Pivoted\PivotedCollectionPromise;
use Cycle\ORM\Relation\Pivoted\PivotedStorage;
use Cycle\ORM\SchemaInterface;
use Doctrine\Common\Collections\Collection;
Expand Down Expand Up @@ -312,7 +313,7 @@ protected function assertEntitySynced(string $eName, array $entity, array $state
continue;
}

if ($eValue instanceof CollectionPromise || $eValue instanceof PivotedCollectionInterface) {
if ($eValue instanceof CollectionPromise || $eValue instanceof PivotedCollectionPromise) {
if (!$eValue->isInitialized()) {
$eValue = $eValue->getPromise();
} else {
Expand All @@ -325,6 +326,9 @@ protected function assertEntitySynced(string $eName, array $entity, array $state

if ($eValue instanceof Collection) {
$eValue = $eValue->toArray();
if ($rValue === null) {
$rValue = [];
}
}

$this->assertEquals(
Expand Down
7 changes: 7 additions & 0 deletions tests/ORM/Classless/ClasslessHasManyPromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Cycle\ORM\Tests\Fixtures\SortByIDConstrain;
use Cycle\ORM\Tests\Traits\TableTrait;
use Cycle\ORM\Transaction;
use Doctrine\Common\Collections\ArrayCollection;

abstract class ClasslessHasManyPromiseTest extends BaseTest
{
Expand Down Expand Up @@ -93,6 +94,12 @@ public function setUp()
]));
}

// public function testInitRelation()
// {
// $u = $this->orm->make('user');
// $this->assertInstanceOf(ArrayCollection::class, $u->comments);
// }

public function testFetchRelation()
{
$selector = new Select($this->orm, 'user');
Expand Down
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/AutoTimestampsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class AutoTimestampsTest extends \Cycle\ORM\Tests\AutoTimestampsTest
{
const DRIVER = "mysql";
class AutoTimestampsTest extends \Cycle\ORM\Tests\AutoTimestampsTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/BelongsToMorphedRelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class BelongsToMorphedRelationTest extends \Cycle\ORM\Tests\Morphed\BelongsToMorphedRelationTest
{
const DRIVER = "mysql";
class BelongsToMorphedRelationTest extends \Cycle\ORM\Tests\Morphed\BelongsToMorphedRelationTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/BelongsToNativeReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class BelongsToNativeReferenceTest extends \Cycle\ORM\Tests\BelongsToNativeReferenceTest
{
const DRIVER = "mysql";
class BelongsToNativeReferenceTest extends \Cycle\ORM\Tests\BelongsToNativeReferenceTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/BelongsToPromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class BelongsToPromiseTest extends \Cycle\ORM\Tests\BelongsToPromiseTest
{
const DRIVER = "mysql";
class BelongsToPromiseTest extends \Cycle\ORM\Tests\BelongsToPromiseTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/BelongsToProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class BelongsToProxyTest extends \Cycle\ORM\Tests\BelongsToProxyTest
{
const DRIVER = "mysql";
class BelongsToProxyTest extends \Cycle\ORM\Tests\BelongsToProxyTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/BelongsToReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class BelongsToReferenceTest extends \Cycle\ORM\Tests\BelongsToReferenceTest
{
const DRIVER = "mysql";
class BelongsToReferenceTest extends \Cycle\ORM\Tests\BelongsToReferenceTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/BelongsToRelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class BelongsToRelationTest extends \Cycle\ORM\Tests\BelongsToRelationTest
{
const DRIVER = "mysql";
class BelongsToRelationTest extends \Cycle\ORM\Tests\BelongsToRelationTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/ClasslessCyclicReferencesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class ClasslessCyclicReferencesTest extends \Cycle\ORM\Tests\Classless\ClasslessCyclicReferencesTest
{
const DRIVER = "mysql";
class ClasslessCyclicReferencesTest extends \Cycle\ORM\Tests\Classless\ClasslessCyclicReferencesTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/ClasslessHasManyPromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class ClasslessHasManyPromiseTest extends \Cycle\ORM\Tests\Classless\ClasslessHasManyPromiseTest
{
const DRIVER = "mysql";
class ClasslessHasManyPromiseTest extends \Cycle\ORM\Tests\Classless\ClasslessHasManyPromiseTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/ClasslessHasOneCyclicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class ClasslessHasOneCyclicTest extends \Cycle\ORM\Tests\Classless\ClasslessHasOneCyclicTest
{
const DRIVER = "mysql";
class ClasslessHasOneCyclicTest extends \Cycle\ORM\Tests\Classless\ClasslessHasOneCyclicTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/ClasslessInverseRelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class ClasslessInverseRelationTest extends \Cycle\ORM\Tests\Classless\ClasslessInverseRelationTest
{
const DRIVER = "mysql";
class ClasslessInverseRelationTest extends \Cycle\ORM\Tests\Classless\ClasslessInverseRelationTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/ClasslessMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class ClasslessMapperTest extends \Cycle\ORM\Tests\Classless\ClasslessMapperTest
{
const DRIVER = "mysql";
class ClasslessMapperTest extends \Cycle\ORM\Tests\Classless\ClasslessMapperTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/ColumnAliasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class ColumnAliasesTest extends \Cycle\ORM\Tests\ColumnAliasesTest
{
const DRIVER = "mysql";
class ColumnAliasesTest extends \Cycle\ORM\Tests\ColumnAliasesTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/CustomRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class CustomRepositoryTest extends \Cycle\ORM\Tests\CustomRepositoryTest
{
const DRIVER = "mysql";
class CustomRepositoryTest extends \Cycle\ORM\Tests\CustomRepositoryTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/CyclicReferencesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class CyclicReferencesTest extends \Cycle\ORM\Tests\CyclicReferencesTest
{
const DRIVER = "mysql";
class CyclicReferencesTest extends \Cycle\ORM\Tests\CyclicReferencesTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/DatetimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class DatetimeTest extends \Cycle\ORM\Tests\DatetimeTest
{
const DRIVER = "mysql";
class DatetimeTest extends \Cycle\ORM\Tests\DatetimeTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/DeepCyclicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class DeepCyclicTest extends \Cycle\ORM\Tests\DeepCyclicTest
{
const DRIVER = "mysql";
class DeepCyclicTest extends \Cycle\ORM\Tests\DeepCyclicTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/DoubleLinkedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class DoubleLinkedTest extends \Cycle\ORM\Tests\DoubleLinkedTest
{
const DRIVER = "mysql";
class DoubleLinkedTest extends \Cycle\ORM\Tests\DoubleLinkedTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/HasManyConstrainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class HasManyConstrainTest extends \Cycle\ORM\Tests\HasManyConstrainTest
{
const DRIVER = "mysql";
class HasManyConstrainTest extends \Cycle\ORM\Tests\HasManyConstrainTest
{
const DRIVER = "mysql";
}
8 changes: 4 additions & 4 deletions tests/ORM/Driver/MySQL/HasManyPromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;
namespace Cycle\ORM\Tests\Driver\MySQL;

class HasManyPromiseTest extends \Cycle\ORM\Tests\HasManyPromiseTest
{
const DRIVER = "mysql";
class HasManyPromiseTest extends \Cycle\ORM\Tests\HasManyPromiseTest
{
const DRIVER = "mysql";
}
Loading

0 comments on commit feacab4

Please sign in to comment.