/**
  * 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;
     }
 }
示例#2
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;
 }
示例#3
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 );
 }
 /**
  * Construtor
  * 
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br
  * @return Lumine_ApplicationContext
  */
 public function __construct()
 {
     include 'lumine-conf.php';
     $cfg = new Lumine_Configuration($lumineConfig);
     register_shutdown_function(array($cfg->getConnection(), 'close'));
     spl_autoload_register(array('Lumine', 'import'));
     spl_autoload_register(array('Lumine', 'loadModel'));
 }
示例#5
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 );
 }
示例#6
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);
                 }
             }
         }
     }
 }
示例#7
0
 /**
  * Efetua o mapeamento da classe.
  *
  * @param Lumine_Base $target
  * @author Hugo Ferreira da Silva
  */
 public static function mapClass(Lumine_Descriptor_AbstractDescriptor $descriptor, Lumine_Configuration $config)
 {
     if (!isset(self::$mappedClasses[$descriptor->getClassname()])) {
         $cache = $config->getCacheImpl();
         $key = 'lumine:map:' . $descriptor->getClassname();
         if ($cache->exists($key)) {
             $classmap = $cache->fetch($key);
             if ($classmap['time'] != $descriptor->getModificationTime()) {
                 $classmap = $descriptor->parse();
                 $cache->store($key, $classmap);
             }
         } else {
             $classmap = $descriptor->parse();
             $cache->store($key, $classmap);
         }
         self::$mappedClasses[$descriptor->getClassname()] = $classmap;
     }
 }
示例#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
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>
################################################################################
require_once 'C:\\www\\ExtJS\\teste2\\Abstergo\\library\\Lumine/Lumine.php';
require_once 'C:/www/ExtJS/teste2/Abstergo/library/lumine-conf.php';
Lumine::load('Form_White');
$cfg = new Lumine_Configuration($lumineConfig);
$cfg->import('Clientes');
register_shutdown_function(array($cfg->getConnection(), 'close'));
$obj = new Clientes();
$form = new Lumine_Form_White($obj);
if (!empty($_REQUEST['_lumineAction'])) {
    switch ($_REQUEST['_lumineAction']) {
        case 'insert':
        case 'save':
            $result = $form->handleAction($_REQUEST['_lumineAction'], $_POST);
            if ($result === true) {
                header("Location: " . $_SERVER['PHP_SELF'] . '?msg=ok');
                exit;
            }
            break;
        case 'delete':
示例#10
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;
 }
示例#11
0
            }
            $class = new ReflectionClass($name);
            $instance = $class->newInstance();
            $method = $class->getMethod($method);
            if (is_null($method) || $method->isPublic() == false) {
                die('Metodo nao encontrado ou nao e publico');
            }
            $result = $method->invokeArgs($instance, array($_POST));
            echo $result;
            break;
        case 'tabelas':
            $res = false;
            $message = '';
            $list = array();
            try {
                $dbh = new Lumine_Configuration($_POST);
                $conn = $dbh->getConnection();
                $res = $conn->connect();
                $list = $conn->getTables();
                $conn->close();
                $dto_packages = array();
                if (!empty($_POST['options']['dto_package']) && !empty($_POST['options']['create_dtos'])) {
                    $dto_packages = $_POST['options']['dto_package'];
                }
                // 2011-04-15 - mapeamento de DTO's
                if (!empty($list)) {
                    echo '<input type="checkbox" onclick="checarTodas(this)" />Selecionar todas as tabelas<br /><br />';
                    foreach ($list as $table) {
                        printf('<p class="table-item">
									<span>
										<input type="checkbox" class="table" name="tables[]" value="%1$s" />