/**
  * Builds the settings file
  */
 public function build()
 {
     /**
      * To get a clean PHP source code from the getLocalDateTimeFormat()
      * We use the var_export(...) function
      */
     $header = "<?php ";
     $settings = var_export(array('datetimeFormat' => $this->config->getLocalDateTimeFormat()), true);
     $tmpFile = TEMP_DIR . '/' . uniqid() . '.php';
     file_put_contents($tmpFile, $header . $settings);
     $settings = php_strip_whitespace($tmpFile);
     unlink($tmpFile);
     render_php_template(dirname(__FILE__) . '/Template/datetime.php', ['settings' => trim(str_replace($header, '', $settings)), 'namespace' => $this->config->getApplicationNamespace() . '\\' . $this->config->getModelRootNamespace()], $this->config->getTargetRootFolder() . '/Database/DateTimeConversion.php', false);
 }
Esempio n. 2
0
 protected function generateClasses(Schema $schema)
 {
     $this->cleanBeforeBuild($schema);
     /**
      * To build the Models and Factory classes we use the following strategy:
      * First we build a model and gather the $converterInfo, then when we
      * are buidling the Factory class we use the previously built $converterInfo
      * to feed the Factory building. This is primarily done to avoid writing
      * redundant code.
      */
     $conatiner = new Container();
     $converterResolver = function ($schema, $relation, $column, $dbtype, $fqcn) {
         return $this->config->getConverterForField($schema, $relation, $column, $dbtype, $fqcn);
     };
     foreach ($schema->getRelations() as $relation) {
         $allowCustomize = $this->allowCustomize($relation);
         $rootPath = $this->config->getTargetRootFolder();
         $rootNamespace = $this->config->getModelRootNamespace();
         $appNamespace = $this->config->getApplicationNamespace();
         $converterInfo = null;
         foreach ([ModelBuilder::class, FactoryBuilder::class, SchemaBuilder::class] as $builderClass) {
             /* @var $builderClass \Blend\DataModelBuilder\Builder\ClassBuilder */
             $builder = $conatiner->get($builderClass, ['relation' => $relation, 'includeSchema' => !$schema->isSingle()]);
             $builder->setApplicationNamespace($appNamespace);
             $builder->setRootNamespace($rootNamespace);
             $builder->setRootPath($rootPath);
             $builder->setColumnConverterResolver($converterResolver);
             if ($builder instanceof FactoryBuilder) {
                 if (count($converterInfo) !== 0) {
                     $builder->setFieldConverterClass($this->config->getFieldConverterClass());
                 }
                 $builder->setFieldConverterInfo($converterInfo);
                 $builder->setCustomFactoryMethods($this->config->getModelFactoryMethods());
             }
             if ($builder instanceof SchemaBuilder === false) {
                 $builder->build($allowCustomize);
             }
             if ($builder instanceof ModelBuilder) {
                 $converterInfo = $builder->getFieldConverterInfo();
             }
             if ($builder instanceof SchemaBuilder && $this->needSchemaHelper($relation)) {
                 $builder->build(false);
             }
         }
     }
 }