Skip to content

Commit 681437c

Browse files
committed
Update entites definitions
1 parent f6b7fc4 commit 681437c

24 files changed

+314
-235
lines changed

generator/AbstractGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function run(\SplFileInfo $dir, string $namespace = ''): void
4343
try {
4444
$this->generate($dir, $unifiedNamespace);
4545
} catch (\Throwable $e) {
46-
$message = 'Error while class generation.';
46+
$message = 'Error while class generation';
4747
throw new \RuntimeException($message, 0, $e);
4848
}
4949
}
@@ -70,7 +70,7 @@ protected function checkDir(\SplFileInfo $dir): void
7070
{
7171
if (!$dir->isDir() || !$dir->isWritable()) {
7272
throw new \InvalidArgumentException(
73-
"Destination folder '" . $dir->getPathname() . "' isn't writable or doesn't exist."
73+
"Destination folder '" . $dir->getPathname() . "' isn't writable or doesn't exist"
7474
);
7575
}
7676
}

generator/MigrationGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function generateClassByDescriptor(EntityDescriptor $descriptor, \SplF
4141
$phpFile->addUse(Connection::class);
4242
}
4343

44-
$class = $phpFile->addClass($className)->addExtend(Migration::class);
44+
$class = $phpFile->addClass($className)->setExtends(Migration::class);
4545
$class->addComment("Миграция для создания сущности '{$descriptor->getName()}'.");
4646
$this->decorateClassWithUpMethodByDescription($class, $descriptor);
4747
$this->decorateClassWithDownMethodByDescription($class, $descriptor);

generator/ModelGenerator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Liquetsoft\Fias\Component\EntityDescriptor\EntityDescriptor;
99
use Liquetsoft\Fias\Component\EntityField\EntityField;
1010
use Nette\PhpGenerator\ClassType;
11+
use Nette\PhpGenerator\Literal;
1112
use Nette\PhpGenerator\PhpFile;
12-
use Nette\PhpGenerator\PhpLiteral;
1313
use Nette\PhpGenerator\PhpNamespace;
1414
use Nette\PhpGenerator\PsrPrinter;
1515

@@ -32,7 +32,7 @@ protected function generateClassByDescriptor(EntityDescriptor $descriptor, \SplF
3232
$namespace = $phpFile->addNamespace($namespace);
3333
$this->decorateNamespace($namespace, $descriptor);
3434

35-
$class = $namespace->addClass($name)->addExtend(Model::class);
35+
$class = $namespace->addClass($name)->setExtends(Model::class);
3636
$this->decorateClass($class, $descriptor);
3737

3838
file_put_contents($fullPath, (new PsrPrinter())->printFile($phpFile));
@@ -75,12 +75,12 @@ protected function decorateClass(ClassType $class, EntityDescriptor $descriptor)
7575
}
7676
}
7777

78-
$class->addProperty('timestamps', new PhpLiteral('false'))
78+
$class->addProperty('timestamps', new Literal('false'))
7979
->setVisibility('public')
8080
->addComment('@var bool')
8181
;
8282

83-
$class->addProperty('incrementing', new PhpLiteral('false'))
83+
$class->addProperty('incrementing', new Literal('false'))
8484
->setVisibility('public')
8585
->addComment('@var bool')
8686
;
@@ -103,13 +103,13 @@ protected function decorateClass(ClassType $class, EntityDescriptor $descriptor)
103103
;
104104
}
105105

106-
$fillableValue = new PhpLiteral("[\n '" . implode("',\n '", $fill) . "',\n]");
106+
$fillableValue = new Literal("[\n '" . implode("',\n '", $fill) . "',\n]");
107107
$class->addProperty('fillable', $fillableValue)
108108
->setVisibility('protected')
109109
->addComment('@var string[]')
110110
;
111111

112-
$castValue = new PhpLiteral($this->createCastValue($descriptor));
112+
$castValue = new Literal($this->createCastValue($descriptor));
113113
$class->addProperty('casts', $castValue)
114114
->setVisibility('protected')
115115
->addComment('@var array')

generator/ModelTestGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function generateClassByDescriptor(EntityDescriptor $descriptor, \SplF
3030
$namespace = $phpFile->addNamespace($namespace);
3131
$this->decorateNamespace($namespace, $descriptor);
3232

33-
$class = $namespace->addClass($name)->addExtend(BaseCase::class);
33+
$class = $namespace->addClass($name)->setExtends(BaseCase::class);
3434
$this->decorateClass($class, $descriptor);
3535

3636
file_put_contents($fullPath, (new PsrPrinter())->printFile($phpFile));

generator/ResourceGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function generateClassByDescriptor(EntityDescriptor $descriptor, \SplF
3232
$namespace = $phpFile->addNamespace($namespace);
3333
$this->decorateNamespace($namespace, $descriptor);
3434

35-
$class = $namespace->addClass($name)->addExtend(JsonResource::class);
35+
$class = $namespace->addClass($name)->setExtends(JsonResource::class);
3636
$this->decorateClass($class, $descriptor);
3737

3838
file_put_contents($fullPath, (new PsrPrinter())->printFile($phpFile));

generator/ResourceTestGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function generateClassByDescriptor(EntityDescriptor $descriptor, \SplF
3131
$namespace = $phpFile->addNamespace($namespace);
3232
$this->decorateNamespace($namespace, $descriptor);
3333

34-
$class = $namespace->addClass($name)->addExtend(BaseCase::class);
34+
$class = $namespace->addClass($name)->setExtends(BaseCase::class);
3535
$this->decorateClass($class, $descriptor);
3636

3737
file_put_contents($fullPath, (new PsrPrinter())->printFile($phpFile));

generator/SerializerGenerator.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use Illuminate\Database\Eloquent\Model;
88
use Liquetsoft\Fias\Component\EntityDescriptor\EntityDescriptor;
99
use Nette\PhpGenerator\ClassType;
10+
use Nette\PhpGenerator\Literal;
1011
use Nette\PhpGenerator\Method;
1112
use Nette\PhpGenerator\PhpFile;
12-
use Nette\PhpGenerator\PhpLiteral;
1313
use Nette\PhpGenerator\PhpNamespace;
1414
use Nette\PhpGenerator\PsrPrinter;
1515
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
@@ -69,6 +69,7 @@ protected function decorateNamespace(PhpNamespace $namespace): void
6969
protected function decorateClass(ClassType $class): void
7070
{
7171
$constants = [];
72+
$supportedTypes = '';
7273

7374
$denormalizeBody = '$data = \\is_array($data) ? $data : [];' . "\n";
7475
$denormalizeBody .= '$type = trim($type, " \t\n\r\0\x0B\\\\/");' . "\n\n";
@@ -82,7 +83,8 @@ protected function decorateClass(ClassType $class): void
8283
$descriptors = $this->registry->getDescriptors();
8384
foreach ($descriptors as $descriptor) {
8485
$className = $this->unifyClassName($descriptor->getName());
85-
$constants[] = new PhpLiteral("{$className}::class");
86+
$constants[] = new Literal("{$className}::class");
87+
$supportedTypes .= "\n {$className}::class => true,";
8688
$denormalizeBody .= " case {$className}::class:\n";
8789
$denormalizeBody .= " \$extractedData = \$this->model{$className}DataExtractor(\$data);\n";
8890
$denormalizeBody .= " break;\n";
@@ -106,7 +108,7 @@ protected function decorateClass(ClassType $class): void
106108
->setBody('return \\in_array(trim($type, " \t\n\r\0\x0B\\\\/"), self::ALLOWED_ENTITIES);');
107109
$supports->addParameter('data');
108110
$supports->addParameter('type')->setType('string');
109-
$supports->addParameter('format', new PhpLiteral('null'))->setType('string');
111+
$supports->addParameter('format', new Literal('null'))->setType('string');
110112

111113
$denormalize = $class->addMethod('denormalize')
112114
->addComment("{@inheritDoc}\n")
@@ -115,8 +117,14 @@ protected function decorateClass(ClassType $class): void
115117
->setBody($denormalizeBody);
116118
$denormalize->addParameter('data');
117119
$denormalize->addParameter('type')->setType('string');
118-
$denormalize->addParameter('format', new PhpLiteral('null'))->setType('string');
119-
$denormalize->addParameter('context', new PhpLiteral('[]'))->setType('array');
120+
$denormalize->addParameter('format', new Literal('null'))->setType('string');
121+
$denormalize->addParameter('context', new Literal('[]'))->setType('array');
122+
123+
$getSupportedTypes = $class->addMethod('getSupportedTypes')
124+
->addComment("{@inheritDoc}\n")
125+
->setVisibility('public')
126+
->setBody("return [\n{$supportedTypes}\n];");
127+
$getSupportedTypes->addParameter('format')->setType('string')->setNullable(true);
120128

121129
foreach ($descriptors as $descriptor) {
122130
$className = $this->unifyClassName($descriptor->getName());

generator/generate_entities.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@
3535
'isPrimary' => true,
3636
]),
3737
new BaseEntityField([
38-
'name' => 'url',
38+
'name' => 'fullUrl',
3939
'type' => 'string',
40-
'description' => 'Ссылка для загрузки указанной версии ФИАС',
40+
'description' => 'Ссылка для загрузки полной версии ФИАС',
41+
'isNullable' => false,
42+
]),
43+
new BaseEntityField([
44+
'name' => 'deltaUrl',
45+
'type' => 'string',
46+
'description' => 'Ссылка для загрузки обновления до версии ФИАС',
4147
'isNullable' => false,
4248
]),
4349
new BaseEntityField([

src/Entity/AdmHierarchy.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* @property \DateTimeInterface $startdate Начало действия записи
2626
* @property \DateTimeInterface $enddate Окончание действия записи
2727
* @property int $isactive Признак действующего адресного объекта
28+
* @property string $path Материализованный путь к объекту (полная иерархия)
2829
*/
2930
class AdmHierarchy extends Model
3031
{
@@ -58,6 +59,7 @@ class AdmHierarchy extends Model
5859
'startdate',
5960
'enddate',
6061
'isactive',
62+
'path',
6163
];
6264

6365
/** @var array */
@@ -78,6 +80,7 @@ class AdmHierarchy extends Model
7880
'startdate' => 'datetime',
7981
'enddate' => 'datetime',
8082
'isactive' => 'integer',
83+
'path' => 'string',
8184
];
8285

8386
/**

src/Entity/FiasVersion.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
* Модель, которая хранит историю версий ФИАС.
1111
*
1212
* @property int $version Номер версии ФИАС
13-
* @property string $url Ссылка для загрузки указанной версии ФИАС
13+
* @property string $fullurl Ссылка для загрузки полной версии ФИАС
14+
* @property string $deltaurl Ссылка для загрузки обновления до версии ФИАС
1415
* @property \DateTimeInterface $created_at Дата создания записи
1516
*/
1617
class FiasVersion extends Model
@@ -30,14 +31,16 @@ class FiasVersion extends Model
3031
/** @var string[] */
3132
protected $fillable = [
3233
'version',
33-
'url',
34+
'fullurl',
35+
'deltaurl',
3436
'created_at',
3537
];
3638

3739
/** @var array */
3840
protected $casts = [
3941
'version' => 'integer',
40-
'url' => 'string',
42+
'fullurl' => 'string',
43+
'deltaurl' => 'string',
4144
'created_at' => 'datetime',
4245
];
4346

src/Entity/MunHierarchy.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @property \DateTimeInterface $startdate Начало действия записи
2121
* @property \DateTimeInterface $enddate Окончание действия записи
2222
* @property int $isactive Признак действующего адресного объекта
23+
* @property string $path Материализованный путь к объекту (полная иерархия)
2324
*/
2425
class MunHierarchy extends Model
2526
{
@@ -48,6 +49,7 @@ class MunHierarchy extends Model
4849
'startdate',
4950
'enddate',
5051
'isactive',
52+
'path',
5153
];
5254

5355
/** @var array */
@@ -63,6 +65,7 @@ class MunHierarchy extends Model
6365
'startdate' => 'datetime',
6466
'enddate' => 'datetime',
6567
'isactive' => 'integer',
68+
'path' => 'string',
6669
];
6770

6871
/**

src/Migration/2019_09_03_144400_fias_laravel_adm_hierarchy.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function up(): void
3838
$table->datetime('startdate')->nullable(false)->comment('Начало действия записи');
3939
$table->datetime('enddate')->nullable(false)->comment('Окончание действия записи');
4040
$table->unsignedInteger('isactive')->nullable(false)->comment('Признак действующего адресного объекта');
41+
$table->string('path', 255)->nullable(false)->comment('Материализованный путь к объекту (полная иерархия)');
4142
// настройки таблицы
4243
$table->engine = 'InnoDB';
4344
$table->charset = 'utf8';

src/Migration/2019_09_03_144400_fias_laravel_fias_version.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public function up(): void
2323
Schema::connection($connectionName)->create('fias_laravel_fias_version', function (Blueprint $table): void {
2424
// создание полей таблицы
2525
$table->unsignedInteger('version')->nullable(false)->comment('Номер версии ФИАС')->primary();
26-
$table->string('url', 255)->nullable(false)->comment('Ссылка для загрузки указанной версии ФИАС');
26+
$table->string('fullurl', 255)->nullable(false)->comment('Ссылка для загрузки полной версии ФИАС');
27+
$table->string('deltaurl', 255)->nullable(false)->comment('Ссылка для загрузки обновления до версии ФИАС');
2728
$table->datetime('created_at')->nullable(false)->comment('Дата создания записи');
2829
// настройки таблицы
2930
$table->engine = 'InnoDB';

src/Migration/2019_09_03_144400_fias_laravel_mun_hierarchy.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function up(): void
3333
$table->datetime('startdate')->nullable(false)->comment('Начало действия записи');
3434
$table->datetime('enddate')->nullable(false)->comment('Окончание действия записи');
3535
$table->unsignedInteger('isactive')->nullable(false)->comment('Признак действующего адресного объекта');
36+
$table->string('path', 255)->nullable(false)->comment('Материализованный путь к объекту (полная иерархия)');
3637
// настройки таблицы
3738
$table->engine = 'InnoDB';
3839
$table->charset = 'utf8';

src/Resource/AdmHierarchy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* @property \DateTimeInterface $startdate
2727
* @property \DateTimeInterface $enddate
2828
* @property int $isactive
29+
* @property string $path
2930
*/
3031
class AdmHierarchy extends JsonResource
3132
{
@@ -53,6 +54,7 @@ public function toArray($request): array
5354
'startdate' => $this->startdate->format(\DateTimeInterface::ATOM),
5455
'enddate' => $this->enddate->format(\DateTimeInterface::ATOM),
5556
'isactive' => $this->isactive,
57+
'path' => $this->path,
5658
];
5759
}
5860
}

src/Resource/FiasVersion.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
* Ресурс для сущности 'FiasVersion'.
1212
*
1313
* @property int $version
14-
* @property string $url
14+
* @property string $fullurl
15+
* @property string $deltaurl
1516
* @property \DateTimeInterface $created_at
1617
*/
1718
class FiasVersion extends JsonResource
@@ -25,7 +26,8 @@ public function toArray($request): array
2526
{
2627
return [
2728
'version' => $this->version,
28-
'url' => $this->url,
29+
'fullurl' => $this->fullurl,
30+
'deltaurl' => $this->deltaurl,
2931
'created_at' => $this->created_at->format(\DateTimeInterface::ATOM),
3032
];
3133
}

src/Resource/MunHierarchy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @property \DateTimeInterface $startdate
2222
* @property \DateTimeInterface $enddate
2323
* @property int $isactive
24+
* @property string $path
2425
*/
2526
class MunHierarchy extends JsonResource
2627
{
@@ -43,6 +44,7 @@ public function toArray($request): array
4344
'startdate' => $this->startdate->format(\DateTimeInterface::ATOM),
4445
'enddate' => $this->enddate->format(\DateTimeInterface::ATOM),
4546
'isactive' => $this->isactive,
47+
'path' => $this->path,
4648
];
4749
}
4850
}

0 commit comments

Comments
 (0)