Adds several options for database connections to the command.

@return void
966342
protected function addDatabaseOptions()
    {
        $this
            ->addOption('database-host', 'H', InputOption::VALUE_REQUIRED, 'Name / IP of the host where the database is running.')
            ->addOption('database-user', 'u', InputOption::VALUE_REQUIRED, 'Username to access the database.')
            ->addOption('database-pass', 'p', InputOption::VALUE_REQUIRED, 'Password to access the database.')
            ->addOption('database-port', 'P', InputOption::VALUE_REQUIRED, 'Port where the database is listen.')
            ->addOption('database-name', 'N', InputOption::VALUE_REQUIRED, 'Name of the database which should be used.');
    }
853622
public static function setConnection()
    {
        $dhost = getenv('DB_HOST');
        $dbase = getenv('DB_BASE');
        $duser = getenv('DB_USER');
        $dpass = getenv('DB_PASS');

        $opt = [
            PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
            PDO::ATTR_EMULATE_PREPARES   => false,
        ];

        try {
            self::$pdo = new PDO("mysql:host=$dhost;dbname=$dbase", $duser, $dpass, $opt);
        } catch (\Exception $exception) {
            var_dump($exception->getMessage());
            exit();
        }
    }
943212
public function cmdSqlDatabase()
    {
        $sql = $this->getParam(0);

        if (empty($sql)) {
            $this->errorAndExit($this->text('Invalid command'));
        }

        $result = $this->db->query($sql);

        if ($this->getParam('fetch')) {
            $result = $result->fetchAll(\PDO::FETCH_ASSOC);
            $this->outputFormat($result);
            $this->outputFormatTableDatabase($result);
        }

        $this->output();
    }
822944
private function tryConnect(): void
    {
        $config = $this->getConfig();

        $pdoConfig = [
          PDO::ATTR_EMULATE_PREPARES => false,
          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
          PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
        ];

        if (isset($config['adapter_options'])) {
            foreach ($config['adapter_options'] as $key => $value) {
                $pdoConfig[$key] = $value;
            }
        }

        if (isset($config['path'])) {
            $path = $config['path'];
            if (substr($path, 0, 8) == 'storage:') {
                $path = Application::getStoragePath(substr($path, 8));
            }
        } else {
            $path = Application::getStoragePath('data/database.sqlite');
        }

        $directory = dirname($path);
        if (!is_dir($directory)) {
            Directory::mkdir($directory, 0755);
        }

        $this->pdo = new PDO('sqlite:' . $path);
        foreach ($pdoConfig as $key => $value) {
            $this->pdo->setAttribute($key, $value);
        }

        // create needed function(s)
        $this->pdo->sqliteCreateFunction('ILIKE', function ($mask, $value) {
            $mask = str_replace(['%', '_'], ['.*?', '.'], preg_quote($mask, '/'));
            $mask = "/^$mask$/ui";
            return preg_match($mask, $value);
        }, 2);
    }
914359
protected function setDbColumns()
    {
        $connection = $this->model()->eloquent()->getConnectionName();

        $this->dbColumns = collect(Schema::connection($connection)->getColumnListing($this->model()->getTable()));
    }
72739
protected function setConnectedRelationOptions()
	{
		$modelTable = $table = $this->model->getTable();
		$toModelTable = $table = $this->toModel->getTable();
		$foreignKey = $this->defaultOptions['foreign_key'];
		$primaryKey = $this->defaultOptions['primary_key'];
		
		if (! $this->db->isFieldExists($toModelTable, $foreignKey)) {
			$question = "Can't find field {$this->text['foreign_key']} in the table {$this->text['to_table']} as {$this->text['foreign_text']} of table {$this->text['table']}, choice one!";
			$this->options['foreign_key'] = $this->command->choice($question, $this->getFields($toModelTable));
		}

		if (! $this->db->isFieldExists($modelTable, $primaryKey)) {
			$question = "Can't find field {$this->text['primary_key']} in the table {$this->text['table']} as {$this->text['primary_text']} of table {$this->text['table']}, choice one!";
			$this->options['primary_key'] = $this->command->choice($question, $this->getFields($modelTable));
		}
	}
1115508
public function configureApplication()
    {
        $config = file_get_contents($this->paths['app'].'/config/config.yml');
        $config = $this->parser->parse($config);

        $this->project_name     = $config['application']['project_name'];
        $this->routeCollection  = $this->bindRouteCollection($this->project_name);

        $this->addDbParams($config['database']['default'], $config['database']['types']);
        $this->createBaseEm($config['application']['environment']);
    }
831668
private function tryConnect(): void
    {
        $config = $this->getConfig();

        $pdoConfig = [
          PDO::ATTR_EMULATE_PREPARES => false,
          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
          PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false,
          PDO::ATTR_PERSISTENT => $config['persistent'] ?? true,
          PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
        ];

        if (isset($config['adapter_options'])) {
            foreach ($config['adapter_options'] as $key => $value) {
                $pdoConfig[$key] = $value;
            }
        }

        $charset = $config['charset'] ?? 'utf8';

        if (!isset($config['socket'])) {
            // not a socket
            $port = $config['port'] ?? 3306;

            $this->pdo = new PDO("mysql:host={$config['host']};port={$port};dbname={$config['database']};charset={$charset}", $config['username'], $config['password'], $pdoConfig);
        } else {
            // the case with unix_socket
            $this->pdo = new PDO("mysql:unix_socket={$config['socket']};dbname={$config['database']};charset={$charset}", $config['username'], $config['password'], $pdoConfig);
        }
    }
672398
public function connect() : void
    {
        $this->logger->info('Connecting to LDAP');
        // Connect to the LDAP server
        $handle = ldap_connect($this->configuration['server'], $this->configuration['port']);

        if (is_resource($handle)) {
            ldap_set_option($handle, LDAP_OPT_PROTOCOL_VERSION, 3);
            ldap_set_option($handle, LDAP_OPT_REFERRALS, 0);
            $this->logger->info('Connected to LDAP');
            $this->handle = $handle;
        } else {
            throw new DatabaseConnectionException('Unable to connect to LDAP');
        }
        $this->logger->debug('Connecting to database engine.');
        $this->bindToServer();
        $this->logger->debug('Connected to database engine.');
        $this->is_connected = true;
    }
267956
public function addListCommands()
    {
        $entity = $this->getController()->getItem();

        if ($entity->authorize('vote')) {
            $this->addCommand('vote');
        }

        if ($entity->authorize('edit')) {
            $this->addCommand('edit', array('layout' => 'form'))
            ->getCommand('edit')
            ->setAttribute('data-action', 'edit');

            $this->addCommand('enable', array('ajax' => true));
        }

        if ($entity->authorize('delete') && $this->getController()->filter != 'leaders') {
            $this->addCommand('delete');
        }
    }
55211
protected function addRelation()
    {
        if ($this->relationType == 'hasAndBelongsToMany')
        {
            $junction = $this->getJunction();

            try
            {
                Validate::table($junction)->exists();
            }
            catch (dbException $e)
            {
                Database::create($junction, [
                    $this->tables['local'] . '_id'   => 'integer',
                    $this->tables['foreign'] . '_id' => 'integer',
                ]);

                $this->insertRelationData($junction, $this->tables['local'], 'hasMany', [
                    'local'   => $this->tables['local'] . '_id',
                    'foreign' => $this->keys['local']
                ]);

                $this->insertRelationData($junction, $this->tables['foreign'], 'hasMany', [
                    'local'   => $this->tables['foreign'] . '_id',
                    'foreign' => $this->keys['foreign']
                ]);
            }
        }
        $this->insertRelationData($this->tables['local'], $this->tables['foreign'], $this->relationType, $this->keys);
    }
1211224
protected static function initConnection()
    {
        $readConfig = new DBConfig();
        self::$conn_list = $readConfig->getAllConnection();
        self::$conn_list['db'] = $readConfig->getDefaultConnection();
        self::$conn_name_list = array_keys(self::$conn_list);
    }
1257071
public function addConstraints()
    {
        if (static::$constraints)
        {
            $this->query->where($this->foreignKey, '=', $this->getParentKey());

            $this->query->whereNotNull($this->foreignKey);

            $this->query->where($this->rootKey, '=', $this->getRootKey());

            $this->query->whereNotNull($this->rootKey);

        }
    }
450157
public function cmdAddDatabase()
    {
        $table = $this->getParam(0);
        $data = $this->getOptions();

        if (empty($table) || empty($data)) {
            $this->errorAndExit($this->text('Invalid command'));
        }

        $this->line($this->db->insert($table, $data));
        $this->output();
    }
707651
public function runSetup()
    {
        if ($this->params->forceIsActive) {
            $this->consoleWriteLineWithIndent('Force mode active! Database will be generated', Color::YELLOW);
            
            $dbParams          = $this->getDbConnectionParams();    
            $dbConnectionCmd   = $this->getDbConnectionCmd();
            $dropDatabaseCmd   = $dbConnectionCmd . ' -e"DROP DATABASE ' . $dbParams['dbname'] . ';"';
            $createDatabaseCmd = $dbConnectionCmd . ' -e"CREATE DATABASE ' . $dbParams['dbname'] . ';"';
            $createSchemaCmd   = 'php bin/doctrine.php orm:schema-tool:create';
            
            $this->consoleWriteWithIndent('Dropping database... ');
            $output = shell_exec($dropDatabaseCmd);
            $this->consoleWriteLine('done!', Color::GREEN);
            
            $this->consoleWriteWithIndent('Creating database... ');
            $output = shell_exec($createDatabaseCmd);
            $this->consoleWriteLine('done!', Color::GREEN);
            
            $this->consoleWriteWithIndent('Creating tables... ');
            $output = shell_exec($createSchemaCmd);
            $this->consoleWriteLine('done!', Color::GREEN);
        } else {
            $this->consoleWriteLineWithIndent('Nothing to do. For database generating please use --force|-f option.', Color::YELLOW);
        }
    }
1338171
public function addListCommands()
    {
        $entity = $this->getController()->getItem();

        if ($entity->authorize('vote')) {
            $this->addCommand('vote');
        }

        if ($entity->authorize('delete')) {
            $this->addCommand('delete');
        }

        if ($entity->authorize('edit')) {
          $this->addCommand('view', AnTranslator::_('LIB-AN-MEDIUM-VIEW'))
               ->getCommand('view')
               ->href(route($entity->getURL()));
        }
    }
720866
protected function configure(): void
    {
        // First command : Test the DB Connexion
        $this->setName($this->command)
            ->setDescription(
                'Generate configuration for the Anonymizer'
            )->setHelp(
                'This command will connect to a DB and extract a list of tables / fields to a yaml file'.PHP_EOL.
                "Usage: neuralyzer <info>{$this->command} -u app -p app -f neuralyzer.yml</info>"
            )->addOption(
                'driver',
                'D',
                InputOption::VALUE_REQUIRED,
                'Driver (check Doctrine documentation to have the list)',
                'pdo_mysql'
            )->addOption(
                'host',
                'H',
                InputOption::VALUE_REQUIRED,
                'Host',
                '127.0.0.1'
            )->addOption(
                'db',
                'd',
                InputOption::VALUE_REQUIRED,
                'Database Name'
            )->addOption(
                'user',
                'u',
                InputOption::VALUE_REQUIRED,
                'User Name',
                get_current_user()
            )->addOption(
                'password',
                'p',
                InputOption::VALUE_REQUIRED,
                "Password (or it'll be prompted)"
            )->addOption(
                'file',
                'f',
                InputOption::VALUE_REQUIRED,
                'File',
                'neuralyzer.yml'
            )->addOption(
                'protect',
                null,
                InputOption::VALUE_NONE,
                'Protect IDs and other fields'
            )->addOption(
                'ignore-table',
                null,
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
                'Table to ignore. Can be repeated'
            )->addOption(
                'ignore-field',
                null,
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
                'Field to ignore. Regexp in the form "table.field". Can be repeated'
            );
    }