Ejemplo n.º 1
0
 /**
  * Construtor
  * 
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @param Lumine_Configuration $cfg
  * @return Lumine_Union
  */
 function __construct(Lumine_Configuration $cfg)
 {
     $clname = 'Lumine_Dialect_' . $cfg->getProperty('dialect');
     $this->_package = $cfg->getProperty('package');
     $this->_tablename = 'union';
     parent::__construct();
     // $this->_bridge = new $clname( $this );
 }
Ejemplo n.º 2
0
 /**
  * Construtor
  * 
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @param Lumine_Configuration $cfg
  * @return Lumine_Union
  */
 function __construct(Lumine_Configuration $cfg)
 {
     $this->_metadata = new Lumine_Metadata($this);
     $clname = 'Lumine_Dialect_' . $cfg->getProperty('dialect');
     $this->metadata()->setPackage($cfg->getProperty('package'));
     $this->metadata()->setTablename('union');
     parent::__construct();
     // $this->_bridge = new $clname( $this );
 }
Ejemplo n.º 3
0
 /**
  * Carrega a lista de arquivos e classes instanciadas da configuracao indicada
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br
  * @return void
  */
 protected function loadClassFileList()
 {
     if ($this->loaded == true) {
         return;
     }
     $this->loaded = true;
     $dir = $this->cfg->getProperty('class_path') . DIRECTORY_SEPARATOR;
     $dir .= str_replace('.', DIRECTORY_SEPARATOR, $this->cfg->getProperty('package'));
     $dir .= DIRECTORY_SEPARATOR;
     if (is_dir($dir)) {
         $dh = opendir($dir);
         while (($file = readdir($dh)) !== false) {
             if (preg_match('@\\.php$@', $file)) {
                 $className = str_replace('.php', '', $file);
                 $this->cfg->import($className);
                 if (class_exists($className)) {
                     $oReflection = new ReflectionClass($className);
                     $oClass = $oReflection->newInstance();
                     if ($oClass instanceof Lumine_Base) {
                         $this->fileList[] = $dir . $file;
                         $this->classList[$className] = $oClass;
                     } else {
                         unset($oClass);
                     }
                     unset($oReflection);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * retona a classe criada
  *
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br
  * @param string $tablename
  * @param Lumine_Configuration $cfg
  * @return Lumine_Factory
  */
 public static function create($tablename, Lumine_Configuration $cfg)
 {
     $pkg = $cfg->getProperty('package');
     Lumine_Log::debug('Recuperando campos da tabela ' . $tablename);
     $fields = $cfg->getConnection()->describe($tablename);
     $obj = new Lumine_Factory($pkg, $tablename);
     foreach ($fields as $item) {
         list($name, $type_native, $type, $length, $primary, $notnull, $default, $autoincrement) = $item;
         $options = array('primary' => $primary, 'notnull' => $notnull, 'autoincrement' => $autoincrement);
         // para o pg, ainda tem o nome da sequence
         if (!empty($item[8]['sequence'])) {
             $options['sequence'] = $item[8]['sequence'];
         }
         // se tiver um valor padrao
         if (!empty($default)) {
             $options['default'] = $default;
         }
         // nome do membro
         $memberName = $name;
         // se for para usar camel case
         if ($cfg->getOption('camel_case') == true) {
             $memberName = Lumine_Util::camelCase($memberName);
         }
         $obj->metadata()->addField($memberName, $name, $type, $length, $options);
     }
     return $obj;
 }
Ejemplo n.º 5
0
 /**
  * Gera os arquivos
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @param boolean $overwrite Forca a sobrescrita nos arquivos
  * @return void
  */
 private function generateFiles($overwrite)
 {
     Lumine_Log::debug('Gerando arquivos direto na pasta');
     $fullpath = $this->cfg->getProperty('class_path') . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $this->cfg->getProperty('package'));
     $sufix = $this->cfg->getOption('class_sufix');
     if (!empty($sufix)) {
         $sufix = '.' . $sufix;
     }
     $dummy = new Lumine_Reverse_ClassTemplate();
     $end = $dummy->getEndDelim();
     if (!file_exists($fullpath) && $this->cfg->getOption('create_paths') == 1) {
         mkdir($fullpath, 0777, true) or die('Não foi possivel criar o diretorio: ' . $fullpath);
     }
     reset($this->files);
     foreach ($this->files as $classname => $content) {
         $filename = $fullpath . DIRECTORY_SEPARATOR . $classname . $sufix . '.php';
         if (file_exists($filename) && empty($overwrite)) {
             $fp = fopen($filename, 'r');
             $old_content = fread($fp, filesize($filename));
             fclose($fp);
             $start = strpos($old_content, $end) + strlen($end);
             $customized = substr($old_content, $start);
             $top = substr($content, 0, strpos($content, $end));
             $content = $top . $end . $customized;
         }
         $fp = @fopen($filename, 'w');
         if ($fp) {
             fwrite($fp, $content);
             fclose($fp);
             chmod($filename, 0777);
             Lumine_Log::debug('Arquivo para a classe ' . $classname . ' gerado com sucesso');
         } else {
             Lumine_Log::error('O PHP nao tem direito de escrita na pasta "' . $fullpath . '". Verifique se o diretario existe e se o PHP tem direito de escrita.');
             exit;
         }
     }
     //// cria os dtos
     if ($this->cfg->getOption('create_dtos')) {
         reset($this->dtos);
         // pasta raiz dos DTO's
         $path = $this->cfg->getProperty('class_path') . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $this->cfg->getProperty('package')) . DIRECTORY_SEPARATOR . 'dto';
         // para cada DTO
         foreach ($this->dtos as $obj) {
             $fullpath = $path . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $obj->getPackage());
             // se o diretorio nao existe, tenta criar
             if (!is_dir($fullpath) && $this->cfg->getOption('create_paths') == 1) {
                 mkdir($fullpath, 0777, true) or die('Não foi possivel criar o diretorio: ' . $fullpath);
             }
             $filename = $fullpath . DIRECTORY_SEPARATOR . $obj->getClassname() . $sufix . '.php';
             file_put_contents($filename, $obj->getContent());
         }
     }
     // models
     foreach ($this->models as $item) {
         Lumine_Log::debug('Criando Model ' . $item->getClassname());
         $filename = $item->getFullFileName();
         if (!is_dir(dirname($filename)) && $this->cfg->getOption('create_paths') == 1) {
             $path = dirname($filename);
             mkdir($path, 0777, true) or die('Não foi possivel criar o diretorio: ' . $path);
         } else {
             if (!is_dir(dirname($filename))) {
                 $path = dirname($filename);
                 Lumine_Log::error('Nao eh possivel gravar em ' . $path . '. Verifique se a pasta existe e se ha permissao de gravacao');
             }
         }
         $content = $item->getContent();
         file_put_contents($filename, $content);
         chmod($filename, 0777);
     }
     // copia o arquivo de contexto
     if ($this->cfg->getOption('model_context') == 1) {
         $contextFile = LUMINE_INCLUDE_PATH . '/lib/Templates/ApplicationContext.php';
         if (file_exists($contextFile)) {
             $path = $this->cfg->getProperty('class_path') . DIRECTORY_SEPARATOR . $this->cfg->getOption('model_context_path') . DIRECTORY_SEPARATOR;
             if (!is_dir($path)) {
                 if ($this->cfg->getOption('create_paths') == 1) {
                     mkdir($path, 0777, true) or die('Não foi possivel criar o diretorio ' . $path);
                 } else {
                     Lumine_Log::error('Nao foi possivel gravar o contexto na pasta ' . $path . '. Verifique se a pasta existe.');
                 }
             }
             $destino = $path . 'Lumine_ApplicationContext.php';
             // so copiamos se o arquivo nao existir
             if (!file_exists($destino)) {
                 Lumine_Log::debug('Copiando arquivo de contexto: ' . $destino);
                 copy($contextFile, $destino);
                 chmod($path . 'Lumine_ApplicationContext.php', 0777);
                 // ja existe, nao copaimos mas avisamos
             } else {
                 Lumine_Log::debug('O arquivo "' . $destino . '" ja existe');
             }
         }
     }
     // escreve os controles
     $path = $this->cfg->getProperty('class_path');
     $path .= DIRECTORY_SEPARATOR . 'controls' . DIRECTORY_SEPARATOR;
     if (!file_exists($path) && $this->cfg->getOption('create_paths') == 1) {
         mkdir($path, 0777, true) or die('Nao foi possivel criar o diretorio: ' . $path);
     }
     foreach ($this->controls as $classname => $content) {
         $filename = $path . $classname . '.php';
         $fp = @fopen($filename, 'w');
         if (!$fp) {
             Lumine_Log::error('O PHP nao tem direito de escrita para gerar o arquivo "' . $filename . '". Verifique se o diretorio existe e se o PHP tem direito de escrita.');
             exit;
         } else {
             fwrite($fp, $content);
             fclose($fp);
             Lumine_Log::debug('Arquivo de controle "' . $filename . '" gerado com sucesso.');
         }
     }
     // copia os demais arquivos
     if (!empty($this->controls) && $this->cfg->getOption('create_controls') != '') {
         $class = 'Lumine_Form_' . $this->cfg->getOption('create_controls');
         $ref = new ReflectionClass($class);
         $instance = $ref->newInstance(null);
         $instance->copyFiles($path);
     }
     // escreve o arquivo de configuracao
     $filename = $this->cfg->getProperty('class_path') . DIRECTORY_SEPARATOR . 'lumine-conf.php';
     $fp = @fopen($filename, 'w');
     if (!$fp) {
         Lumine_Log::error('O PHP nao tem direito de escrita para gerar o arquivo "' . $filename . '". Verifique se o diretorio existe e se o PHP tem direito de escrita.');
         exit;
     }
     fwrite($fp, $this->config);
     fclose($fp);
     Lumine_Log::debug('Arquivo "' . $filename . '" gerado com sucesso.');
 }
Ejemplo n.º 6
0
 /**
  * 
  * @see Lumine_Form_IForm::getControlTemplate()
  */
 public function getControlTemplate(Lumine_Configuration $cfg, $className)
 {
     $file = LUMINE_INCLUDE_PATH . $this->template . 'control.txt';
     if (!file_exists($file)) {
         Lumine_Log::error('O arquivo "' . $file . '" nao existe!');
         exit;
     }
     $content = file_get_contents($file);
     $content = str_replace('{class_path}', str_replace('\\', '/', $cfg->getProperty('class_path')), $content);
     $content = str_replace('{entity_name}', $className, $content);
     $content = str_replace('{LUMINE_PATH}', LUMINE_INCLUDE_PATH, $content);
     return $content;
 }