function __construct(Command $command, $package_name = '', $packages_directory = '', $zip = false, $hash = false, $crypt = false) { $this->save_src = $packages_directory == '' ? false : true; if ($crypt) { $command->setCryptMode(Command::CRYPT_MD5); } if ($hash) { $command->setHashMode(Command::HASH_MD5); } if ($zip) { $command->setZipMode(Command::ZIP_MD5); } $this->command = $command; if ($packages_directory == '') { $this->keep_backup = false; $packages_directory = sys_get_temp_dir() . '/' . str_replace(' ', '', microtime(true)); } $this->directory = $packages_directory; if (!is_dir($this->directory)) { if (!mkdir($this->directory . ($this->save_src ? '/ftp' : ''), 0777, true)) { throw new \Exception('Package directory can\'t be created.'); } } if ($this->save_src && !is_dir($this->directory . '/src')) { if (!mkdir($this->directory . '/src', 0777, true)) { throw new \Exception('Package\'s sources directory can\'t be created.'); } } if ($package_name == '') { $this->name = date('maileva_YmdHis'); } elseif (!preg_match('/^[a-zA-Z0-9_\\-]*$/', $package_name)) { throw new \Exception('Package name is invalid.'); } else { $this->name = $package_name; } }