Ejemplo n.º 1
0
 /**
  * Executa o comando.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $parts = explode('\\', $name);
     $class_name = end($parts);
     $folder_name = nameToFolderName($name, 'Models');
     $root_ns = Config::getInstance()->get('root-namespace');
     if ($input->getOption('tablename')) {
         $table_name = $input->getOption('tablename');
     } else {
         $name = str_replace('\\', '', $name);
         preg_match_all('/([A-Z][a-z]+)/', $name, $teste);
         $table_name = implode('_', $teste[1]);
         $table_name = strtolower($table_name);
     }
     $tmp_name_folder = str_replace('/', '\\', $folder_name);
     $params = ['model_name' => $class_name, 'dev_name' => Config::getInstance()->get('app.developer'), 'data' => date('d/m/Y'), 'namespace' => $root_ns . '\\Models' . $tmp_name_folder, 'table_name' => $table_name];
     $template = TemplateHelper::getInstance()->render('model_template', $params);
     $cmd_file_path = SYS_ROOT . 'App' . DS . 'Models' . $folder_name . DS . $class_name . 'Model.php';
     if (is_file($cmd_file_path)) {
         $output->writeln('O model ' . $class_name . 'Model ja existe.');
         return true;
     }
     $hand = fopen($cmd_file_path, 'w+');
     fwrite($hand, $template);
     fclose($hand);
     $output->writeln('Model ' . $class_name . 'Model criado com sucesso.');
 }
Ejemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $root_name = Config::getInstance()->get('root-namespace');
     $path = SYS_ROOT . 'App';
     $classes = $this->loadAppCommands($path);
     $trocou = false;
     foreach ($classes as $class) {
         $initname = explode('\\', $class)[0];
         $class = str_replace($initname, 'App', $class);
         $fpath = SYS_ROOT . $class . '.php';
         if (is_file($fpath)) {
             $content = file_get_contents($fpath);
             $content = str_replace($root_name . '\\', $name . '\\', $content);
             $h = fopen($fpath, 'w+');
             fwrite($h, $content);
             fclose($h);
             $trocou = true;
         }
     }
     if ($trocou) {
         $this->changeComposerRoots($name, $output);
     }
     exec('php composer dump-autoload');
     $output->writeln('Namespace raiz trocado com sucesso.');
 }
Ejemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = trim($input->getArgument('name'));
     $parts = explode('\\', $name);
     $class_name = end($parts);
     $folder_name = nameToFolderName($name, 'Controllers');
     $root_ns = Config::getInstance()->get('root-namespace');
     $tmp_name_folder = str_replace('/', '\\', $folder_name);
     $params = ['controller_name' => nameToClassName($class_name), 'dev_name' => Config::getInstance()->get('app.developer'), 'data' => date('d/m/Y'), 'namespace' => $root_ns . '\\Controllers' . $tmp_name_folder];
     $template = TemplateHelper::getInstance()->render('resource_template', $params);
     $cmd_file_path = SYS_ROOT . 'App' . DS . 'Controllers' . $folder_name . DS . $class_name . 'Controller.php';
     if (is_file($cmd_file_path)) {
         $output->writeln('Anna: O Controlador ' . $class_name . 'Controller ja existe.');
         return true;
     }
     $hand = fopen($cmd_file_path, 'a+');
     if (!$hand) {
         $output->writeln('Anna: Não foi possível criar o arquivo do controlador.');
     }
     fwrite($hand, $template);
     fclose($hand);
     //add controlador na router
     if (!$this->addResourceToRoute($class_name)) {
         $output->writeln('Anna: Nao foi possivel criar uma nova rota.');
     }
     $output->writeln('Anna: Controlador ' . $class_name . 'Controller criado com sucesso.');
 }
Ejemplo n.º 4
0
 /**
  * @conver \Anna\Config
  */
 public function testeConfig()
 {
     $cfg = Config::getInstance();
     $this->assertEquals(Config::class, get_class($cfg), 'Nao foi encontrado instancia de Ann\\Config');
     $testParam = 'Value of Teste param';
     try {
         $cfg->set('testParam', $testParam);
     } catch (Exception $e) {
         $this->fail('Nao foi possivel escrever valor nas configuracoes');
     }
     try {
         $getTestParam = $cfg->get('testParam');
     } catch (Exception $e) {
         $this->fail('Nao foi possivel ler valor nas configuracoes');
     }
     $this->assertEquals('Value of Teste param', $getTestParam, 'Discrepancia entre os valores de entrada e saida das configuracoes');
     $testArrayParams = ['param1' => 'teste1', 'param2' => 'teste2', 'param3' => 'teste3', 'param4' => 'teste4'];
     try {
         $cfg->addConfigs($testArrayParams);
     } catch (Exception $e) {
         $this->fail('Nao foi possivel escrever array de valores nas configuracoes');
     }
     $this->assertEquals('teste1', $cfg->get('param1'), 'O parametro 1 nao foi devidamente salvo');
     $this->assertEquals('teste2', $cfg->get('param2'), 'O parametro 2 nao foi devidamente salvo');
     $this->assertEquals('teste3', $cfg->get('param3'), 'O parametro 3 nao foi devidamente salvo');
     $this->assertEquals('teste4', $cfg->get('param4'), 'O parametro 4 nao foi devidamente salvo');
 }
Ejemplo n.º 5
0
 /**
  * Inspeciona o arquivo de configuração do work manager para atualizar algumas configurações.
  *
  * @return bool
  */
 private function inspect()
 {
     $table = Table::getInstance();
     $table->loadInformation();
     $config = $table->getConfig();
     if ($config['active'] == false) {
         return false;
     }
     $amount = memory_get_usage(true);
     $megabytes = $amount / 1024 / 1024;
     $table->updateMemoryUsage($megabytes);
     //verificando se a memória atual esta´dentro do limite imposto pela configuração da aplicação
     $limit_memory = Config::getInstance()->get('app.work-limit-memory');
     if ($megabytes >= $limit_memory) {
         $table->turnOff();
         exec('php anna job:up');
     }
     $config = null;
     $table = null;
     $amount = null;
     unset($config);
     unset($table);
     unset($amount);
     return true;
 }
Ejemplo n.º 6
0
 private function loadConfiguration()
 {
     $config = Config::getInstance();
     $driver = $config->get('database.connection.driver');
     switch ($driver) {
         case 'pdo_mysql':
             $conn_params = ['driver' => $driver, 'host ' => $config->get('database.connection.host'), 'user' => $config->get('database.connection.user'), 'password' => $config->get('database.connection.password'), 'dbname' => $config->get('database.connection.db_name'), 'charset' => $config->get('database.connection.charset'), 'port' => $config->get('database.connection.port'), 'collation' => $config->get('database.connection.collation'), 'prefix' => $config->get('database.connection.prefix'), 'unix_socket' => $config->get('database.connection.unix_socket')];
             break;
         case 'pdo_sqlite':
             $conn_params = ['driver' => $driver, 'user' => $config->get('database.connection.user'), 'password' => $config->get('database.connection.password'), 'path' => $config->get('database.connection.path'), 'memory' => $config->get('database.connection.memory')];
             break;
         case 'mysqli':
             $conn_params = ['driver' => $driver, 'host' => $config->get('database.connection.host'), 'port' => $config->get('database.connection.port'), 'user' => $config->get('database.connection.user'), 'password' => $config->get('database.connection.password'), 'db_name' => $config->get('database.connection.db_name'), 'charset' => $config->get('database.connection.charset'), 'prefix' => $config->get('database.connection.prefix'), 'unix_socket' => $config->get('database.connection.unix_socket'), 'driverOptions' => $config->get('database.connection.driverOptions')];
             break;
         case 'pdo_pgsql':
             $conn_params = ['driver' => $driver, 'host' => $config->get('database.connection.host'), 'port' => $config->get('database.connection.port'), 'user' => $config->get('database.connection.user'), 'password' => $config->get('database.connection.password'), 'db_name' => $config->get('database.connection.db_name'), 'charset' => $config->get('database.connection.charset'), 'sslmode' => $config->get('database.connection.sslmode'), 'sslrootcert' => $config->get('database.connection.sslrootcert')];
             break;
         case 'pdo_oci':
         case 'oci8':
             $conn_params = ['driver' => $driver, 'host' => $config->get('database.connection.host'), 'port' => $config->get('database.connection.port'), 'user' => $config->get('database.connection.user'), 'password' => $config->get('database.connection.password'), 'db_name' => $config->get('database.connection.db_name'), 'charset' => $config->get('database.connection.charset'), 'servicename' => $config->get('database.connection.servicename'), 'service' => $config->get('database.connection.service'), 'pooled' => $config->get('database.connection.pooled'), 'instancename' => $config->get('database.connection.instancename')];
             break;
         case 'sqlsrv':
         case 'pdo_sqlsrv':
             $conn_params = ['driver' => $driver, 'host' => $config->get('database.connection.host'), 'port' => $config->get('database.connection.port'), 'user' => $config->get('database.connection.user'), 'password' => $config->get('database.connection.password'), 'db_name' => $config->get('database.connection.db_name')];
             break;
         case 'sqlanywhere':
             $conn_params = ['driver' => $driver, 'host' => $config->get('database.connection.host'), 'port' => $config->get('database.connection.port'), 'user' => $config->get('database.connection.user'), 'password' => $config->get('database.connection.password'), 'db_name' => $config->get('database.connection.db_name'), 'server' => $config->get('database.connection.server'), 'persistent' => $config->get('database.connection.persistent')];
             break;
         default:
             throw new \Exception("Erro na configuração do banco de dados, verifique o arquivo Config\\database.php");
     }
     return $conn_params;
 }
Ejemplo n.º 7
0
 /**
  * Inicializa a aplicação.
  *
  * @throws \Exception
  */
 public function run()
 {
     //apenas para inicializar
     Config::getInstance();
     $application = new Application();
     $commands = [];
     /* Carregando os comandos internos */
     $anna_commands = __DIR__ . DS . 'Commands' . DS;
     $anna_commands = $this->loadAppCommands($anna_commands);
     /* Carregandos os comandos criados pelos desenvolvedores */
     $app_commands = SYS_ROOT . 'App' . DS . 'Console' . DS;
     $app_commands = $this->loadAppCommands($app_commands);
     /* Registra todos os comandos encontrados */
     foreach ($app_commands as $cmd) {
         $commands[] = new $cmd();
     }
     foreach ($anna_commands as $cmd) {
         $class = new \ReflectionClass($cmd);
         if (!$class->isAbstract()) {
             $commands[] = new $cmd();
         }
     }
     $application->addCommands($commands);
     $application->run();
 }
Ejemplo n.º 8
0
 /**
  * do the thing here.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $driver = new DoctrineAdapter();
     $driver->init();
     $em = $driver->getManager();
     $schema = new SchemaTool($em);
     $models = [];
     $model_name = $input->getArgument('model_name');
     $full_name = Config::getInstance()->get('root-namespace') . '\\Models' . '\\' . $model_name . 'Model';
     $schemaManager = $em->getConnection()->getSchemaManager();
     try {
         $metadata = $em->getClassMetadata($full_name);
         $table_name = $metadata->getTableName();
         if ($schemaManager->tablesExist([$table_name]) == true) {
             $models[] = $metadata;
         }
         if (count($models) > 0) {
             $schema->dropSchema($models);
         } else {
             $output->writeln('O model ' . $full_name . ' nao esta registrado no banco de dados.');
         }
     } catch (\Doctrine\ORM\Mapping\MappingException $e) {
         $output->writeln('Erro encontrado:');
         $output->writeln($e->getMessage());
         return;
     }
     $output->writeln('Tabela ' . $table_name . ' removida com sucesso.');
 }
Ejemplo n.º 9
0
 /**
  * Inicializa o manager do adaptador registrado nas configurações.
  */
 public function init()
 {
     $adapter_name = Config::getInstance()->get('database.adapter');
     $adapter = new $adapter_name();
     $adapter->init();
     $this->manager = $adapter->getManager();
 }
Ejemplo n.º 10
0
 public function __construct()
 {
     $config = Config::getInstance()->get('cache');
     if (!$config['cache']) {
         throw new \Exception('Driver de cache não configurado.');
     }
     $this->selectDriver($config);
 }
Ejemplo n.º 11
0
 /**
  * Determina a forma como o registro do erro será feito com base na variável de ambiente setada nas configurações.
  */
 public static function log($ex)
 {
     $env = \Anna\Config::getInstance()->get('app.enviroment');
     if ($env == 'development') {
         self::logDev($ex);
     } else {
         self::logProduction($ex);
     }
 }
Ejemplo n.º 12
0
 /**
  * Caso o comando receba a opção -view este método irá gerar a view index e suas possíveis subpastas.
  */
 private function generateView($class_name)
 {
     $view_folder = strtolower($class_name);
     $filename = Config::getInstance()->get('view.view-engine') == 'blade' ? 'index.blade.php' : 'index.php';
     $path = SYS_ROOT . 'App' . DS . 'Views' . DS . $view_folder;
     if (!is_dir($path)) {
         if (!mkdir($path)) {
             return false;
         }
     }
     $path .= DS . $filename;
     $hand = fopen($path, 'a+');
     fwrite($hand, '<div>Olá mundo!</div>');
     fclose($hand);
 }
Ejemplo n.º 13
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $cmd_name = $input->getArgument('name');
     $cmd_description = $input->hasArgument('description') ? $input->getArgument('description') : '';
     $class_name = nameToClassName($cmd_name);
     $dev_name = Config::getInstance()->get('app.developer');
     $data = date('d/m/Y');
     $root_ns = Config::getInstance()->get('root-namespace');
     $params = ['command_class_name' => $class_name, 'dev_name' => $dev_name, 'data_atual' => $data, 'command_name' => $cmd_name, 'command_description' => $cmd_description, 'root_ns' => $root_ns];
     $template = TemplateHelper::getInstance()->render('command_template', $params);
     $cmd_file_path = SYS_ROOT . 'App' . DS . 'Console' . DS . $class_name . 'Command.php';
     $hand = fopen($cmd_file_path, 'a+');
     fwrite($hand, $template);
     fclose($hand);
     $output->writeln('Comando ' . $class_name . 'Command criado com sucesso.');
 }
Ejemplo n.º 14
0
 private function loadConfiguration()
 {
     $config = Config::getInstance();
     $driver = $config->get('database.connection.driver');
     $conn_params = ['driver' => $driver, 'host' => $config->get('database.connection.host'), 'user' => $config->get('database.connection.user'), 'password' => $config->get('database.connection.password'), 'dbname' => $config->get('database.connection.db_name'), 'charset' => $config->get('database.connection.charset'), 'port' => $config->get('database.connection.port')];
     switch ($driver) {
         case 'pdo_mysql':
             $conn_params['collation'] = $config->get('database.connection.collation');
             $conn_params['prefix'] = $config->get('database.connection.prefix');
             $conn_params['unix_socket'] = $config->get('database.connection.unix_socket');
             break;
         case 'pdo_pgsql':
             $conn_params['sslmode'] = $config->get('database.connection.sslmode');
             $conn_params['sslrootcert'] = $config->get('database.connection.sslrootcert');
             break;
         default:
             throw new \Exception('Erro na configuração do banco de dados, verifique o arquivo Config\\database.php');
     }
     return $conn_params;
 }
Ejemplo n.º 15
0
 /**
  * Executa o comando.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $parts = explode('\\', $name);
     $class_name = end($parts);
     $folder_name = nameToFolderName($name, 'Watchers');
     $root_ns = Config::getInstance()->get('root-namespace');
     $tmp_name_folder = str_replace('/', '\\', $folder_name);
     $params = ['watcher_name' => $class_name, 'dev_name' => Config::getInstance()->get('app.developer'), 'data' => date('d/m/Y'), 'namespace' => $root_ns . '\\Watchers' . $tmp_name_folder];
     $template = TemplateHelper::getInstance()->render('watcher_template', $params);
     $cmd_file_path = SYS_ROOT . 'App' . DS . 'Watchers' . $folder_name . DS . $class_name . 'Watcher.php';
     if (is_file($cmd_file_path)) {
         $output->writeln('O watcher ' . $class_name . 'Watcher ja existe.');
         return true;
     }
     $hand = fopen($cmd_file_path, 'w+');
     fwrite($hand, $template);
     fclose($hand);
     $output->writeln('Watcher ' . $class_name . 'Watcher criado com sucesso.');
 }
Ejemplo n.º 16
0
 public function __construct()
 {
     $config = Config::getInstance();
     $this->addDefaultParams();
     $view_engine = $config->get('view.view-engine');
     $view_folder = SYS_ROOT . $config->get('view.view-folder');
     $view_cache = $config->get('view.cache-folder');
     $paths = new \SplPriorityQueue();
     $paths->insert($view_folder, 1);
     switch ($view_engine) {
         case 'blade':
             $this->renderer = new BladeRenderer($paths, ['cache_path' => $view_cache]);
             break;
         case 'twig':
             $this->renderer = new TwigRenderer($paths);
             break;
         case 'mustache':
             $this->renderer = new MustacheRenderer($paths);
             break;
         default:
             $this->renderer = new BladeRenderer($paths, $view_cache);
             break;
     }
 }
Ejemplo n.º 17
0
 /**
  * Efetua a leitura do arquivo de script SQL.
  *
  * @param $fileScript
  *
  * @throws \DatabaseException
  *
  * @return mixed
  */
 private function getScript($fileScript)
 {
     $file = Config::getInstance()->get('database.queries_folder') . DS . $fileScript . '.php';
     if (!is_file($file)) {
         throw new \DatabaseException("Arquivo de query [{$fileScript}] não encontrado");
     }
     return include $file;
 }
Ejemplo n.º 18
0
 /**
  * Remove o registro no banco de dados referente ao nome do modelo recebido como parâmetro
  * Caso as opções de soft delete estejam configuradas o campo buscará por a data atual no campo informado
  * como delflag nas configurações do aplicativo.
  *
  * @param int $id valor da chave primária do registro
  *
  * @return false|null
  */
 public function remove($id)
 {
     $modelname = get_class($this->model);
     $metadata = $this->manager->getClassMetadata($modelname);
     $table_name = $metadata->getTableName();
     $primary_key = $metadata->getSingleIdentifierFieldName();
     $this->model = $this->search([$primary_key => $id], true);
     if (!$this->model instanceof Model) {
         Error::log(new \Exception('Não foi encontrado registro na tabela: ' . $table_name));
         return false;
     }
     if (Config::getInstance()->get('database.softdelete')) {
         $delflag = Config::getInstance()->get('database.delflag');
         $bin_field = $delflag;
         $this->model->{$bin_field} = new \Datetime('now');
         try {
             $this->manager->merge($this->model);
             $this->manager->flush();
         } catch (\Exception $e) {
             Error::log($e);
             return false;
         }
     } else {
         try {
             $this->manager->remove($this->model);
             $this->manager->flush();
         } catch (\Exception $e) {
             Error::log($e);
             return false;
         }
     }
 }
Ejemplo n.º 19
0
 public function __construct()
 {
     $this->collection = new RouteCollection();
     $this->collection->setHost(Config::getInstance()->get('app.url'));
     $this->addDefaultsWildCards();
 }
Ejemplo n.º 20
0
 /**
  * Efetua algumas configurações avançadas do sistema.
  */
 private function config()
 {
     Config::getInstance()->set('ANNA_PATH', __DIR__ . DS);
     if (is_callable('uncaughtExceptionHandler')) {
         set_exception_handler('uncaughtExceptionHandler');
     }
     // Implementando o Dependence Injection automatizado
     $di_builder = new ContainerBuilder();
     $di_builder->useAnnotations(true);
     $this->di = $di_builder->build();
 }
Ejemplo n.º 21
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = Config::getInstance()->get('app.developer');
     $text = 'Ola ' . $name . ', estou na versao 1.20';
     $output->writeln($text);
 }
Ejemplo n.º 22
0
/**
 * Gera uma url completa com base nos parametros recebidos.
 *
 * @param string $string
 *
 * @return string
 */
function path($string)
{
    $url = \Anna\Config::getInstance()->get('app.url') . $string;
    return $url;
}