Primary function, triggers dumping.

@param string $filename  Name of file to write sql dump to
@return null
@throws \Exception
489359
public function start($filename = '')
    {
        // Output file can be redefined here
        if (!empty($filename)) {
            $this->fileName = $filename;
        }

        // Connect to database
        $this->connect();

        // Create output file
        $this->compressManager->open($this->fileName);

        // Write some basic info to output file
        $this->compressManager->write($this->getDumpFileHeader());

        // Store server settings and use sanner defaults to dump
        $this->compressManager->write(
            $this->typeAdapter->backup_parameters()
        );

        if ($this->dumpSettings['databases']) {
            $this->compressManager->write(
                $this->typeAdapter->getDatabaseHeader($this->dbName)
            );
            if ($this->dumpSettings['add-drop-database']) {
                $this->compressManager->write(
                    $this->typeAdapter->add_drop_database($this->dbName)
                );
            }
        }

        // Get table, view, trigger, procedures and events structures from
        // database.
        $this->getDatabaseStructureTables();
        $this->getDatabaseStructureViews();
        $this->getDatabaseStructureTriggers();
        $this->getDatabaseStructureProcedures();
        $this->getDatabaseStructureEvents();

        if ($this->dumpSettings['databases']) {
            $this->compressManager->write(
                $this->typeAdapter->databases($this->dbName)
            );
        }

        // If there still are some tables/views in include-tables array,
        // that means that some tables or views weren't found.
        // Give proper error and exit.
        // This check will be removed once include-tables supports regexps.
        if (0 < count($this->dumpSettings['include-tables'])) {
            $name = implode(",", $this->dumpSettings['include-tables']);
            throw new Exception("Table (".$name.") not found in database");
        }

        $this->exportTables();
        $this->exportTriggers();
        $this->exportViews();
        $this->exportProcedures();
        $this->exportEvents();

        // Restore saved parameters.
        $this->compressManager->write(
            $this->typeAdapter->restore_parameters()
        );
        // Write some stats to output file.
        $this->compressManager->write($this->getDumpFileFooter());
        // Close output file.
        $this->compressManager->close();

        return;
    }
1369352
function Save($filename)
    {
        $result = @$this->domDoc->save($filename);
        
        if ($result === false)
            throw new \Exception("RSS Feed saviing to '$filename' failed");
        
        return $result;
    }
1344846
public function saveExport($source, $filename) {
    $this->deleteExport($filename);

    if (!self::dirReady("{$this->path}/exports")) {
      throw new Exception("Unable to create directory for H5P export file.");
    }

    if (!copy($source, "{$this->path}/exports/{$filename}")) {
      throw new Exception("Unable to save H5P export file.");
    }
  }
350983
public function dump()
    {
        if (empty($this->files)) {
            return;
        }

        $buffer = <<<'PHP'
<?php

$runonce = function(array $files, $delete = false) {
    foreach ($files as $file) {
        try {
            include $file;
        } catch (\Exception $e) {}

        $relpath = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $file);

        if ($delete && !unlink($file)) {
            throw new \Exception(
                'The file ' . $relpath . ' cannot be deleted. ' .
                'Please remove the file manually and correct the file permission settings on your server.'
            );
        }
    }
};

PHP;

        if (file_exists($this->targetFile)) {
            if (!is_writable($this->targetFile) || !is_file($this->targetFile)) {
                throw new \RuntimeException(
                    sprintf('Runonce file "%s" exists but is not writable.', $this->targetFile)
                );
            }

            $current = str_replace('.php', '_'.substr(md5(mt_rand()), 0, 8).'.php', $this->targetFile);
            $this->filesystem->rename($this->targetFile, $current);

            $buffer .= "\n\$runonce(array('" . $current . "'), true);\n";
        }

        $buffer .= "\n\$runonce(" . var_export(array_unique($this->files), true) . ");\n";

        $this->filesystem->ensureDirectoryExists(dirname($this->targetFile));

        if (false === file_put_contents($this->targetFile, $buffer)) {
            throw new \RuntimeException(sprintf('Could not write runonce file to "%s"', $this->targetFile));
        }

        $this->files = [];
    }
842584
public function download($filename) {
    if(!empty($this->pdf->getError())) {
      throw new Exception('Could not create PDF: ' . $this->pdf->getError());
    } else {
      $filename = rtrim(File::create()->setName($filename), '.pdf') . '.pdf';
      $this->pdf->send($filename);
    }
  }
502217
public function getSqlFileByName($fileName)
    {
        $sqlFinder = $this->getFinder();

        $files = $sqlFinder->files()
            ->in($this->sqlFilesDir)
            ->name($fileName)
        ;

        if ($files->count() !== 1) {
            throw new RuntimeException('cannot find File:' . $fileName);
        }

        foreach ($files as $file){
            return $file;
        }
    }
904675
public function write(string $fileName) : void
    {
        file_put_contents(
            $fileName,
            // str_replace here is to convert empty arrays into empty JS objects, which is expected by
            // codecov.io. Owner of the service said he was going to patch it, haven't tested since
            // Note: Can't use JSON_FORCE_OBJECT here as we **do** want arrays for the 'b' structure
            // which FORCE_OBJECT turns into objects, breaking at least the Istanbul coverage reporter
            str_replace('[]', '{}', (string) json_encode($this->coverage, JSON_UNESCAPED_SLASHES))
        );
    }
515090
public static function detectByFilename($filename)
    {
        $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));

        return empty($extension) ? 'text/plain' : static::detectByFileExtension($extension);
    }
202327
public function filename($filename = null)
    {
        if ($filename === null) {
            return $this->_filename;
        }
        $this->_filename = $filename;
    }
962587
public function save(File $file, $filename = null)
    {
        if ($filename !== null) {
            $file->setFilename($filename);
        }

        $this->filesystem->write($file);
    }
878116
public function handleFile(string $fileName): void
	{
		$file = $this->getFileInfo($fileName);
		if (strpos($file->type, 'image') !== false) {
			$response = new FileResponse($this->getFullPath($file->name), $file->name, $file->type, false);
			$this->presenter->sendResponse($response);
		} else {
			exit;
		}
	}
1249132
function columnIsNull($fieldname, $source)
    {
        $column = self::describeColumn($fieldname, $source);
        if ( ! $column ) throw new \Exception("Could not find $fieldname");
        return U::get($column, "Null") == "YES";
    }
1306453
private function _processFile($filename) {
		if ($this->debug) {
			echo "Processing File : " . $filename . PHP_EOL;
		}

		// Reset the tokenizer
		$this->tokenizer->reset();

		// Reset the state of the attributes
		$this->_resetValues();

		// Try to detect the type of file in a MVC framework
		if (stripos($filename, 'view') !== false || stripos($filename, 'layouts') !== false) {
			$this->_isView = true;
		} elseif (stripos($filename, 'model') !== false) {
			$this->_isModel = true;
		} elseif (stripos($filename, 'controller') !== false) {
			$this->_isController = true;
		} elseif (stripos($filename, 'class') !== false) {
			// simple simple data objects
			$this->_isClass = true;
		}

		// Store the file name
		$this->_currentFilename = $filename;

		// By defaut the package name is based on the file name
		$this->_packageName = $this->_extractPackageName($filename);

		// Tokenize the file
		$this->tokenizer->tokenize($filename);

		// Empty PHP file
		if ($this->tokenizer->getTokenNumber() === 0) {
			$this->_checkEmptyFile($filename);
			return; // end the scan
		}

		// Go to the first token
		$token = $this->tokenizer->getCurrentToken();

		// File start
		$this->_processFileStart();

		// Run through every token of the file
		while ($token !== false) {
			// Process the token
			$this->_processToken($token);

			$this->lineNumber = $token->line;

			// Go to the next token
			$token = $this->tokenizer->getNextToken();
		}

		// Test the last token of the file
		if ($this->_isActive('noFileCloseTag')) {
			if ($this->tokenizer->checkPreviousToken(T_CLOSE_TAG)) {
				// Closing tag is not recommended since PHP 5.0
				$this->_writeError('noFileCloseTag', $this->_getMessage('END_FILE_CLOSE_TAG'));
			}
		}

		// Inner HTML is OK for views but not for other classes (controllers, models, ...)
		if ($this->_isActive('noFileFinishHTML') && !$this->_isView) {
			if ($this->tokenizer->checkPreviousToken(T_INLINE_HTML)) {
				$this->_writeError('noFileFinishHTML', $this->_getMessage('END_FILE_INLINE_HTML'));
			}
		}

		// Check for unused private functions
		$this->_checkUnusedPrivateFunctions();

		// Check for unused variables
		$this->_checkUnusedVariables();

		if ($this->_ncssFileClasses > 0 || $this->_ncssFileInterfaces > 0) {
			// Test the file name, only if it contains a class or interface
			$this->_checkFileNaming();
		}

		// Write the count of lines for this file
		if ($this->_lineCountReporter !== null) {
			$this->_lineCountReporter->writeFileCount($this->_packageName, $this->_ncssFileClasses, $this->_ncssFileInterfaces, $this->_ncssFileFunctions, $this->_ncssFileLinesOfCode, $this->_ncssFilePhpdoc, $this->_ncssFileLinesPhpdoc, $this->_ncssFileSingleComment, $this->_ncssFileMultiComment);
		}

		// Reset the suppression warnings
		$this->_fileSuppressWarnings = array();
		$this->_classSuppressWarnings = array();
		$this->_interfaceSuppressWarnings = array();
	}
612309
public static function import($filename) {
        $configFile = BASE_DIR . '/config/' . $filename . '.php';

        if (!file_exists($configFile)) {
            throw new \Exception(ExceptionMessages::CONFIG_FILE_NOT_FOUND);
        }
        
        $allConfigs = self::getAll();
        foreach ($allConfigs as $key => $config) {
            if($filename == $key) { 
                throw new \Exception(ExceptionMessages::CONFIG_COLLISION);
            }
        }

        self::$configs[$filename] = require_once BASE_DIR . '/config/' . $filename . '.php';
    }
1009119
public function parseFile($filename)
    {
        // Run the fileEval the string, if it throws an exception, rethrow it
        try {
            $data = require $filename;
        } catch (Exception $exception) {
            throw new ParseException(
                [
                    'message'   => 'PHP file threw an exception',
                    'exception' => $exception,
                ]
            );
        }

        // Complete parsing
        return (array)$this->parse($data, $filename);
    }
1109283
public function output(string $filename = null): int
    {
        if (null !== $filename) {
            $this->sendHeaders($filename);
        }
        $input_bom = $this->getInputBOM();
        $this->document->rewind();
        $this->document->fseek(strlen($input_bom));
        echo $this->output_bom;

        return strlen($this->output_bom) + $this->document->fpassthru();
    }
403283
private function exec(callable $fn)
    {
        ob_start();

        try {
            $returnData = call_user_func_array($fn, $this->args);
        } catch (Exception $e) {
            ob_end_clean();
            throw $e;
        }

        $outputBuffer = ob_get_clean();

        foreach ($this->outputTo as $filename) {
            if ($outputBuffer) {
                file_put_contents($filename, $outputBuffer, $this->outputMode === 'a' ? FILE_APPEND : 0);
            }

            if ($returnData) {
                file_put_contents($filename, $returnData, FILE_APPEND);
            }
        }

        $this->removeLockFile();

        return $outputBuffer . (is_string($returnData) ? $returnData : '');
    }