Create an SQL backup file for the current database's data

@param array $exclude
@return string
971551
public function backupData($exclude=[]): string
	{
		$tables = $this->getDriver()->getTables();

		// Filter out the tables you don't want
		if( ! empty($exclude))
		{
			$tables = array_diff($tables, $exclude);
		}

		$outputSql = '';

		// Select the rows from each Table
		foreach($tables as $t)
		{
			$sql = "SELECT * FROM `{$t}`";
			$res = $this->getDriver()->query($sql);
			$rows = $res->fetchAll(PDO::FETCH_ASSOC);

			// Skip empty tables
			if (count($rows) < 1)
			{
				continue;
			}

			// Nab the column names by getting the keys of the first row
			$columns = @array_keys($rows[0]);

			$insertRows = [];

			// Create the insert statements
			foreach($rows as $row)
			{
				$row = array_values($row);

				// Workaround for Quercus
				foreach($row as &$r)
				{
					$r = $this->getDriver()->quote($r);
				}
				$row = array_map('trim', $row);

				$rowString = 'INSERT INTO `'.trim($t).'` (`'.implode('`,`', $columns).'`) VALUES ('.implode(',', $row).');';

				$row = NULL;

				$insertRows[] = $rowString;
			}

			$outputSql .= "\n\n".implode("\n", $insertRows)."\n";
		}

		return $outputSql;
	}
170742
public function filter($keys, $exclude = false): SplArray
    {
        if (is_string($keys)) {
            $keys = explode(',', $keys);
        }
        $new = array();
        foreach ($this->getArrayCopy() as $name => $value) {
            if (!$exclude) {
                in_array($name, $keys) ? $new[$name] = $value : null;
            } else {
                in_array($name, $keys) ? null : $new[$name] = $value;
            }
        }
        return new SplArray($new);
    }
950727
public function getUpdateSql(array $sql)
    {
        $update = 'UPDATE';
        if (!empty($this->priority)) {
            $update .= ' ' . $this->priority;
        }
        if (!empty($this->ignore)) {
            $update .= ' ' . $this->ignore;
        }
        $sql[] = $update . ' ' . $this->quoter->quoteName($this->table);

        return $sql;
    }
385294
public function fields(array $fields=array(), $exclude=false) {
		$addInc=[];
		if ($fields)
			// collect & set restricted fields for related mappers
			foreach($fields as $i=>$val)
				if(is_int(strpos($val,'.'))) {
					list($key, $relField) = explode('.',$val,2);
					$this->relWhitelist[$key][(int)$exclude][] = $relField;
					unset($fields[$i]);
					$addInc[] = $key;
				}
		$fields = array_unique($fields);
		$schema = $this->whitelist ?: $this->mapper->fields();
		if (!$schema && $this->dbsType != 'sql' && $this->dry()) {
			$this->load();
			$schema = $this->mapper->fields();
			$this->reset();
		}
		// include relation linkage fields to $fields (if $fields is a whitelist)
		if (!$exclude && !empty($fields) && !empty($addInc))
			$fields=array_unique(array_merge($fields,$addInc));
		// include relation linkage fields to existing whitelist (if $fields is a blacklist or there's nothing else to whitelist)
		elseif (!empty($addInc) && $this->whitelist)
			$this->whitelist=array_unique(array_merge($this->whitelist,$addInc));
		// initially merge configured fields into schema (add virtual/rel fields to schema)
		if (!$this->whitelist && $this->fieldConf)
			$schema=array_unique(array_merge($schema,
				array_keys($this->fieldConf),array_keys($this->vFields?:[])));
		// skip if there's nothing to set for own model
		if (!$fields || empty($fields))
			return $schema;
		elseif ($exclude) {
			$this->whitelist=array_diff($schema,$fields);
		} else
			$this->whitelist=$fields;
		$id=$this->dbsType=='sql'?$this->primary:'_id';
		if (!in_array($id,$this->whitelist))
			$this->whitelist[]=$id;
		$this->applyWhitelist();
		return $this->whitelist;
	}
460922
public static function getPathSegments(array $exclude = array()): array
    {
        $exclude = array_merge($exclude, array(
            INDEX_FILE,
            CHAR_SPACE,
            ''
        ));
        
        $exclude[] = "";
        
        $requestUri = self::getServerVariable('REQUEST_URI', '');
        $requestUri = substr($requestUri, 0, (strpos($requestUri, "?") !== false) ? strpos($requestUri, "?") : strlen($requestUri));
        $requestUri = preg_replace("#/+#", "/", $requestUri);
        
        $pathInfo = explode(CHAR_SLASH, $requestUri);
        return array_values(array_diff(array_merge($pathInfo, $exclude), $exclude));
    }
626821
public function backupDb($filename, $tables = '*')
    {
        $data = [];

        // get all of the tables
        if ($tables == '*') {
            $tables = array();
            $result = $this->connection->prepare('SHOW TABLES');
            $result->execute();
            while ($row = $result->fetch(PDO::FETCH_NUM)) {
                $tables[] = $row[0];
            }
        } else {
            $tables = \is_array($tables) ? $tables : explode(',', $tables);
        }

        $data[] = "\n";
        $data[] = 'SET foreign_key_checks=0;';
        $data[] = "\n\n";

        foreach ($tables as $table) {
            if (!preg_match("/^[\w_\-]+$/", $table)) {
                Tlog::getInstance()->alert(
                    sprintf(
                        "Attempt to backup the db with this invalid table name: '%s'",
                        $table
                    )
                );

                continue;
            }

            $result = $this->execute('SELECT * FROM `' . $table . '`');

            $fieldCount = $result->columnCount();

            $data[] = 'DROP TABLE `' . $table . '`;';

            $resultStruct = $this->execute('SHOW CREATE TABLE `' . $table . '`');

            $rowStruct = $resultStruct->fetch(PDO::FETCH_NUM);

            $data[] = "\n\n";
            $data[] = $rowStruct[1];
            $data[] = ";\n\n";

            for ($i = 0; $i < $fieldCount; $i++) {
                while ($row = $result->fetch(PDO::FETCH_NUM)) {
                    $data[] = 'INSERT INTO `' . $table . '` VALUES(';
                    for ($j = 0; $j < $fieldCount; $j++) {
                        $row[$j] = addslashes($row[$j]);
                        $row[$j] = str_replace("\n", "\\n", $row[$j]);
                        if (isset($row[$j])) {
                            $data[] = '"' . $row[$j] . '"';
                        } else {
                            $data[] = '""';
                        }
                        if ($j < ($fieldCount - 1)) {
                            $data[] = ',';
                        }
                    }
                    $data[] = ");\n";
                }
            }
            $data[] = "\n\n\n";
        }

        $data[] = 'SET foreign_key_checks=1;';

        //save filename
        $this->writeFilename($filename, $data);
    }
597056
public function getTableColumns( $table, array $exclude = [ ] )
    {
        $query = "pragma table_info( $table )";

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

        // grab all columns
        $columns = [ ];

        foreach ( $result as $res )
        {
            foreach ( $res as $key => $value )
            {
                if ( 'name' === $key && !in_array( $value, $exclude ) )
                {
                    $null = ' NULL';

                    if ( TRUE === ( bool ) $res[ 'notnull' ] )
                    {
                        $null = ' NOT NULL';
                    }

                    $columns[ $value ] = $res[ 'type' ] . $null;
                }
            }
        }

        return $columns;
    }
731132
public function serializeURL($excludeFragmentFlag = false)
    {
        $output = $this->scheme . ':';
        if (!is_null($this->host)) {
            $output .= '//';
            if ($this->isIncludingCredentials()) {
                $output .= $this->username;
                if ($this->password !== '') {
                    $output .= ':' . $this->password;
                }
                $output .= '@';
            }
            $output .= HostProcessing::serializeHost($this->host);
            if (!is_null($this->port)) {
                $output .= ':' . $this->port;
            }
        } elseif (is_null($this->host) && $this->scheme === 'file') {
            $output .= '//';
        }
        $output .= $this->cannotBeABaseURLFlag ? $this->path[0] :  '/' . implode('/', $this->path);
        if (!is_null($this->query)) {
            $output .= '?' . $this->query;
        }
        if (!$excludeFragmentFlag && !is_null($this->fragment)) {
            $output .= '#' . $this->fragment;
        }
        return $output;
    }
1010609
@Nonnull
  public final ESuccess createBackup (@Nonnull final File fDestFile)
  {
    ValueEnforcer.notNull (fDestFile, "DestFile");

    LOGGER.info ("Backing up database '" + getDatabaseName () + "' to " + fDestFile);
    final DBExecutor aExecutor = new DBExecutor (this);
    return aExecutor.executeStatement ("BACKUP TO '" + fDestFile.getAbsolutePath () + "'");
  }
1141114
public function listAllDirectories($exclude = [])
    {
        $fullPath = $this->getMediaPath('/');

        $folders = $this->getStorageDisk()->allDirectories($fullPath);

        $folders = array_unique($folders, SORT_LOCALE_STRING);

        $result = [];

        foreach ($folders as $folder) {
            $folder = $this->getMediaRelativePath($folder);
            if (!strlen($folder)) {
                $folder = '/';
            }

            if (Str::startsWith($folder, $exclude)) {
                continue;
            }

            $result[] = $folder;
        }

        if (!in_array('/', $result)) {
            array_unshift($result, '/');
        }

        return $result;
    }
813210
public function dump()
	{
		$tables   = App::get('db')->getTableList();
		$prefix   = App::get('db')->getPrefix();
		$excludes = [];
		$now      = new Date;
		$exclude  = '';
		$includes = (array)$this->arguments->getOpt('include-table', []);

		if (!$this->arguments->getOpt('all-tables'))
		{
			$this->output->addLine('Dumping database with all prefixed tables included');
			foreach ($tables as $table)
			{
				if (strpos($table, $prefix) !== 0 && !in_array(str_replace('#__', $prefix, $table), $includes))
				{
					$excludes[] = Config::get('db') . '.' . $table;
				}
				elseif (in_array(str_replace('#__', $prefix, $table), $includes))
				{
					$this->output->addLine('Also including `' . $table . '`');
				}
			}

			// Build exclude list string
			$exclude = '--ignore-table=' . implode(' --ignore-table=', $excludes);
		}
		else
		{
			$this->output->addLine('Dumping database with all tables included');
		}

		// Add save location option

		$home     = getenv('HOME');
		$hostname = gethostname();
		$filename = tempnam($home, "{$hostname}.mysql.dump." . $now->format('Y.m.d') . ".sql.");

		// Build command
		$cmd = "mysqldump -u " . Config::get('user') . " -p'" . Config::get('password') . "' " . Config::get('db') . " --routines {$exclude} > {$filename}";

		exec($cmd);

		// Print out location of file
		$this->output->addLine('File saved to: ' . $filename, 'success');
	}
1348636
public function parseFiles($files, $exclude = false)
    {
        $parser = $this->getParser();
        $result = [];
        foreach ($files as $path) {
            if ($exclude && preg_match($exclude, $path)) {
                continue;
            }
            try {
                $code = file_get_contents($path);
                $stmts = $parser->parse($code);
                $result[$path] = new CodeFile($stmts, $path);
            } catch (PhpParserError $e) {
                echo $path, ' Line ', $e->getLine(), ":\n";
                echo 'Parse Error: ', $e->getRawMessage();
                echo "\n";
            }
        }
        $this->_files = $result + $this->_files;
        return $result;
    }
290999
public function fullClean($exclude = [])
    {
        $errors = [];

        try {
            $this->cleanFields($exclude);
        } catch (ValidationError $error) {
            //todo
        }

        try {
            $this->clean();
        } catch (ValidationError $error) {
            //todo
        }
        if (!empty($errors)) {
            throw new ValidationError($errors);
        }
    }
733536
public static function getDbFieldNames(array $exclude = [])
    {
        $fieldNames = [];
        foreach (array_keys(static::$dbProperties) as $propertyName) {
            $fieldNames[] = static::getDbFieldName($propertyName);
        }

        return $exclude ? array_diff($fieldNames, $exclude) : $fieldNames;
    }
705401
public function cleanFields($exclude = [])
    {
        $errors = [];

        /** @var $field Field */
        foreach ($this->getMeta()->getConcreteFields() as $field) {
            if (in_array($field->getName(), $exclude)) {
                continue;
            }
            $value = $this->{$field->getAttrName()};
            // Skip validation for empty fields with blank=True. The developer
            // is responsible for making sure they have a valid value.
            if ($field->formBlank && empty($value)) {
                continue;
            }

            try {
                $this->{$field->getAttrName()} = $field->clean($this, $value);
            } catch (ValidationError $error) {
                $errors[$field->getName()] = $error->getErrorList();
            }
        }

        if (!empty($errors)) {
            throw new ValidationError($errors);
        }
    }
997521
public function getData($table, $max, $exclude = null, $orderBy = null, $direction = 'ASC')
    {
        $result = \DB::connection($this->databaseName)->table($table);

        if (!empty($exclude)) {
            $allColumns = \DB::connection($this->databaseName)->getSchemaBuilder()->getColumnListing($table);
            $result = $result->select(array_diff($allColumns, $exclude));
        }

        if($orderBy) {
            $result = $result->orderBy($orderBy, $direction);
        }

        if ($max) {
            $result = $result->limit($max);
        }

        return $result->get();
    }
771457
protected function excludeNext($key, array $exclude)
  {
    if (array_key_exists($key, $exclude) && is_array($exclude[$key]))
    {
      return $exclude[$key];
    }

    return array();
  }