Skip to content

Commit

Permalink
Merge branch 'dic-dbal'
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Dec 27, 2017
2 parents b9cbf31 + 26bee4b commit 4426015
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 17 deletions.
65 changes: 50 additions & 15 deletions doc/migrate_3.0.texy
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,58 @@ BC breaks

The following BC breaks are quite important and you will probably have to deal with them in your code:

- PHP 7.0: this means you have to add newly added typhints to classes that implemnts interfaces from Orm; practically, only typehints in your repositories and mappers will have to be updated;
- Collection: removed comparison operator `!`, use equivalent `!=` operator, e.g. replace `findBy(['name!' => 'Jon'])` with `findBy(['name!=' => 'Jon'])`;
- Entity: all `datetime` properties (types) have to be replaced with `\DateTimeImmutable` type;
- Entity: IEntity::toArray() method was moved from interface to Entity, also the related constants were moved to a helper class; "[commit]":https://github.com/nextras/orm/commit/1f01f75dd5627c25ab8fb745c8b3261bed455849;
- Entity: IEntity::setAsModified() method does not return the entity; "[commit]":https://github.com/nextras/orm/commit/a7c6d7201d58a615e2ecc0f079f12f9e9344a9c3;
- Entity: IEntity::hasValue() throws an exception when property does not exist; "[commit]":https://github.com/nextras/orm/commit/a7c6d7201d58a615e2ecc0f079f12f9e9344a9c3;
- Entity: all event methods are included in the interface definition, therefore if you override them, you will have to changed their visibility modifier to public; "[commit]":https://github.com/nextras/orm/commit/548faa1e7c716f0f0717a5fe0ce5e39fa2a8c669;
- Entity relationships: removed duplicit relationship names in property modifiers, supported are only these with letter `m`, e.g. `1:m`, `m:1`, `m:m` as abbreviation of Many word; "[commit]":https://github.com/nextras/orm/commit/1cc1f2464f15d45265bea1cbd5e59001eb8f4b58;
- Mapper: proxy calls from repository have to return already ICollection or IEntity|null. To achieve this, use DbalMapper::toCollection() or DbalMapper::toEntity() methods; "[commit]":https://github.com/nextras/orm/commit/a7a2744b7a769f472297aa6319d55aceeb0cce81;
- **required PHP 7.0 and new types**
We have added scalar types to Orm interfaces; yours repositorys and mapper will have to be probably updated;
- **Collection: removed comparison operator `!`**
We have removed `!` comparison operator that has been a duplicated of `!=`; use equivalent `!=` operator;
/--php
$collection->findBy(['name!' => 'Jon']);
// replace with
$collection->findBy(['name!=' => 'Jon']);
\--
- **Entity: all `datetime` property types have to be replaced with `\DateTimeImmutable` type;**
We have dropped support for simple `DateTime`, in fact, there is no useful usecase for the mutable type.
During the entity parsing all places will be checked and exception will be thrown if you use the muttable date time.
/--php
/**
* @property DateTime $born
*/
class MyEntity extends Nextras\Orm\Entity\Entity {}

// replace with
/**
* @property DateTimeImmutable $born
*/
class MyEntity extends Nextras\Orm\Entity\Entity {}
\--
- **IEntity::toArray() method was moved away from Entity**
The `Nextras\Orm\Entity\Entity` still contains `toArray()` method; The conversion type constants were moved to the helper.
See the "[commit]":https://github.com/nextras/orm/commit/1f01f75dd5627c25ab8fb745c8b3261bed455849;
- **IEntity::setAsModified() method does not return the entity**
See the "[commit]":https://github.com/nextras/orm/commit/a7c6d7201d58a615e2ecc0f079f12f9e9344a9c3;
- **IEntity::hasValue() throws an exception when property does not exist**
See the "[commit]":https://github.com/nextras/orm/commit/a7c6d7201d58a615e2ecc0f079f12f9e9344a9c3;
- **Entity: all event methods are included in the interface definition**
The events method are currently included in th interface and are called directly when the event should be fixed; Therefore if you override the methods, you will have to changed their visibility modifier to public; "[commit]":https://github.com/nextras/orm/commit/548faa1e7c716f0f0717a5fe0ce5e39fa2a8c669;
- **Entity relationships: removed duplicit relationship names in property modifiers**
We have cleand up the relationship names, currently supported are only these with the letter `m`, e.g. `1:m`, `m:1`, `m:m` as abbreviation of the Many word; "[commit]":https://github.com/nextras/orm/commit/1cc1f2464f15d45265bea1cbd5e59001eb8f4b58;
- **Mapper: proxy calls from repository have to return ICollection or IEntity|null**
We have dropped the magic; the proxied methods on mapper have to return already converted results as IColleciton or IEntity|null; to achieve this, use DbalMapper::toCollection() or DbalMapper::toEntity() methods; "[commit]":https://github.com/nextras/orm/commit/a7a2744b7a769f472297aa6319d55aceeb0cce81;
- **Dbal changes**
Orm 3.0 require Nextras Dbal 3.0. Dbal brigs some datetime handling changes, generally speaking, if you use columns with timezone support, you should be pretty safe to upgrade. See Dbal "3.0.0 release notes":https://github.com/nextras/dbal/releases/tag/v3.0.0.


The following BC breaks are quite internal, in other words, you probably will not have to do anything because of them:

- Model: refactored internals to use Repository loader. "[commit]": https://github.com/nextras/orm/commit/0af0c911a5dddf4f58fc4184f921beff6c393403;
- Entity: removed serilization support, the support was not tested and well covered. Generally speaking, tray to serialize entities' id and refetch it every time you need it;
- Entity: method getRepository throws an exception, when entity is not attached to repository; check the state by IEntity::isAttached() method;
- Entity: virtual properties are never implicitly stored, removed IEntity::SKIP_SET_VALUE; "[commit]": https://github.com/nextras/orm/commit/987ca131e7bc2b49dcdb2d7963ed9c221f0f78c7;
- Entity relationships: refactored iterators and collections internals; "[commit]":https://github.com/nextras/orm/commit/f4cf22baef87a7ad5232d6d877616e96f1b67d36, "[commit]":https://github.com/nextras/orm/commit/eabd333e96b026debc9fe5c63ea9347725638625, "[commit]":https://github.com/nextras/orm/commit/f3a589a4b7e640b94079a5d60dc82ed0920c01fc;
- Model: refactored internals to use Repository loader.
See the "[commit]":https://github.com/nextras/orm/commit/0af0c911a5dddf4f58fc4184f921beff6c393403;
- Entity: removed serilization support, the support was not tested and well covered.
We encourage to serialize entity id and refetch the entity every time you need it;
- Entity: method getRepository throws an exception, when entity is not attached to repository;
To check the state use the `IEntity::isAttached()` method;
- Entity: virtual properties are never implicitly stored;
We have removed `IEntity::SKIP_SET_VALUE`; "[commit]":https://github.com/nextras/orm/commit/987ca131e7bc2b49dcdb2d7963ed9c221f0f78c7;
- Entity relationships: refactored iterators and collections internals;
See the relevant commits: "[commit]":https://github.com/nextras/orm/commit/f4cf22baef87a7ad5232d6d877616e96f1b67d36, "[commit]":https://github.com/nextras/orm/commit/eabd333e96b026debc9fe5c63ea9347725638625, "[commit]":https://github.com/nextras/orm/commit/f3a589a4b7e640b94079a5d60dc82ed0920c01fc;
- Entity|Repository: event handling was refactored to own methods, removed fireEvent() methods and replaced with custom methods for each event.
- Repository|Mapper|Model: interface changes
- Repository|Mapper|Model: many interface changes.
2 changes: 2 additions & 0 deletions src/Bridges/NetteDI/OrmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public function beforeCompile()
$this->setupMetadataStorage($repositoriesConfig[2]);
$this->setupModel($this->modelClass, $repositoriesConfig);
}

$this->setupDbalMapperDependencies();
}


Expand Down
12 changes: 12 additions & 0 deletions tests/cases/integration/BridgeNetteDI/dic-extension-order.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extensions:
nextras.orm: Nextras\Orm\Bridges\NetteDI\OrmExtension
nextras.dbal: Nextras\Dbal\Bridges\NetteDI\DbalExtension
nette.cache: Nette\Bridges\CacheDI\CacheExtension(%tempDir%)

nextras.orm:
model: NextrasTests\Orm\Model
repositoryFinder: Nextras\Orm\Bridges\NetteDI\DIRepositoryFinder

services:
- NextrasTests\Orm\ContentsRepository(NextrasTests\Orm\ContentsMapper())
- Nette\Caching\Cache
34 changes: 34 additions & 0 deletions tests/cases/integration/BridgeNetteDI/dic-extension-order.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types = 1);

namespace NextrasTests\Orm\Integration\BridgeNetteDI;

use Nette\DI\Compiler;
use Nette\DI\Container;
use Nette\DI\ContainerLoader;
use Nette\DI\Extensions\ExtensionsExtension;
use Nextras\Orm\Model\IModel;
use Tester\Assert;


require_once __DIR__ . '/../../../bootstrap.php';

function buildDic($config)
{
$cacheDir = TEMP_DIR . '/cache/bridge-nette-dic-extension-order';
$loader = new ContainerLoader($cacheDir);
$key = __FILE__ . ':' . __LINE__ . ':' . $config;
$className = $loader->load(function (Compiler $compiler) use ($config, $cacheDir) {
$compiler->addExtension('extensions', new ExtensionsExtension());
$compiler->addConfig(['parameters' => ['tempDir' => $cacheDir]]);
$compiler->loadConfig($config);
}, $key);

/** @var Container $dic */
$dic = new $className;
return $dic;
}

$container = buildDic(__DIR__ . '/dic-extension-order.neon');
assert($container instanceof Container);

Assert::true($container->findByType(IModel::class) != null);
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require_once __DIR__ . '/../../../bootstrap.php';

function buildDic($config)
{
$cacheDir = TEMP_DIR . '/cache/bridge-nette-di';
$cacheDir = TEMP_DIR . '/cache/bridge-nette-di-dic-finder';
$loader = new ContainerLoader($cacheDir);
$key = __FILE__ . ':' . __LINE__ . ':' . $config;
$className = $loader->load(function (Compiler $compiler) use ($config, $cacheDir) {
Expand All @@ -30,7 +30,7 @@ function buildDic($config)
return $dic;
}

$container = buildDic(__DIR__ . '/config.neon');
$container = buildDic(__DIR__ . '/dic-finder.neon');
assert($container instanceof Container);
$model = $container->getByType(IModel::class);
assert($model instanceof IModel);
Expand Down

0 comments on commit 4426015

Please sign in to comment.