From 5420c20d06a46e9d3cdd5e5d321a1ed3db87df68 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Sun, 24 Dec 2017 00:26:02 +0100 Subject: [PATCH 1/3] upgraded the 3.0 migration guide --- doc/migrate_3.0.texy | 65 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/doc/migrate_3.0.texy b/doc/migrate_3.0.texy index 43020e90..053b226f 100644 --- a/doc/migrate_3.0.texy +++ b/doc/migrate_3.0.texy @@ -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. From c789ff5f7d73c7ec7533e2cf5f29e9e55b07ace0 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Wed, 27 Dec 2017 22:53:03 +0100 Subject: [PATCH 2/3] test: renamed BridgeNetteDI DIC finder test --- .../BridgeNetteDI/{config.neon => dic-finder.neon} | 0 .../BridgeNetteDI/{test.di.finder.phpt => dic-finder.phpt} | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename tests/cases/integration/BridgeNetteDI/{config.neon => dic-finder.neon} (100%) rename tests/cases/integration/BridgeNetteDI/{test.di.finder.phpt => dic-finder.phpt} (91%) diff --git a/tests/cases/integration/BridgeNetteDI/config.neon b/tests/cases/integration/BridgeNetteDI/dic-finder.neon similarity index 100% rename from tests/cases/integration/BridgeNetteDI/config.neon rename to tests/cases/integration/BridgeNetteDI/dic-finder.neon diff --git a/tests/cases/integration/BridgeNetteDI/test.di.finder.phpt b/tests/cases/integration/BridgeNetteDI/dic-finder.phpt similarity index 91% rename from tests/cases/integration/BridgeNetteDI/test.di.finder.phpt rename to tests/cases/integration/BridgeNetteDI/dic-finder.phpt index b9877952..9d5fae82 100644 --- a/tests/cases/integration/BridgeNetteDI/test.di.finder.phpt +++ b/tests/cases/integration/BridgeNetteDI/dic-finder.phpt @@ -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) { @@ -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); From 26bee4b814b71e5deae783da0c77e5314a954665 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Wed, 27 Dec 2017 23:21:04 +0100 Subject: [PATCH 3/3] bridges/nette-di: try to init dbal mapper coordinator in beforeCompile when Dbal extension is registered later [closes #270] --- src/Bridges/NetteDI/OrmExtension.php | 2 ++ .../BridgeNetteDI/dic-extension-order.neon | 12 +++++++ .../BridgeNetteDI/dic-extension-order.phpt | 34 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/cases/integration/BridgeNetteDI/dic-extension-order.neon create mode 100644 tests/cases/integration/BridgeNetteDI/dic-extension-order.phpt diff --git a/src/Bridges/NetteDI/OrmExtension.php b/src/Bridges/NetteDI/OrmExtension.php index 4c336d23..f68d9e01 100644 --- a/src/Bridges/NetteDI/OrmExtension.php +++ b/src/Bridges/NetteDI/OrmExtension.php @@ -72,6 +72,8 @@ public function beforeCompile() $this->setupMetadataStorage($repositoriesConfig[2]); $this->setupModel($this->modelClass, $repositoriesConfig); } + + $this->setupDbalMapperDependencies(); } diff --git a/tests/cases/integration/BridgeNetteDI/dic-extension-order.neon b/tests/cases/integration/BridgeNetteDI/dic-extension-order.neon new file mode 100644 index 00000000..8397739e --- /dev/null +++ b/tests/cases/integration/BridgeNetteDI/dic-extension-order.neon @@ -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 diff --git a/tests/cases/integration/BridgeNetteDI/dic-extension-order.phpt b/tests/cases/integration/BridgeNetteDI/dic-extension-order.phpt new file mode 100644 index 00000000..b9af07c4 --- /dev/null +++ b/tests/cases/integration/BridgeNetteDI/dic-extension-order.phpt @@ -0,0 +1,34 @@ +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);