Skip to content

Commit 58de562

Browse files
committed
Porting Symfony 5 compatiblity to 5.2 branch
1 parent 36c690d commit 58de562

13 files changed

+330
-151
lines changed

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@
2828
"mouf/classname-mapper": "~1.0",
2929
"doctrine/cache": "^1.6",
3030
"greenlion/php-sql-parser": "^4.3.0",
31-
"phlib/logger": "^3.0.1",
32-
"symfony/console": "^2 || ^3 || ^4",
31+
"symfony/console": "^2 || ^3 || ^4 || ^5",
3332
"mouf/utils.log.psr.multi-logger": "^1.0",
34-
"symfony/filesystem": "^2.7 || ^3 || ^4",
33+
"symfony/filesystem": "^2.7 || ^3 || ^4 || ^5",
3534
"ramsey/uuid": "^3.7",
3635
"doctrine/annotations": "^1.6",
37-
"zendframework/zend-code": "^3.3.1",
36+
"zendframework/zend-code": "^3.4",
3837
"psr/container": "^1",
3938
"ext-PDO": "*",
4039
"ext-json": "*",
@@ -47,7 +46,7 @@
4746
"php-coveralls/php-coveralls": "^2.1",
4847
"wa72/simplelogger" : "^1.0",
4948
"friendsofphp/php-cs-fixer": "^2.15.1",
50-
"symfony/process": "^3 || ^4",
49+
"symfony/process": "^3 || ^4 || ^5",
5150
"thecodingmachine/tdbm-fluid-schema-builder": "^1.0.0",
5251
"phpstan/phpstan": "^0.11.5",
5352
"thecodingmachine/phpstan-strict-rules": "^0.11.0",

src/Commands/GenerateCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6666
$tdbmService->generateAllDaosAndBeans($fromLock);
6767

6868
$multiLogger->notice('Finished regenerating DAOs and beans');
69+
70+
return 0;
6971
}
7072
}

src/TDBMService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
use TheCodingMachine\TDBM\QueryFactory\FindObjectsFromSqlQueryFactory;
4040
use TheCodingMachine\TDBM\QueryFactory\FindObjectsQueryFactory;
4141
use TheCodingMachine\TDBM\QueryFactory\FindObjectsFromRawSqlQueryFactory;
42+
use TheCodingMachine\TDBM\Utils\Logs\LevelFilter;
4243
use TheCodingMachine\TDBM\Utils\ManyToManyRelationshipPathDescriptor;
4344
use TheCodingMachine\TDBM\Utils\NamingStrategyInterface;
4445
use TheCodingMachine\TDBM\Utils\TDBMDaoGenerator;
45-
use Phlib\Logger\Decorator\LevelFilter;
4646
use Psr\Log\LoggerInterface;
4747
use Psr\Log\LogLevel;
4848
use Psr\Log\NullLogger;

src/Utils/BeanDescriptor.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,9 @@ private function generateBeanConstructor() : MethodGenerator
361361
$constructorProperties = $this->getConstructorProperties();
362362

363363
$constructor = new MethodGenerator('__construct', [], MethodGenerator::FLAG_PUBLIC);
364-
$constructor->setDocBlock('The constructor takes all compulsory arguments.');
365-
$constructor->getDocBlock()->setWordWrap(false);
364+
$constructorDocBlock = new DocBlockGenerator('The constructor takes all compulsory arguments.');
365+
$constructorDocBlock->setWordWrap(false);
366+
$constructor->setDocBlock($constructorDocBlock);
366367

367368
$assigns = [];
368369
$parentConstructorArguments = [];
@@ -374,7 +375,7 @@ private function generateBeanConstructor() : MethodGenerator
374375
}
375376
$constructor->setParameter($parameter);
376377

377-
$constructor->getDocBlock()->setTag($property->getParamAnnotation());
378+
$constructorDocBlock->setTag($property->getParamAnnotation());
378379

379380
if ($property->getTable()->getName() === $this->table->getName()) {
380381
$assigns[] = $property->getConstructorAssignCode()."\n";
@@ -487,9 +488,14 @@ public function generateJsonSerialize(): MethodGenerator
487488
$parentFk = $this->schemaAnalyzer->getParentRelationship($tableName);
488489

489490
$method = new MethodGenerator('jsonSerialize');
490-
$method->setDocBlock('Serializes the object for JSON encoding.');
491-
$method->getDocBlock()->setTag(new ParamTag('$stopRecursion', ['bool'], 'Parameter used internally by TDBM to stop embedded objects from embedding other objects.'));
492-
$method->getDocBlock()->setTag(new ReturnTag(['array']));
491+
$method->setDocBlock(new DocBlockGenerator(
492+
'Serializes the object for JSON encoding.',
493+
null,
494+
[
495+
new ParamTag('$stopRecursion', ['bool'], 'Parameter used internally by TDBM to stop embedded objects from embedding other objects.'),
496+
new ReturnTag(['array'])
497+
]
498+
));
493499
$method->setParameter(new ParameterGenerator('stopRecursion', 'bool', false));
494500

495501
if ($parentFk !== null) {
@@ -1409,8 +1415,11 @@ private function generateGetUsedTablesCode(): MethodGenerator
14091415
}
14101416

14111417
$method = new MethodGenerator('getUsedTables');
1412-
$method->setDocBlock('Returns an array of used tables by this bean (from parent to child relationship).');
1413-
$method->getDocBlock()->setTag(new ReturnTag(['string[]']));
1418+
$method->setDocBlock(new DocBlockGenerator(
1419+
'Returns an array of used tables by this bean (from parent to child relationship).',
1420+
null,
1421+
[new ReturnTag(['string[]'])]
1422+
));
14141423
$method->setReturnType('array');
14151424
$method->setBody($code);
14161425

@@ -1433,7 +1442,7 @@ private function generateOnDeleteCode(): ?MethodGenerator
14331442
}
14341443

14351444
$method = new MethodGenerator('onDelete');
1436-
$method->setDocBlock('Method called when the bean is removed from database.');
1445+
$method->setDocBlock(new DocBlockGenerator('Method called when the bean is removed from database.'));
14371446
$method->setReturnType('void');
14381447
$method->setBody('parent::onDelete();
14391448
'.$code);
@@ -1453,8 +1462,11 @@ private function generateGetManyToManyRelationshipDescriptorCode(array $pivotTab
14531462

14541463
$method = new MethodGenerator('_getManyToManyRelationshipDescriptor');
14551464
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
1456-
$method->setDocBlock('Get the paths used for many to many relationships methods.');
1457-
$method->getDocBlock()->setTag(new GenericTag('internal'));
1465+
$method->setDocBlock(new DocBlockGenerator(
1466+
'Get the paths used for many to many relationships methods.',
1467+
null,
1468+
[new GenericTag('internal')]
1469+
));
14581470
$method->setReturnType(ManyToManyRelationshipPathDescriptor::class);
14591471

14601472
$parameter = new ParameterGenerator('pathKey');
@@ -1488,9 +1500,11 @@ private function generateGetManyToManyRelationshipDescriptorKeysCode(array $pivo
14881500
$method = new MethodGenerator('_getManyToManyRelationshipDescriptorKeys');
14891501
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
14901502
$method->setReturnType('array');
1491-
$method->setDocBlock('Returns the list of keys supported for many to many relationships');
1492-
$method->getDocBlock()->setTag(new GenericTag('internal'));
1493-
$method->getDocBlock()->setTag(new ReturnTag('string[]'));
1503+
$method->setDocBlock(new DocBlockGenerator(
1504+
'Returns the list of keys supported for many to many relationships',
1505+
null,
1506+
[new GenericTag('internal'), new ReturnTag('string[]')]
1507+
));
14941508

14951509
$keys = [];
14961510
foreach ($pivotTableMethodsDescriptors as $pivotTableMethodsDescriptor) {
@@ -1659,12 +1673,12 @@ private function generateGetForeignKeys(array $fks): MethodGenerator
16591673
}
16601674
return parent::getForeignKeys(\$tableName);
16611675
EOF;
1662-
$code = sprintf($code, var_export($this->getTable()->getName(), true), $this->psr2VarExport($fkArray, ' '));
1676+
$code = sprintf($code, var_export($this->getTable()->getName(), true), $this->psr2VarExport($fkArray, ' '));
16631677

16641678
$method = new MethodGenerator('getForeignKeys');
16651679
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PROTECTED);
16661680
$method->setStatic(true);
1667-
$method->setDocBlock('Internal method used to retrieve the list of foreign keys attached to this bean.');
1681+
$method->setDocBlock(new DocBlockGenerator('Internal method used to retrieve the list of foreign keys attached to this bean.'));
16681682
$method->setReturnType(ForeignKeys::class);
16691683

16701684
$parameter = new ParameterGenerator('tableName');

src/Utils/DirectForeignKeyMethodDescriptor.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use TheCodingMachine\TDBM\Utils\Annotation;
1414
use Zend\Code\Generator\AbstractMemberGenerator;
1515
use Zend\Code\Generator\DocBlock\Tag\ReturnTag;
16+
use Zend\Code\Generator\DocBlockGenerator;
1617
use Zend\Code\Generator\MethodGenerator;
1718

1819
/**
@@ -127,9 +128,11 @@ public function getCode() : array
127128
$getter = new MethodGenerator($this->getName());
128129

129130
if ($this->hasLocalUniqueIndex()) {
130-
$getter->setDocBlock(sprintf('Returns the %s pointing to this bean via the %s column.', $beanClass, implode(', ', $this->foreignKey->getUnquotedLocalColumns())));
131131
$classType = '\\' . $this->beanNamespace . '\\' . $beanClass;
132-
$getter->getDocBlock()->setTag(new ReturnTag([$classType . '|null']))->setWordWrap(false);
132+
$getterDocBlock = new DocBlockGenerator(sprintf('Returns the %s pointing to this bean via the %s column.', $beanClass, implode(', ', $this->foreignKey->getUnquotedLocalColumns())));
133+
$getterDocBlock->setTag([new ReturnTag([$classType . '|null'])]);
134+
$getterDocBlock->setWordWrap(false);
135+
$getter->setDocBlock($getterDocBlock);
133136
$getter->setReturnType('?' . $classType);
134137

135138
$code = sprintf(
@@ -139,11 +142,10 @@ public function getCode() : array
139142
$this->getFilters($this->foreignKey)
140143
);
141144
} else {
142-
$getter->setDocBlock(sprintf('Returns the list of %s pointing to this bean via the %s column.', $beanClass, implode(', ', $this->foreignKey->getUnquotedLocalColumns())));
143-
$getter->getDocBlock()->setTag(new ReturnTag([
144-
$beanClass . '[]',
145-
'\\' . AlterableResultIterator::class
146-
]))->setWordWrap(false);
145+
$getterDocBlock = new DocBlockGenerator(sprintf('Returns the list of %s pointing to this bean via the %s column.', $beanClass, implode(', ', $this->foreignKey->getUnquotedLocalColumns())));
146+
$getterDocBlock->setTag(new ReturnTag([$beanClass . '[]', '\\' . AlterableResultIterator::class]));
147+
$getterDocBlock->setWordWrap(false);
148+
$getter->setDocBlock($getterDocBlock);
147149
$getter->setReturnType(AlterableResultIterator::class);
148150

149151
$code = sprintf(

src/Utils/Logs/LevelFilter.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\TDBM\Utils\Logs;
5+
6+
use Psr\Log\AbstractLogger;
7+
use Psr\Log\InvalidArgumentException;
8+
use Psr\Log\LoggerInterface;
9+
use Psr\Log\LogLevel;
10+
use function array_search;
11+
use function sprintf;
12+
13+
class LevelFilter extends AbstractLogger
14+
{
15+
/**
16+
* Logging levels from syslog protocol defined in RFC 5424
17+
*
18+
* @var string[] $levels Logging levels
19+
*/
20+
private static $levels = array(
21+
LogLevel::EMERGENCY, // 0
22+
LogLevel::ALERT, // 1
23+
LogLevel::CRITICAL, // 2
24+
LogLevel::ERROR, // 3
25+
LogLevel::WARNING, // 4
26+
LogLevel::NOTICE, // 5
27+
LogLevel::INFO, // 6
28+
LogLevel::DEBUG // 7
29+
);
30+
31+
/**
32+
* @var int
33+
*/
34+
private $logLevel;
35+
/**
36+
* @var LoggerInterface
37+
*/
38+
private $logger;
39+
40+
/**
41+
* @param LoggerInterface $logger
42+
* @param string $level \Psr\Log\LogLevel string
43+
*/
44+
public function __construct(LoggerInterface $logger, $level)
45+
{
46+
$this->logger = $logger;
47+
48+
$this->logLevel = array_search($level, self::$levels, true);
49+
if ($this->logLevel === false) {
50+
throw new InvalidArgumentException(
51+
sprintf(
52+
'Cannot use logging level "%s"',
53+
$level
54+
)
55+
);
56+
}
57+
}
58+
59+
/**
60+
* Logs with an arbitrary level.
61+
*
62+
* @param mixed $level
63+
* @param string $message
64+
* @param array $context
65+
*
66+
* @return void
67+
*/
68+
public function log($level, $message, array $context = array())
69+
{
70+
$levelCode = array_search($level, self::$levels, true);
71+
if ($levelCode === false) {
72+
throw new InvalidArgumentException(
73+
sprintf(
74+
'Cannot use unknown logging level "%s"',
75+
$level
76+
)
77+
);
78+
}
79+
if ($levelCode > $this->logLevel) {
80+
return;
81+
}
82+
83+
$this->logger->log($level, $message, $context);
84+
}
85+
}

src/Utils/ObjectBeanPropertyDescriptor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use TheCodingMachine\TDBM\Utils\Annotation\AnnotationParser;
1111
use TheCodingMachine\TDBM\Utils\Annotation;
1212
use Zend\Code\Generator\AbstractMemberGenerator;
13+
use Zend\Code\Generator\DocBlockGenerator;
1314
use Zend\Code\Generator\MethodGenerator;
1415
use Zend\Code\Generator\ParameterGenerator;
1516

@@ -159,7 +160,7 @@ public function getGetterSetterCode(): array
159160
$referencedBeanName = $this->namingStrategy->getBeanClassName($this->foreignKey->getForeignTableName());
160161

161162
$getter = new MethodGenerator($getterName);
162-
$getter->setDocBlock('Returns the ' . $referencedBeanName . ' object bound to this object via the ' . implode(' and ', $this->foreignKey->getUnquotedLocalColumns()) . ' column.');
163+
$getter->setDocBlock(new DocBlockGenerator('Returns the ' . $referencedBeanName . ' object bound to this object via the ' . implode(' and ', $this->foreignKey->getUnquotedLocalColumns()) . ' column.'));
163164

164165
/*$types = [ $referencedBeanName ];
165166
if ($isNullable) {
@@ -177,7 +178,7 @@ public function getGetterSetterCode(): array
177178
}
178179

179180
$setter = new MethodGenerator($setterName);
180-
$setter->setDocBlock('The setter for the ' . $referencedBeanName . ' object bound to this object via the ' . implode(' and ', $this->foreignKey->getUnquotedLocalColumns()) . ' column.');
181+
$setter->setDocBlock(new DocBlockGenerator('The setter for the ' . $referencedBeanName . ' object bound to this object via the ' . implode(' and ', $this->foreignKey->getUnquotedLocalColumns()) . ' column.'));
181182

182183
$setter->setParameter(new ParameterGenerator('object', ($isNullable ? '?' : '') . $this->beanNamespace . '\\' . $referencedBeanName));
183184

src/Utils/PivotTableMethodsDescriptor.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\DBAL\Schema\Column;
88
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
99
use Doctrine\DBAL\Schema\Table;
10+
use Zend\Code\Generator\DocBlockGenerator;
1011
use function implode;
1112
use function sprintf;
1213
use TheCodingMachine\TDBM\Utils\Annotation\AnnotationParser;
@@ -199,39 +200,49 @@ public function getCode() : array
199200
$localTableName = var_export($this->remoteFk->getLocalTableName(), true);
200201

201202
$getter = new MethodGenerator($this->getName());
202-
$getter->setDocBlock(sprintf('Returns the list of %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
203-
$getter->getDocBlock()->setTag(new ReturnTag([ $fqcnRemoteBeanName.'[]' ]))->setWordWrap(false);
203+
$getterDocBlock = new DocBlockGenerator(sprintf('Returns the list of %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
204+
$getterDocBlock->setTag(new ReturnTag([ $fqcnRemoteBeanName.'[]' ]));
205+
$getterDocBlock->setWordWrap(false);
206+
$getter->setDocBlock($getterDocBlock);
204207
$getter->setReturnType('array');
205208
$getter->setBody(sprintf('return $this->_getRelationships(%s);', $pathKey));
206209

207210

208211
$adder = new MethodGenerator('add'.$singularName);
209-
$adder->setDocBlock(sprintf('Adds a relationship with %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
210-
$adder->getDocBlock()->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]))->setWordWrap(false);
212+
$adderDocBlock = new DocBlockGenerator(sprintf('Adds a relationship with %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
213+
$adderDocBlock->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]));
214+
$adderDocBlock->setWordWrap(false);
215+
$adder->setDocBlock($adderDocBlock);
211216
$adder->setReturnType('void');
212217
$adder->setParameter(new ParameterGenerator($variableName, $fqcnRemoteBeanName));
213218
$adder->setBody(sprintf('$this->addRelationship(%s, $%s);', $localTableName, $variableName));
214219

215220
$remover = new MethodGenerator('remove'.$singularName);
216-
$remover->setDocBlock(sprintf('Deletes the relationship with %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
217-
$remover->getDocBlock()->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]))->setWordWrap(false);
221+
$removerDocBlock = new DocBlockGenerator(sprintf('Deletes the relationship with %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
222+
$removerDocBlock->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]));
223+
$removerDocBlock->setWordWrap(false);
224+
$remover->setDocBlock($removerDocBlock);
218225
$remover->setReturnType('void');
219226
$remover->setParameter(new ParameterGenerator($variableName, $fqcnRemoteBeanName));
220227
$remover->setBody(sprintf('$this->_removeRelationship(%s, $%s);', $localTableName, $variableName));
221228

222229
$has = new MethodGenerator('has'.$singularName);
223-
$has->setDocBlock(sprintf('Returns whether this bean is associated with %s via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
224-
$has->getDocBlock()->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]))->setWordWrap(false);
225-
$has->getDocBlock()->setTag(new ReturnTag([ 'bool' ]));
230+
$hasDocBlock = new DocBlockGenerator(sprintf('Returns whether this bean is associated with %s via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
231+
$hasDocBlock->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]));
232+
$hasDocBlock->setTag(new ReturnTag([ 'bool' ]));
233+
$hasDocBlock->setWordWrap(false);
234+
$has->setDocBlock($hasDocBlock);
226235
$has->setReturnType('bool');
227236
$has->setParameter(new ParameterGenerator($variableName, $fqcnRemoteBeanName));
228237
$has->setBody(sprintf('return $this->hasRelationship(%s, $%s);', $pathKey, $variableName));
229238

230239
$setter = new MethodGenerator('set'.$pluralName);
231-
$setter->setDocBlock(sprintf('Sets all relationships with %s associated to this bean via the %s pivot table.
240+
$setterDocBlock = new DocBlockGenerator(sprintf('Sets all relationships with %s associated to this bean via the %s pivot table.
232241
Exiting relationships will be removed and replaced by the provided relationships.', $remoteBeanName, $this->pivotTable->getName()));
233-
$setter->getDocBlock()->setTag(new ParamTag($pluralVariableName, [ $fqcnRemoteBeanName.'[]' ]))->setWordWrap(false)->setWordWrap(false);
234-
$setter->getDocBlock()->setTag(new ReturnTag([ 'void' ]));
242+
$setterDocBlock->setTag(new ParamTag($pluralVariableName, [ $fqcnRemoteBeanName.'[]' ]));
243+
$setterDocBlock->setTag(new ReturnTag([ 'void' ]));
244+
$setterDocBlock->setWordWrap(false);
245+
$setter->setDocBlock($setterDocBlock);
235246
$setter->setReturnType('void');
236247
$setter->setParameter(new ParameterGenerator($pluralVariableName, 'array'));
237248
$setter->setBody(sprintf('$this->setRelationships(%s, $%s);', $pathKey, $pluralVariableName));

0 commit comments

Comments
 (0)