/**
  * @param       $config
  * @param array $options
  *
  * @return MWP_Backup_MysqlDump_MysqlDump
  * @throws InvalidArgumentException
  */
 public static function make($config, array $options = array(), MWP_Backup_Writer_WriterInterface $writer = null)
 {
     // Determine which dumping strategy is to be used
     // Check if user is trying to force a particular method
     $forcedMethod = MWP_Backup_ArrayHelper::getKey($options, 'force_method');
     if ($forcedMethod) {
         switch ($forcedMethod) {
             case 'mysqldump':
                 $strategy = new MWP_Backup_MysqlDump_ShellDump($config, $options, $writer);
                 break;
             case 'sequential':
                 $strategy = new MWP_Backup_MysqlDump_QuerySequenceDump($config, $options, $writer);
                 break;
             default:
                 throw new InvalidArgumentException('Trying to force a non existing backup method');
                 break;
         }
     } else {
         // Not forced, choose the best method
         $strategy = new MWP_Backup_MysqlDump_ShellDump($config, $options, $writer);
         if ($config instanceof PDO || !self::isShellExecAvailable() || !$strategy->isMysqldumpAvailable()) {
             $strategy = new MWP_Backup_MysqlDump_QuerySequenceDump($config, $options, $writer);
         }
     }
     return $strategy;
 }
 /**
  * Creates the database dump at a given path
  *
  * @param       $config
  * @param array $options
  *
  * @return MWP_Backup_MysqlDump_MysqlDump
  */
 public static function dump($config, array $options = array())
 {
     @set_time_limit(0);
     $writer = MWP_Backup_Writer_WriterFactory::make(MWP_Backup_ArrayHelper::getKey($options, 'save_path'), MWP_Backup_ArrayHelper::getKey($options, 'compression_method'));
     $dumper = MWP_Backup_MysqlDump_DumpFactory::make($config, $options, $writer);
     $dumper->dumpToFile();
 }
 /**
  * @inherit
  */
 public function createStream()
 {
     $stream = new MWP_Stream_Append();
     $stream->addStream(MWP_Stream_Stream::factory("\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n/*!40101 SET NAMES utf8 */;\n/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n/*!40103 SET TIME_ZONE='+00:00' */;\n/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n\n"));
     $allTables = MWP_Backup_ArrayHelper::arrayColumn($this->getConnection()->query('SHOW TABLES')->fetchAll());
     $tables = array_intersect($allTables, $this->options->getTables() ? $this->options->getTables() : $allTables);
     foreach ($tables as $tableName) {
         $stream->addStream(new MWP_Stream_Callable(array($this, 'streamCreateTable'), array($tableName)));
     }
     $stream->addStream(MWP_Stream_Stream::factory("\n/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n"));
     return $stream;
 }