Skip to content

Commit

Permalink
Wire ORMAdapter manually instead of using autowire
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Dec 3, 2017
1 parent ab38d22 commit 47e4a40
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ matrix:
include:
- php: 7.0
env: SYMFONY_VERSION=^3.3
- php: 7.0
env: SYMFONY_VERSION=^3.4
- php: 7.0
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 7.1
env: SYMFONY_VERSION=^3.4
- php: 7.2
env: SYMFONY_VERSION=^3.3
- php: 7.2
env: SYMFONY_VERSION=^3.4
- php: 7.2
env: DEPENDENCIES=dev
- php: nightly
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
Nothing yet.

## [0.1.1] - 2017-12-03
### Fixed
- Changed ORMAdapter autowire to manual to avoid compile time failures when optional
dependencies are missing

## 0.1.0 - 2017-12-01
### Added
- Basic functionality

[Unreleased]: https://github.com/omines/datatables-bundle/compare/0.1.0...master
[Unreleased]: https://github.com/omines/datatables-bundle/compare/0.1.1...master
[0.1.1]: https://github.com/omines/datatables-bundle/compare/0.1.0...0.1.1
8 changes: 6 additions & 2 deletions src/Adapter/Doctrine/ORMAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ class ORMAdapter extends AbstractAdapter
/**
* DoctrineAdapter constructor.
*
* @param RegistryInterface $registry
* @param RegistryInterface|null $registry
*/
public function __construct(RegistryInterface $registry)
public function __construct(RegistryInterface $registry = null)
{
if (null === $registry) {
throw new \LogicException('Install doctrine/doctrine-bundle to use the ORMAdapter');
}

parent::__construct();
$this->registry = $registry;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ services:

# Register default adapters via autoconfig/autowire
Omines\DataTablesBundle\Adapter\ArrayAdapter: ~
Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter: ~
Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter:
arguments: ['@?doctrine']

Omines\DataTablesBundle\DataTableFactory:
arguments: ['%datatables.config%', '@datatables.renderer']
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Adapter/DoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider;
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
use Omines\DataTablesBundle\Column\TextColumn;
use Omines\DataTablesBundle\DataTable;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -53,4 +54,13 @@ public function testSearchCriteriaProvider()
// As this is buggy right now ignore the result
$this->assertTrue(true);
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage doctrine/doctrine-bundle
*/
public function testORMAdapterRequiresDependency()
{
(new ORMAdapter());
}
}

0 comments on commit 47e4a40

Please sign in to comment.