Skip to content

Commit efcbbae

Browse files
committed
Merge branch 'release/1.1'
2 parents 49ca0bc + 74f20d7 commit efcbbae

File tree

9 files changed

+66
-16
lines changed

9 files changed

+66
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/.idea/
2+
.phpunit.result.cache

bin/console

100644100755
File mode changed.

src/Application/Console/ConsoleCommand/DumpObjectReferenceCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ public function exec(InputInterface $input, OutputInterface $output, SymfonyStyl
3737

3838
$io->writeln('Dumping reference ...');
3939
$outFile = $input->getOption('out-file');
40+
41+
if(!$outFile) {
42+
$io->error('Please specify a value for the out file option');
43+
return self::STATUS_ERROR;
44+
}
45+
4046
file_put_contents($outFile, $ref);
47+
4148
$io->writeln("<info>Reference dumped successfully to '{$outFile}'</info>");
4249

4350
return parent::STATUS_SUCCESS;

src/Application/Shared/Constant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
class Constant
88
{
9-
public const VERSION = '1.0.0';
9+
public const VERSION = '1.1.0';
1010
}

src/Application/Shared/Service/ApplicationService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Morebec\ObjectGenerator\Application\Shared\Service;
55

66
use Morebec\ObjectGenerator\Domain\Definition\ObjectDefinition;
7+
use Morebec\ObjectGenerator\Domain\Exception\FileNotFoundException;
78
use Morebec\ObjectGenerator\Domain\ObjectDumper;
89
use Morebec\ObjectGenerator\Domain\ObjectGenerationResult;
910
use Morebec\ObjectGenerator\Domain\ObjectGenerator;
@@ -20,6 +21,7 @@ class ApplicationService
2021
* Compiles a file and returns an ObjectGenerationResult
2122
* @param string $pathToFile
2223
* @return ObjectGenerationResult
24+
* @throws FileNotFoundException
2325
*/
2426
public function compileFile(string $pathToFile): ObjectGenerationResult
2527
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* Compiler
1010
*/
11-
class Compiler
11+
class PHPObjectCompiler
1212
{
1313
/**
1414
* @var CompilerPassInterface[]

src/Domain/ObjectGenerator.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace Morebec\ObjectGenerator\Domain;
44

55

6-
use Morebec\ObjectGenerator\Domain\Compiler\Compiler;
6+
use Morebec\ObjectGenerator\Domain\Compiler\PHPObjectCompiler;
77
use Morebec\ObjectGenerator\Domain\Definition\ObjectDefinition;
88
use Morebec\ObjectGenerator\Domain\Definition\Schema\ObjectDefinitionSchema;
99
use Morebec\ObjectGenerator\Domain\Loader\DefinitionLoaderInterface;
1010
use Morebec\ObjectGenerator\Domain\ObjectReferenceDumper\ObjectReferenceDumperInterface;
11+
use Morebec\ObjectGenerator\Domain\Validation\ObjectSchemaValidator;
1112
use Morebec\ValueObjects\File\File;
1213
use Symfony\Component\Config\Definition\Processor;
1314

@@ -33,6 +34,11 @@ public function __construct(
3334
$this->dumper = $dumper;
3435
}
3536

37+
/**
38+
* @param File $file
39+
* @return ObjectGenerationResult
40+
* @throws Exception\FileNotFoundException
41+
*/
3642
public function generateFile(File $file): ObjectGenerationResult
3743
{
3844
// Load definition data schema
@@ -42,34 +48,37 @@ public function generateFile(File $file): ObjectGenerationResult
4248
$result->setInitialSchema($data);
4349
return $result;
4450
}
45-
51+
52+
/**
53+
* @param array $schema
54+
* @return ObjectGenerationResult
55+
*/
4656
public function generateFromArraySchema(array $schema): ObjectGenerationResult
4757
{
48-
$typeName = array_key_first($schema);
49-
$objectSchema = new ObjectDefinitionSchema($typeName);
58+
$objectName = array_key_first($schema);
5059

51-
// Validate schema against schema validator
52-
$processor = new Processor();
53-
$validatedArraySchema = $processor->processConfiguration(
54-
$objectSchema,
55-
$schema
56-
);
60+
$validator = new ObjectSchemaValidator();
61+
$validatedArraySchema = $validator->validate($objectName, $schema);
5762

5863
// Create definition object
5964
$definition = ObjectDefinition::createFromArray(
60-
$typeName,
65+
$objectName,
6166
$validatedArraySchema
6267
);
6368

6469
$result = $this->generateFromObjectDefinition($definition);
6570
$result->setValidatedSchema($schema);
6671
return $result;
6772
}
68-
73+
74+
/**
75+
* @param ObjectDefinition $definition
76+
* @return ObjectGenerationResult
77+
*/
6978
public function generateFromObjectDefinition(ObjectDefinition $definition): ObjectGenerationResult
7079
{
7180
// Compile Schema into class representation
72-
$compiler = new Compiler();
81+
$compiler = new PHPObjectCompiler();
7382
$object = $compiler->compile($definition);
7483

7584
// Generate code
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
4+
namespace Morebec\ObjectGenerator\Domain\Validation;
5+
6+
use Morebec\ObjectGenerator\Domain\Definition\Schema\ObjectDefinitionSchema;
7+
use Symfony\Component\Config\Definition\Processor;
8+
9+
/**
10+
* Validates the data of a loaded schema
11+
* before converting it to a schema
12+
*/
13+
class ObjectSchemaValidator
14+
{
15+
/**
16+
* Validates the array data of an Object definition loaded from file
17+
* and returns a sanitized version of it
18+
* @param array $data
19+
* @return array
20+
*/
21+
public function validate(string $objectName, array $data): array {
22+
$typeName = array_key_first($data);
23+
$objectSchema = new ObjectDefinitionSchema($objectName);
24+
25+
$processor = new Processor();
26+
return $processor->processConfiguration(
27+
$objectSchema,
28+
$data
29+
);
30+
}
31+
}

tests/ObjectGenerator/Definition/VariableTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Morebec\Devtools\ObjectGenerator\Definition;
44

5-
use Morebec\Devtools\ObjectGenerator\Domain\Definition\VariableType;
5+
use Morebec\ObjectGenerator\Domain\Definition\VariableType;
66
use PHPUnit\Framework\TestCase;
77

88
/**

0 commit comments

Comments
 (0)