예제 #1
0
 /**
  * Procura pelo arquivo XML para efetuar a validacao
  * 
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @param Lumine_Base $obj Instancia da Classe para ser validada
  * @return void
  */
 protected function checkForValidationFile(Lumine_Base $obj)
 {
     if (!class_exists('DomDocument')) {
         Lumine_Log::warning('Classe de validacao por XML "DomDocument" nao definida"');
     } else {
         $cfg = $obj->_getConfiguration();
         $xml_validation_path = $cfg->getOption('xml_validation_path');
         $classes_path = $cfg->getProperty('class_path') . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $cfg->getProperty('package'));
         $filename = $obj->_getName() . '-validation.xml';
         $file_list = array();
         $file_list[] = $cfg->getProperty('class_path') . DIRECTORY_SEPARATOR . $filename;
         $file_list[] = $classes_path . DIRECTORY_SEPARATOR . $filename;
         $file_list[] = $classes_path . DIRECTORY_SEPARATOR . 'validators' . DIRECTORY_SEPARATOR . $filename;
         if (!empty($xml_validation_path)) {
             $file_list[] = $xml_validation_path . DIRECTORY_SEPARATOR . $filename;
         }
         $file = '';
         foreach ($file_list as $filename) {
             if (file_exists($filename)) {
                 Lumine_Log::debug('Arquivo ' . $filename . ' encontrado, iniciando validacao.');
                 $file = $filename;
                 break;
             } else {
                 Lumine_Log::debug('Arquivo ' . $filename . ' nao encontrado.');
             }
         }
         if ($file != '') {
             $this->xml = $file;
         } else {
             Lumine_Log::warning('Nenhum arquivo de validacao em XML encontrado para "' . $obj->_getName() . '"', __FILE__, __LINE__);
         }
     }
 }
예제 #2
0
 /**
  * Cria uma nova referencia de conexao com o banco
  *
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @param string $connectionName Nome da conexao
  * @param Lumine_Configuration $config Objeto de configuracao
  * @return void
  */
 public function create($connectionName, Lumine_Configuration $config)
 {
     if ($this->getConnection($connectionName) != false) {
         Lumine_Log::warning('Ja existe uma conexao com este nome: ' . $connectionName);
     } else {
         Lumine_Log::debug('Armazenando conexao: ' . $connectionName);
         $connObj = $this->getConnectionClass($config->options['dialect']);
         if ($connObj == false) {
             Lumine_Log::error('Dialeto nao implementado: ' . $config->options['dialect']);
             return;
         }
         $connObj->setDatabase($config->options['database']);
         $connObj->setHost($config->options['host']);
         $connObj->setPort($config->options['port']);
         $connObj->setUser($config->options['user']);
         $connObj->setPassword($config->options['password']);
         if (isset($config->options['options'])) {
             $connObj->setOptions($config->options['options']);
         }
         if ($config->getOption('charset') != '') {
             $connObj->setCharset($config->getOption('charset'));
         }
         $config->setConnection($connObj);
         $this->connections[$connectionName] = $config;
     }
 }
예제 #3
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;
 }
예제 #4
0
 /**
  * @see Lumine_Connection_IConnection::close()
  */
 public function close()
 {
     $this->dispatchEvent(new Lumine_Events_ConnectionEvent(Lumine_Event::PRE_CLOSE, $this));
     if ($this->conn_id && $this->state != self::CLOSED) {
         Lumine_Log::debug('Liberando resultados todos os resultados');
         Lumine_Dialect_Factory::getByName('MySQL')->freeAllResults();
         $this->state = self::CLOSED;
         Lumine_Log::debug('Fechando conexao com ' . $this->getDatabase());
         mysql_close($this->conn_id);
     }
     $this->dispatchEvent(new Lumine_Events_ConnectionEvent(Lumine_Event::POS_CLOSE, $this));
 }
예제 #5
0
 /**
  * 
  * @see Lumine_Export_IExport::create()
  */
 public function create()
 {
     $this->getForeignKeys();
     $this->getIndexes();
     $this->getTablesDefinition();
     $sqlList = array_merge($this->tables, $this->indexes);
     // para cada chave estrangeira, criaremos o SQL de geracao do Foreign Key
     reset($this->foreignKeys);
     foreach ($this->foreignKeys as $fk) {
         $sql = sprintf('ALTER TABLE `%s` ADD FOREIGN KEY(`%s`) REFERENCES `%s`(`%s`) ON DELETE %s ON UPDATE %s', $fk['table'], $fk['column'], $fk['reftable'], $fk['refcolumn'], $fk['onDelete'], $fk['onUpdate']);
         $sqlList[] = $sql;
     }
     $sqlList = array_merge($sqlList, $this->foreignKeysSQL);
     // ok, agora que temos as definicoes de tabela, vamos cria-las no banco
     // e so executar uma a uma
     foreach ($sqlList as $sql) {
         Lumine_Log::debug('Executando a SQL: ' . $sql);
         $this->cnn->executeSQL($sql);
     }
 }
예제 #6
0
 /**
  * Retorna o indice do registro atual
  * @return int;
  */
 public function key()
 {
     Lumine_Log::debug('Retornando o indice ' . ($this->_iteratorPosition + 1) . ' para iterator');
     return $this->_iteratorPosition;
 }
예제 #7
0
 /**
  * Limpa o resultado armazenado para o objeto atual
  * 
  * @author Hugo Ferreira da Silva
  * @return void
  */
 public function freeResult($resultID)
 {
     if (isset($this->resultList[$resultID]) && is_resource($this->resultList[$resultID])) {
         Lumine_Log::debug('Liberando o registro #' . $resultID);
         ibase_free_result($this->resultList[$resultID]);
     }
 }
예제 #8
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.');
 }
예제 #9
0
 /**
  * recupera uma opcao de um campo desejado
  *
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @param string $name nome do campo desejado
  * @param string $option nome da opcao desejada
  * @return mixed Valor da opcao
  */
 public function getFieldOption($name, $option)
 {
     try {
         $fld = $this->getField($name);
         if (isset($fld['options'][$option])) {
             return $fld['options'][$option];
         } else {
             if (isset($fld[$option])) {
                 return $fld[$option];
             }
         }
     } catch (Exception $e) {
         Lumine_Log::debug($e->getMessage());
     }
     return null;
 }
예제 #10
0
 /**
  * @see ILumine_Connection::executeSQL()
  */
 public function executeSQL($sql)
 {
     $this->dispatchEvent(new Lumine_ConnectionEvent(Lumine_Event::PRE_EXECUTE, $this, '', $sql));
     $this->connect();
     if (preg_match('@\\s*(LIMIT.+?)$@i', $sql, $reg)) {
         $sql = str_replace($reg[1], '', $sql);
         $limite = strtoupper($reg[1]);
         $limite = str_replace('LIMIT', 'FIRST', $limite);
         $limite = str_replace('OFFSET', 'SKIP', $limite);
         $sql = preg_replace('@^SELECT\\s+@i', 'SELECT ' . $limite . ' ', $sql);
         Lumine_Log::debug('Consulta transformada para Firebird: ' . $sql);
     }
     $rs = @ibase_query($sql, $this->conn_id);
     if (!$rs) {
         $msg = $this->getErrorMsg();
         $this->dispatchEvent(new Lumine_ConnectionEvent(Lumine_Event::EXECUTE_ERROR, $this, $msg, $sql));
         throw new Lumine_Exception("Falha na consulta: " . $msg, Lumine_Exception::QUERY_ERROR);
     }
     $this->dispatchEvent(new Lumine_ConnectionEvent(Lumine_Event::CONNECTION_ERROR, $this, '', $sql));
     return $rs;
 }
예제 #11
0
 /**
  * @see ILumine_Connection::close()
  */
 public function close()
 {
     $this->dispatchEvent(new Lumine_ConnectionEvent(Lumine_Event::PRE_CLOSE, $this));
     if ($this->conn_id && self::$state != self::CLOSED) {
         self::$state = self::CLOSED;
         Lumine_Log::debug('Fechando conexao com ' . $this->getDatabase());
         pg_close($this->conn_id);
     }
     $this->dispatchEvent(new Lumine_ConnectionEvent(Lumine_Event::POS_CLOSE, $this));
 }
예제 #12
0
 /**
  * Cria uma classe pelo nome da tabelaon the fly
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br
  * @param string $tablename Nome da tabela
  * @return Lumine_Factory
  */
 public function factory($tablename)
 {
     Lumine_Log::debug('Criando entidade para a tabela ' . $tablename);
     return Lumine_Factory::create($tablename, $this);
 }
예제 #13
0
 /**
  * Importa o DTO relacionado a classe, quando houver
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @return void
  */
 public static function importDTO()
 {
     $args = func_get_args();
     $cn = Lumine_ConnectionManager::getInstance();
     $list = $cn->getConfigurationList();
     $cfg = array_shift($list);
     /////////////////////////////////////////////////////////////
     // alteracoes para poder buscar os DTO's em varios pacotes
     /////////////////////////////////////////////////////////////
     $dtoPkgList = $cfg->getOption('dto_package');
     if (!is_array($dtoPkgList)) {
         $dtoPkgList = array($dtoPkgList);
         $cfg->setOption('dto_package', $dtoPkgList);
     }
     foreach ($dtoPkgList as $dtoPkg) {
         $path = $cfg->getProperty('class_path') . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $cfg->getProperty('package')) . DIRECTORY_SEPARATOR . 'dto' . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $dtoPkg) . DIRECTORY_SEPARATOR;
         foreach ($args as $classname) {
             Lumine_Log::debug('procurando dto ' . $path . $classname);
             $filename = $path . $classname . $cfg->getOption('class_sufix') . '.php';
             if (file_exists($filename)) {
                 require_once $filename;
             }
         }
     }
 }
예제 #14
0
파일: MsSQL.php 프로젝트: rrmoura1/Abstergo
 /**
  * @see ILumine_Connection::executeSQL()
  */
 public function executeSQL($sql)
 {
     $this->dispatchEvent(new Lumine_ConnectionEvent(Lumine_Event::PRE_EXECUTE, $this, '', $sql));
     $this->connect();
     if (preg_match('@\\s*(LIMIT.+?)$@i', $sql, $reg)) {
         $sql = str_replace($reg[1], '', $sql);
         preg_match('@LIMIT\\s*(\\d+)\\s*(OFFSET\\s*(\\d+)?)?@i', $reg[1], $f);
         $limit = $f[1];
         $offset = isset($f[3]) ? $f[3] : 0;
         $sql = $this->modifyLimitQuery($sql, $limit, $offset);
         Lumine_Log::debug('Consulta transformada para MsSQL: ' . $sql);
     }
     $rs = @mssql_query($sql, $this->conn_id);
     if (!$rs) {
         $msg = $this->getErrorMsg();
         $this->dispatchEvent(new Lumine_ConnectionEvent(Lumine_Event::EXECUTE_ERROR, $this, $msg, $sql));
         throw new Lumine_Exception("Falha na consulta: " . $msg, Lumine_Exception::QUERY_ERROR);
     }
     $this->dispatchEvent(new Lumine_ConnectionEvent(Lumine_Event::POS_EXECUTE, $this, '', $sql));
     return $rs;
 }
예제 #15
0
         // ajusta algumas configuracoes
         if ($_POST['options']['tipo_geracao'] == 1) {
             $_POST['options']['generate_files'] = 1;
             $_POST['options']['generate_zip'] = 0;
         } else {
             if ($_POST['options']['tipo_geracao'] == 2) {
                 $_POST['options']['generate_files'] = 0;
                 $_POST['options']['generate_zip'] = 1;
             }
         }
         Lumine_Log::setLevel(Lumine_Log::ERROR);
         $cfg = new Lumine_Reverse($_POST);
         $cfg->setTables($table_list);
         $cfg->start();
         if (!empty($_POST['addons'])) {
             Lumine_Log::debug('Executando add-ons');
             foreach ($_POST['addons'] as $classname) {
                 foreach ($addons as $item) {
                     if (get_class($item) == $classname) {
                         $item->execute($_POST['class_path'] . '/lumine-conf.php', $_POST[strtolower($classname)]);
                     }
                 }
             }
         }
         echo '<span style="color: #006600; font-weight: bold;">Engenharia reversa terminada!</span>';
     } catch (Exception $e) {
         echo "Falha na engenharia reversa: " . $e->getMessage();
     }
     exit;
     break;
 case 'loadTemplate':