Passed
Push — master ( 8e9e8c...5c7da6 )
by Fran
03:59
created

GeneratorService::generateConfigTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace PSFS\services;
3
4
use Propel\Generator\Config\GeneratorConfig;
5
use Propel\Generator\Manager\AbstractManager;
6
use Propel\Generator\Manager\ModelManager;
7
use Propel\Generator\Manager\SqlManager;
8
use PSFS\base\Cache;
9
use PSFS\base\config\Config;
10
use PSFS\base\exception\ConfigException;
11
use PSFS\base\Logger;
12
use PSFS\base\Service;
13
use PSFS\base\types\helpers\GeneratorHelper;
14
use Symfony\Component\Filesystem\Filesystem;
15
16
class GeneratorService extends Service
17
{
18
    /**
19
     * @Injectable
20
     * @var \PSFS\base\config\Config Servicio de configuración
21
     */
22
    protected $config;
23
    /**
24
     * @Injectable
25
     * @var \PSFS\base\Security Servicio de autenticación
26
     */
27
    protected $security;
28
    /**
29
     * @Injectable
30
     * @var \PSFS\base\Template Servicio de gestión de plantillas
31
     */
32
    protected $tpl;
33
34
    /**
35
     * Método que revisa las traducciones directorio a directorio
36
     * @param $path
37
     * @param $locale
38
     * @return array
39
     */
40
    public static function findTranslations($path, $locale)
41
    {
42
        $localePath = realpath(BASE_DIR . DIRECTORY_SEPARATOR . 'locale');
43
        $localePath .= DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR;
44
45
        $translations = array();
46
        if (file_exists($path)) {
47
            $d = dir($path);
48
            while (false !== ($dir = $d->read())) {
49
                GeneratorHelper::createDir($localePath);
50
                if (!file_exists($localePath . 'translations.po')) {
51
                    file_put_contents($localePath . 'translations.po', '');
52
                }
53
                $inspect_path = realpath($path . DIRECTORY_SEPARATOR . $dir);
54
                $cmd_php = "export PATH=\$PATH:/opt/local/bin; xgettext " .
55
                    $inspect_path . DIRECTORY_SEPARATOR .
56
                    "*.php --from-code=UTF-8 -j -L PHP --debug --force-po -o {$localePath}translations.po";
57
                if (is_dir($path . DIRECTORY_SEPARATOR . $dir) && preg_match('/^\./', $dir) == 0) {
58
                    $res = t('Revisando directorio: ') . $inspect_path;
59
                    $res .= t('Comando ejecutado: ') . $cmd_php;
60
                    $res .= shell_exec($cmd_php);
61
                    usleep(10);
62
                    $translations[] = $res;
63
                    $translations = array_merge($translations, self::findTranslations($inspect_path, $locale));
64
                }
65
            }
66
        }
67
        return $translations;
68
    }
69
70
    /**
71
     * Servicio que genera la estructura de un módulo o lo actualiza en caso de ser necesario
72
     * @param string $module
73
     * @param boolean $force
74
     * @param string $type
75
     * @param string $apiClass
76
     * @return mixed
77
     */
78
    public function createStructureModule($module, $force = false, $type = "", $apiClass = "")
79
    {
80
        $mod_path = CORE_DIR . DIRECTORY_SEPARATOR;
81
        $module = ucfirst($module);
82
        $this->createModulePath($module, $mod_path);
83
        $this->createModulePathTree($module, $mod_path);
0 ignored issues
show
Bug introduced by
$mod_path of type string is incompatible with the type boolean expected by parameter $mod_path of PSFS\services\GeneratorS...:createModulePathTree(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

83
        $this->createModulePathTree($module, /** @scrutinizer ignore-type */ $mod_path);
Loading history...
84
        $this->createModuleBaseFiles($module, $mod_path, $force, $type);
85
        $this->createModuleModels($module, $mod_path);
86
        $this->generateBaseApiTemplate($module, $mod_path, $force, $apiClass);
87
        //Redireccionamos al home definido
88
        $this->log->addLog("Módulo generado correctamente");
89
    }
90
91
    /**
92
     * Service that creates the root paths for the modules
93
     * @param string $module
94
     * @param string $mod_path
95
     */
96
    private function createModulePath($module, $mod_path)
97
    {
98
        // Creates the src folder
99
        GeneratorHelper::createDir($mod_path);
100
        // Create module path
101
        GeneratorHelper::createDir($mod_path . $module);
102
    }
103
104
    /**
105
     * Servicio que genera la estructura base
106
     * @param string $module
107
     * @param boolean $mod_path
108
     * @return boolean
109
     */
110
    private function createModulePathTree($module, $mod_path)
111
    {
112
        //Creamos las carpetas CORE del módulo
113
        $this->log->addLog("Generamos la estructura");
114
        $paths = [
115
            "Api", "Api/base", "Config", "Controller", "Models", "Public", "Templates", "Services", "Test", "Doc",
116
            "Locale", "Locale/" . Config::getParam('default.locale', 'es_ES'), "Locale/" . Config::getParam('default.locale', 'es_ES') . "/LC_MESSAGES"
117
        ];
118
        $module_path = $mod_path . $module;
119
        foreach ($paths as $path) {
120
            GeneratorHelper::createDir($module_path . DIRECTORY_SEPARATOR . $path);
121
        }
122
        //Creamos las carpetas de los assets
123
        $htmlPaths = array("css", "js", "img", "media", "font");
124
        foreach ($htmlPaths as $path) {
125
            GeneratorHelper::createDir($module_path . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . $path);
126
        }
127
    }
128
129
    /**
130
     * Servicio que genera las plantillas básicas de ficheros del módulo
131
     * @param string $module
132
     * @param string $mod_path
133
     * @param boolean $force
134
     * @param string $controllerType
135
     */
136
    private function createModuleBaseFiles($module, $mod_path, $force = false, $controllerType = '')
137
    {
138
        $module_path = $mod_path . $module;
139
        $this->generateControllerTemplate($module, $module_path, $force, $controllerType);
140
        $this->generateServiceTemplate($module, $module_path, $force);
141
        $this->genereateAutoloaderTemplate($module, $module_path, $force);
142
        $this->generateSchemaTemplate($module, $module_path, $force);
143
        $this->generatePropertiesTemplate($module, $module_path, $force);
144
        $this->generateConfigTemplate($module_path, $force);
145
        $this->generateIndexTemplate($module, $module_path, $force);
146
        $this->generatePublicTemplates($module_path, $force);
147
    }
148
149
    /**
150
     * Servicio que ejecuta Propel y genera el modelo de datos
151
     * @param string $module
152
     * @param string $path
153
     */
154
    private function createModuleModels($module, $path)
155
    {
156
        $module_path = $path . $module;
157
        $module_path = str_replace(CORE_DIR . DIRECTORY_SEPARATOR, '', $module_path);
158
159
        $configGenerator = $this->getConfigGenerator($module_path);
160
161
        $this->buildModels($configGenerator);
162
        $this->buildSql($configGenerator);
163
164
        $configTemplate = $this->tpl->dump("generator/config.propel.template.twig", array(
165
            "module" => $module,
166
        ));
167
        $this->writeTemplateToFile($configTemplate, CORE_DIR . DIRECTORY_SEPARATOR . $module_path . DIRECTORY_SEPARATOR . "Config" .
168
            DIRECTORY_SEPARATOR . "config.php", true);
169
        $this->log->addLog("Generado config genérico para propel");
170
    }
171
172
173
    /**
174
     * @param string $module
175
     * @param string $mod_path
176
     * @param boolean $force
177
     * @param string $controllerType
178
     * @return boolean
179
     */
180
    private function generateControllerTemplate($module, $mod_path, $force = false, $controllerType = "")
181
    {
182
        //Generamos el controlador base
183
        $this->log->addLog("Generamos el controlador BASE");
184
        $class = preg_replace('/(\\\|\/)/', '', $module);
185
        $controllerBody = $this->tpl->dump("generator/controller.template.twig", array(
186
            "module" => $module,
187
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
188
            "url" => preg_replace('/(\\\|\/)/', '/', $module),
189
            "class" => $class,
190
            "controllerType" => $class . "Base",
191
            "is_base" => false
192
        ));
193
        $controller = $this->writeTemplateToFile($controllerBody, $mod_path . DIRECTORY_SEPARATOR . "Controller" .
194
            DIRECTORY_SEPARATOR . "{$class}Controller.php", $force);
195
196
        $controllerBody = $this->tpl->dump("generator/controller.template.twig", array(
197
            "module" => $module,
198
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
199
            "url" => preg_replace('/(\\\|\/)/', '/', $module),
200
            "class" => $class . "Base",
201
            "service" => $class,
202
            "controllerType" => $controllerType,
203
            "is_base" => true,
204
            "domain" => $class,
205
        ));
206
        $controllerBase = $this->writeTemplateToFile($controllerBody, $mod_path . DIRECTORY_SEPARATOR . "Controller" .
207
            DIRECTORY_SEPARATOR . "base" . DIRECTORY_SEPARATOR . "{$class}BaseController.php", true);
208
209
        $filename = $mod_path . DIRECTORY_SEPARATOR . "Test" . DIRECTORY_SEPARATOR . "{$class}Test.php";
210
        $test = true;
211
        if(!file_exists($filename)) {
212
            $testTemplate = $this->tpl->dump("generator/testCase.template.twig", array(
213
                "module" => $module,
214
                "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
215
                "class" => $class,
216
            ));
217
            $test = $this->writeTemplateToFile($testTemplate, $filename, true);
218
        }
219
        return ($controller && $controllerBase && $test);
220
    }
221
222
    /**
223
     * @param string $module
224
     * @param string $mod_path
225
     * @param boolean $force
226
     * @param string $apiClass
227
     * @return boolean
228
     */
229
    private function generateBaseApiTemplate($module, $mod_path, $force = false, $apiClass = "")
230
    {
231
        $created = true;
232
        $modelPath = $mod_path . $module . DIRECTORY_SEPARATOR . 'Models';
233
        $api_path = $mod_path . $module . DIRECTORY_SEPARATOR . 'Api';
234
        if (file_exists($modelPath)) {
235
            $dir = dir($modelPath);
236
            while ($file = $dir->read()) {
237
                if (!in_array($file, array('.', '..'))
238
                    && !preg_match('/Query\.php$/i', $file)
239
                    && preg_match('/\.php$/i', $file)
240
                ) {
241
                    $filename = str_replace(".php", "", $file);
242
                    $this->log->addLog("Generamos Api BASES para {$filename}");
243
                    $this->createApiBaseFile($module, $api_path, $filename, $apiClass);
244
                    $this->createApi($module, $api_path, $force, $filename);
245
                }
246
            }
247
        }
248
        return $created;
249
    }
250
251
    /**
252
     * @param string $mod_path
253
     * @param boolean $force
254
     * @return boolean
255
     */
256
    private function generateConfigTemplate($mod_path, $force = false)
257
    {
258
        //Generamos el fichero de configuración
259
        $this->log->addLog("Generamos fichero vacío de configuración");
260
        return $this->writeTemplateToFile("<?php\n\t",
261
            $mod_path . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "config.php",
262
            $force);
263
    }
264
265
    /**
266
     * @param string $mod_path
267
     * @param string $mod_path
268
     * @param boolean $force
269
     * @return boolean
270
     */
271
    private function generatePublicTemplates($mod_path, $force = false)
272
    {
273
        //Generamos el fichero de configuración
274
        $this->log->addLog("Generamos ficheros para assets base");
275
        $css = $this->writeTemplateToFile("/* CSS3 STYLES */\n\n",
276
            $mod_path . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . "css" . DIRECTORY_SEPARATOR . "styles.css",
277
            $force);
278
        $js = $this->writeTemplateToFile("/* APP MODULE JS */\n\n(function() {\n\t'use strict';\n})();",
279
            $mod_path . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . "js" . DIRECTORY_SEPARATOR . "app.js",
280
            $force);
281
        return ($css && $js);
282
    }
283
284
    /**
285
     * @param string $module
286
     * @param string $mod_path
287
     * @param boolean $force
288
     * @return boolean
289
     */
290
    private function generateServiceTemplate($module, $mod_path, $force = false)
291
    {
292
        //Generamos el controlador base
293
        $this->log->addLog("Generamos el servicio BASE");
294
        $class = preg_replace('/(\\\|\/)/', '', $module);
295
        $controller = $this->tpl->dump("generator/service.template.twig", array(
296
            "module" => $module,
297
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
298
            "class" => $class,
299
        ));
300
        return $this->writeTemplateToFile($controller,
301
            $mod_path . DIRECTORY_SEPARATOR . "Services" . DIRECTORY_SEPARATOR . "{$class}Service.php",
302
            $force);
303
    }
304
305
    /**
306
     * @param string $module
307
     * @param string $mod_path
308
     * @param boolean $force
309
     * @return boolean
310
     */
311
    private function genereateAutoloaderTemplate($module, $mod_path, $force = false)
312
    {
313
        //Generamos el autoloader del módulo
314
        $this->log->addLog("Generamos el autoloader");
315
        $autoloader = $this->tpl->dump("generator/autoloader.template.twig", array(
316
            "module" => $module,
317
            "autoloader" => preg_replace('/(\\\|\/)/', '_', $module),
318
            "regex" => preg_replace('/(\\\|\/)/m', '\\\\\\\\\\\\', $module),
319
        ));
320
        $autoload = $this->writeTemplateToFile($autoloader, $mod_path . DIRECTORY_SEPARATOR . "autoload.php", $force);
321
322
        $this->log->addLog("Generamos el phpunit");
323
        $phpUnitTemplate = $this->tpl->dump("generator/phpunit.template.twig", array(
324
            "module" => $module,
325
        ));
326
        $phpunit = $this->writeTemplateToFile($phpUnitTemplate, $mod_path . DIRECTORY_SEPARATOR . "phpunit.xml.dist", $force);
327
        return $autoload && $phpunit;
328
    }
329
330
    /**
331
     * @param string $module
332
     * @param string $mod_path
333
     * @param boolean $force
334
     * @return boolean
335
     */
336
    private function generateSchemaTemplate($module, $mod_path, $force = false)
337
    {
338
        //Generamos el autoloader del módulo
339
        $this->log->addLog("Generamos el schema");
340
        $schema = $this->tpl->dump("generator/schema.propel.twig", array(
341
            "module" => $module,
342
            "namespace" => preg_replace('/(\\\|\/)/', '', $module),
343
            "prefix" => preg_replace('/(\\\|\/)/', '', $module),
344
            "db" => $this->config->get("db_name"),
345
        ));
346
        return $this->writeTemplateToFile($schema,
347
            $mod_path . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "schema.xml",
348
            $force);
349
    }
350
351
    /**
352
     * @param string $module
353
     * @param string $mod_path
354
     * @param boolean $force
355
     * @return boolean
356
     */
357
    private function generatePropertiesTemplate($module, $mod_path, $force = false)
358
    {
359
        $this->log->addLog("Generamos la configuración de Propel");
360
        $build_properties = $this->tpl->dump("generator/build.properties.twig", array(
361
            "module" => $module,
362
            "namespace" => preg_replace('/(\\\|\/)/', '', $module),
363
        ));
364
        return $this->writeTemplateToFile($build_properties,
365
            $mod_path . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "propel.yml",
366
            $force);
367
    }
368
369
    /**
370
     * @param string $module
371
     * @param string $mod_path
372
     * @param boolean $force
373
     * @return boolean
374
     */
375
    private function generateIndexTemplate($module, $mod_path, $force = false)
376
    {
377
        //Generamos la plantilla de index
378
        $this->log->addLog("Generamos una plantilla base por defecto");
379
        $index = $this->tpl->dump("generator/index.template.twig", array(
380
            "module" => $module,
381
        ));
382
        return $this->writeTemplateToFile($index,
383
            $mod_path . DIRECTORY_SEPARATOR . "Templates" . DIRECTORY_SEPARATOR . "index.html.twig",
384
            $force);
385
    }
386
387
    /**
388
     * Método que graba el contenido de una plantilla en un fichero
389
     * @param string $fileContent
390
     * @param string $filename
391
     * @param boolean $force
392
     * @return boolean
393
     */
394
    private function writeTemplateToFile($fileContent, $filename, $force = false)
395
    {
396
        $created = false;
397
        if ($force || !file_exists($filename)) {
398
            try {
399
                $this->cache->storeData($filename, $fileContent, Cache::TEXT, true);
400
                $created = true;
401
            } catch (\Exception $e) {
402
                Logger::log($e->getMessage(), LOG_ERR);
403
            }
404
        } else {
405
            Logger::log($filename . t(' not exists or cant write'), LOG_ERR);
406
        }
407
        return $created;
408
    }
409
410
    /**
411
     * Create ApiBase
412
     * @param string $module
413
     * @param string $mod_path
414
     * @param string $api
415
     * @param string $apiClass
416
     *
417
     * @return bool
418
     */
419
    private function createApiBaseFile($module, $mod_path, $api, $apiClass = '')
420
    {
421
        $class = preg_replace('/(\\\|\/)/', '', $module);
422
        $customClass = GeneratorHelper::extractClassFromNamespace($apiClass);
423
        $controller = $this->tpl->dump("generator/api.base.template.twig", array(
424
            "module" => $module,
425
            "api" => $api,
426
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
427
            "url" => preg_replace('/(\\\|\/)/', '/', $module),
428
            "class" => $class,
429
            'customClass' => $customClass,
430
            'customNamespace' => $apiClass,
431
        ));
432
433
        return $this->writeTemplateToFile($controller,
434
            $mod_path . DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR . "{$api}BaseApi.php", true);
435
    }
436
437
    /**
438
     * Create Api
439
     * @param string $module
440
     * @param string $mod_path
441
     * @param bool $force
442
     * @param string $api
443
     *
444
     * @return bool
445
     */
446
    private function createApi($module, $mod_path, $force, $api)
447
    {
448
        $class = preg_replace('/(\\\|\/)/', '', $module);
449
        $controller = $this->tpl->dump("generator/api.template.twig", array(
450
            "module" => $module,
451
            "api" => $api,
452
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
453
            "url" => preg_replace('/(\\\|\/)/', '/', $module),
454
            "class" => $class,
455
        ));
456
457
        return $this->writeTemplateToFile($controller, $mod_path . DIRECTORY_SEPARATOR . "{$api}.php", $force);
458
    }
459
460
    /**
461
     * Method that copy resources recursively
462
     * @param string $dest
463
     * @param boolean $force
464
     * @param $filename_path
465
     * @param boolean $debug
466
     */
467 1
    public static function copyResources($dest, $force, $filename_path, $debug)
468
    {
469 1
        if (file_exists($filename_path)) {
470 1
            $destfolder = basename($filename_path);
471 1
            if (!file_exists(WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) || $debug || $force) {
472 1
                if (is_dir($filename_path)) {
473 1
                    self::copyr($filename_path, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder);
474
                } else {
475
                    if (@copy($filename_path, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) === FALSE) {
476
                        throw new ConfigException("Can't copy " . $filename_path . " to " . WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder);
477
                    }
478
                }
479
            }
480
        }
481 1
    }
482
483
    /**
484
     * Method that copy a resource
485
     * @param string $src
486
     * @param string $dst
487
     * @throws ConfigException
488
     */
489 1
    public static function copyr($src, $dst)
490
    {
491 1
        $dir = opendir($src);
492 1
        GeneratorHelper::createDir($dst);
493 1
        while (false !== ($file = readdir($dir))) {
0 ignored issues
show
Bug introduced by
It seems like $dir can also be of type false; however, parameter $dir_handle of readdir() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

493
        while (false !== ($file = readdir(/** @scrutinizer ignore-type */ $dir))) {
Loading history...
494 1
            if (($file != '.') && ($file != '..')) {
495 1
                if (is_dir($src . '/' . $file)) {
496 1
                    self::copyr($src . '/' . $file, $dst . '/' . $file);
497 1
                } elseif (@copy($src . '/' . $file, $dst . '/' . $file) === false) {
498
                    throw new ConfigException("Can't copy " . $src . " to " . $dst);
499
                }
500
            }
501
        }
502 1
        closedir($dir);
0 ignored issues
show
Bug introduced by
It seems like $dir can also be of type false; however, parameter $dir_handle of closedir() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

502
        closedir(/** @scrutinizer ignore-type */ $dir);
Loading history...
503 1
    }
504
505
    /**
506
     * @param $module_path
507
     * @return array
508
     */
509
    private function getPropelPaths($module_path)
510
    {
511
        $moduleDir = CORE_DIR . DIRECTORY_SEPARATOR . $module_path;
512
        GeneratorHelper::createDir($moduleDir);
513
        $moduleDir = realpath($moduleDir);
514
        $configDir = $moduleDir . DIRECTORY_SEPARATOR . 'Config';
515
        $sqlDir = $moduleDir . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'Sql';
516
        $migrationDir = $moduleDir . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'Migrations';
517
        $paths = [
518
            'projectDir' => $moduleDir,
519
            'outputDir' => $moduleDir,
520
            'phpDir' => $moduleDir,
521
            'phpConfDir' => $configDir,
522
            'sqlDir' => $sqlDir,
523
            'migrationDir' => $migrationDir,
524
            'schemaDir' => $configDir,
525
        ];
526
        return $paths;
527
    }
528
529
    /**
530
     * @param string $module_path
531
     * @return GeneratorConfig
532
     */
533
    private function getConfigGenerator($module_path)
534
    {
535
        // Generate the configurator
536
        $paths = $this->getPropelPaths($module_path);
537
        foreach ($paths as $path) {
538
            GeneratorHelper::createDir($path);
539
        }
540
        $configGenerator = new GeneratorConfig($paths['phpConfDir'], [
541
            'propel' => [
542
                'paths' => $paths,
543
            ]
544
        ]);
545
        return $configGenerator;
546
    }
547
548
    /**
549
     * @param GeneratorConfig $configGenerator
550
     */
551
    private function buildModels(GeneratorConfig $configGenerator)
552
    {
553
        $manager = new ModelManager();
554
        $manager->setFilesystem(new Filesystem());
555
        $this->setupManager($configGenerator, $manager);
556
        $manager->build();
557
    }
558
559
    /**
560
     * @param GeneratorConfig $configGenerator
561
     */
562
    private function buildSql(GeneratorConfig $configGenerator)
563
    {
564
        $manager = new SqlManager();
565
        $connections = $configGenerator->getBuildConnections();
566
        $manager->setConnections($connections);
567
        $manager->setValidate(true);
568
        $this->setupManager($configGenerator, $manager, $configGenerator->getSection('paths')['sqlDir']);
569
570
        $manager->buildSql();
571
    }
572
573
    /**
574
     * @param GeneratorConfig $configGenerator
575
     * @param AbstractManager $manager
576
     * @param string $workingDir
577
     */
578
    private function setupManager(GeneratorConfig $configGenerator, AbstractManager &$manager, $workingDir = CORE_DIR)
579
    {
580
        $manager->setGeneratorConfig($configGenerator);
581
        $schemaFile = new \SplFileInfo($configGenerator->getSection('paths')['schemaDir'] . DIRECTORY_SEPARATOR . 'schema.xml');
582
        $manager->setSchemas([$schemaFile]);
583
        $manager->setLoggerClosure(function ($message) {
584
            Logger::log($message, LOG_INFO);
585
        });
586
        $manager->setWorkingDirectory($workingDir);
587
    }
588
}
589