Skip to content

Commit

Permalink
Merge pull request #3 from ipublikuj/dropnette2
Browse files Browse the repository at this point in the history
Drop Nette 2 support
  • Loading branch information
akadlec authored Feb 14, 2020
2 parents 99102c9 + f03bc41 commit 690fd1c
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 179 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
vendor
tests/temp
.idea
/vendor
/composer.lock
tests/*/output
6 changes: 2 additions & 4 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ checks:
build:
environment:
php:
version: 7.2
variables:
NETTE: default
version: 7.3

dependencies:
before:
Expand All @@ -16,7 +14,7 @@ build:
tests:
override:
-
command: 'vendor/bin/tester tests -p php -c ./tests/php.ini-unix --coverage build/logs/clover.xml --coverage-src src'
command: 'vendor/bin/tester -s -p php -c ./tests/php.ini-unix tests --coverage build/logs/clover.xml --coverage-src src'
coverage:
file: build/logs/clover.xml
format: php-clover
Expand Down
21 changes: 0 additions & 21 deletions .travis.composer.php

This file was deleted.

14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
language: php

env:
- NETTE=default
- NETTE=~2.4.0

php:
- 7.2
- 7.3

before_install:
# turn off XDebug
- phpenv config-rm xdebug.ini || return 0
- composer self-update

before_script:
- php .travis.composer.php
- composer install --no-interaction --prefer-source --dev
- travis_retry composer install --no-progress --prefer-dist

script:
- vendor/bin/tester -s -p php -c ./tests/php.ini-unix tests

after_failure:
- 'for i in $(find ./tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done'
# Print *.actual content
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done
23 changes: 12 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,36 @@
"extra" : {
"ipub" : {
"configuration" : {
"extensions" : {
"doctrineCrud" : "IPub\\DoctrineCrud\\DI\\DoctrineCrudExtension"
}
"extension" : "IPub\\DoctrineCrud\\DI\\DoctrineCrudExtension"
}
}
},

"require" : {
"php" : ">=7.2.0",
"php" : ">=7.3.0",

"doctrine/orm" : "~2.5",

"nette/di" : "~2.4 || ~3.0",
"nette/utils" : "~2.5 || ~3.0",
"nette/reflection" : "~2.4"
"phpdocumentor/reflection-docblock": "^5.0",

"nette/di" : "~3.0",
"nette/utils" : "~3.0"
},

"require-dev" : {
"nette/bootstrap" : "~2.4 || ~3.0",
"nette/mail" : "~2.4 || ~3.0",
"nette/robot-loader" : "~2.4 || ~3.0",
"nette/bootstrap" : "~3.0",
"nette/http" : "~3.0",
"nette/mail" : "~3.0",
"nette/robot-loader" : "~3.0",
"nette/safe-stream" : "~2.3",
"nette/tester" : "~2.3",

"tracy/tracy" : "~2.4",

"pds/skeleton" : "~1.0",

"nettrine/orm" : "~0.3"
"nettrine/orm" : "~0.3",
"contributte/console" : "~0.7"
},

"autoload" : {
Expand Down
112 changes: 45 additions & 67 deletions src/IPub/DoctrineCrud/DI/DoctrineCrudExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace IPub\DoctrineCrud\DI;

use Doctrine;
use Doctrine\Common;

use Nette;
Expand Down Expand Up @@ -75,69 +76,37 @@ public function loadConfiguration() : void
* CRUD factories
*/

// NETTE 3.x
if (method_exists($builder, 'addFactoryDefinition')) {
$builder->addFactoryDefinition($this->prefix('entity.creator'))
->setImplement(Crud\Create\IEntityCreator::class)
->setAutowired(FALSE)
->getResultDefinition()
->setType(Crud\Create\EntityCreator::class);

$builder->addFactoryDefinition($this->prefix('entity.updater'))
->setImplement(Crud\Update\IEntityUpdater::class)
->setAutowired(FALSE)
->getResultDefinition()
->setFactory(Crud\Update\EntityUpdater::class);

$builder->addFactoryDefinition($this->prefix('entity.deleter'))
->setImplement(Crud\Delete\IEntityDeleter::class)
->setAutowired(FALSE)
->getResultDefinition()
->setFactory(Crud\Delete\EntityDeleter::class);

// Syntax sugar for config
$builder->addFactoryDefinition($this->prefix('crud'))
->setImplement(Crud\IEntityCrudFactory::class)
->setParameters(['entityName'])
->getResultDefinition()
->setType(Crud\EntityCrud::class)
->setArguments([
new PhpGenerator\PhpLiteral('$entityName'),
'@' . $this->prefix('entity.mapper'),
'@' . $this->prefix('entity.creator'),
'@' . $this->prefix('entity.updater'),
'@' . $this->prefix('entity.deleter'),
]);

// NETTE 2.4+
} else {
$builder->addDefinition($this->prefix('entity.creator'))
->setType(Crud\Create\EntityCreator::class)
->setImplement(Crud\Create\IEntityCreator::class)
->setAutowired(FALSE);

$builder->addDefinition($this->prefix('entity.updater'))
->setType(Crud\Update\EntityUpdater::class)
->setImplement(Crud\Update\IEntityUpdater::class)
->setAutowired(FALSE);

$builder->addDefinition($this->prefix('entity.deleter'))
->setType(Crud\Delete\EntityDeleter::class)
->setImplement(Crud\Delete\IEntityDeleter::class)
->setAutowired(FALSE);

$builder->addDefinition($this->prefix('crud'))
->setType(Crud\EntityCrud::class)
->setImplement(Crud\IEntityCrudFactory::class)
->setParameters(['entityName'])
->setArguments([
new PhpGenerator\PhpLiteral('$entityName'),
'@' . $this->prefix('entity.mapper'),
'@' . $this->prefix('entity.creator'),
'@' . $this->prefix('entity.updater'),
'@' . $this->prefix('entity.deleter'),
]);
}
$builder->addFactoryDefinition($this->prefix('entity.creator'))
->setImplement(Crud\Create\IEntityCreator::class)
->setAutowired(FALSE)
->getResultDefinition()
->setType(Crud\Create\EntityCreator::class);

$builder->addFactoryDefinition($this->prefix('entity.updater'))
->setImplement(Crud\Update\IEntityUpdater::class)
->setAutowired(FALSE)
->getResultDefinition()
->setFactory(Crud\Update\EntityUpdater::class);

$builder->addFactoryDefinition($this->prefix('entity.deleter'))
->setImplement(Crud\Delete\IEntityDeleter::class)
->setAutowired(FALSE)
->getResultDefinition()
->setFactory(Crud\Delete\EntityDeleter::class);

// Syntax sugar for config
$builder->addFactoryDefinition($this->prefix('crud'))
->setImplement(Crud\IEntityCrudFactory::class)
->setParameters(['entityName'])
->getResultDefinition()
->setType(Crud\EntityCrud::class)
->setArguments([
new PhpGenerator\PhpLiteral('$entityName'),
'@' . $this->prefix('entity.mapper'),
'@' . $this->prefix('entity.creator'),
'@' . $this->prefix('entity.updater'),
'@' . $this->prefix('entity.deleter'),
]);
}

/**
Expand All @@ -158,8 +127,15 @@ public function beforeCompile() : void
$validator->addSetup('registerValidator', ['@' . $serviceName, $serviceName]);
}

$builder->getDefinition($builder->getByType('Doctrine\ORM\EntityManagerInterface', TRUE))
->addSetup('?->getConfiguration()->addCustomStringFunction(?, ?)', ['@self', 'DATE_FORMAT', DoctrineCrud\StringFunctions\DateFormat::class]);
$builder->getDefinition($builder->getByType(Doctrine\ORM\EntityManagerInterface::class, TRUE))
->addSetup(
'?->getConfiguration()->addCustomStringFunction(?, ?)',
[
'@self',
'DATE_FORMAT',
DoctrineCrud\StringFunctions\DateFormat::class
]
);
}

/**
Expand All @@ -168,8 +144,10 @@ public function beforeCompile() : void
*
* @return void
*/
public static function register(Nette\Configurator $config, string $extensionName = 'doctrineCrud') : void
{
public static function register(
Nette\Configurator $config,
string $extensionName = 'doctrineCrud'
) : void {
$config->onCompile[] = function (Nette\Configurator $config, DI\Compiler $compiler) use ($extensionName) : void {
$compiler->addExtension($extensionName, new DoctrineCrudExtension());
};
Expand Down
2 changes: 1 addition & 1 deletion src/IPub/DoctrineCrud/Entities/TIdentifiedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ trait TIdentifiedEntity
*/
public function getId()
{
return is_integer($this->id) ? $this->id : $this->id;
return $this->id;
}

/**
Expand Down
16 changes: 11 additions & 5 deletions src/IPub/DoctrineCrud/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

namespace IPub\DoctrineCrud;

use ReflectionException;
use ReflectionMethod;
use ReflectionParameter;

use IPub\DoctrineCrud\Exceptions;

/**
Expand All @@ -31,14 +35,16 @@ class Helpers
/**
* This method was inspired same method in Nette framework
*
* @param \ReflectionMethod $method
* @param ReflectionMethod $method
* @param array $arguments
*
* @return array
*
* @throws Exceptions\EntityCreationException
*
* @throws ReflectionException
*/
public static function autowireArguments(\ReflectionMethod $method, array $arguments) : array
public static function autowireArguments(ReflectionMethod $method, array $arguments) : array
{
$optCount = 0;
$num = -1;
Expand Down Expand Up @@ -92,14 +98,14 @@ public static function autowireArguments(\ReflectionMethod $method, array $argum
}

/**
* @param \ReflectionParameter $param
* @param ReflectionParameter $param
*
* @return string|NULL
*/
public static function getParameterType(\ReflectionParameter $param) : ?string
public static function getParameterType(ReflectionParameter $param) : ?string
{
if ($param->hasType()) {
$type = PHP_VERSION_ID >= 70100 ? $param->getType()->getName() : (string) $param->getType();
$type = $param->getType()->getName();

return strtolower($type) === 'self' ? $param->getDeclaringClass()->getName() : $type;
}
Expand Down
13 changes: 12 additions & 1 deletion src/IPub/DoctrineCrud/Mapping/EntityHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace IPub\DoctrineCrud\Mapping;

use ReflectionException;

use Doctrine\Common;
use Doctrine\ORM;

Expand Down Expand Up @@ -70,6 +72,9 @@ public function hydrate($values, Entities\IEntity $entity) : Entities\IEntity

/**
* {@inheritdoc}
*
* @throws Common\Annotations\AnnotationException
* @throws ReflectionException
*/
public function extract(Entities\IEntity $entity, int $maxLevel = 1, int $level = 1) : array
{
Expand Down Expand Up @@ -102,6 +107,9 @@ public function extract(Entities\IEntity $entity, int $maxLevel = 1, int $level

/**
* {@inheritdoc}
*
* @throws Common\Annotations\AnnotationException
* @throws ReflectionException
*/
public function simpleExtract(Entities\IEntity $entity) : array
{
Expand Down Expand Up @@ -138,6 +146,9 @@ public function simpleExtract(Entities\IEntity $entity) : array
* @param int $level
*
* @return mixed|mixed[]
*
* @throws Common\Annotations\AnnotationException
* @throws ReflectionException
*/
private function extractor($value, int $maxLevel = 1, int $level = 1)
{
Expand Down Expand Up @@ -195,7 +206,7 @@ private function simpleExtractor($value)
*
* @return Nette\Reflection\Property[]
*
* @throws \ReflectionException
* @throws ReflectionException
*/
private function getEntityProperties(Entities\IEntity $entity) : array
{
Expand Down
Loading

0 comments on commit 690fd1c

Please sign in to comment.