Open new file handle.
@throws \Exception
501749
protected function openHandle()
    {
        $fileName = $this->getFileName();

        $this->_handle = fopen($fileName, 'w');

        if (!$this->_handle) {
            throw new \Exception('Cannot open file ' . $fileName);
        }
    }
572870
protected function _open($url)
    {
        set_error_handler(function ($code, $message) {
            $this->_connectionErrors[] = $message;
        });
        try {
            $this->_stream = fopen($url, 'rb', false, $this->_context);
        } finally {
            restore_error_handler();
        }

        if (!$this->_stream || !empty($this->_connectionErrors)) {
            throw new Exception(implode("\n", $this->_connectionErrors));
        }
    }
497752
public static function open($fileName)
    {
        self::checkRequirements();

        if (!file_exists($fileName) || !is_readable($fileName))
            throw new Exception('Could not open file: '.$fileName);

        $type = self::detectArchiveType($fileName);
        if (!self::canOpenType($type)) {
            return null;
        }

        return new self($fileName, $type);
    }
875410
protected function createFile()
    {
        $event = new FileEvent([
            'realPath' => $this->iterator->current(),
            'relativePath' => $this->iterator->getRelativePath()
        ]);

        $this->module->trigger(Module::EVENT_PROCESS_FILE, $event);

        $this->file = $event;
    }
1300366
public function beginNewFile()
    {
        $nameParts = explode('.', $this->sitemapFileName);
        $ext = array_pop($nameParts);
        $filename = implode('.', $nameParts) . (count($this->_filesList) + 1) . '.' . $ext;

        $fullPath = Yii::getAlias($this->savePathAlias) . DIRECTORY_SEPARATOR . $filename;

        $f = @fopen($fullPath, 'w');

        if ($f === false) {
            throw new Exception("I'm cannot create file '$fullPath'");
        }

        // Add new filename to list of exists
        $this->_filesList[] = $filename;

        $this->_file = $f;

        // Write sitemap header
        $this->writeHeader();
        // Reset count of items
        $this->_itemsCount = 0;

        return $this->_file;
    }
593725
protected function open($archiveFileName)
    {
        $this->zip = new ZipArchive();
        $open_result = $this->zip->open($archiveFileName);
        if ($open_result !== true) {
            throw new Exception('Could not open Zip archive: '.$open_result);
        }
    }
205397
public function Start()
    {
        if(!file_exists($this->definitions_path))
        {
            throw new \Exception(
                t("Trying to import symbols from a non existent directory.")
            );
        }
        
        $this->SendMessage(
            sprintf(
                t("Starting import of definitions stored in %s format."),
                $this->import_type
            )
        );
        
        if($this->import_type == Type::JSON)
        {
            $this->LoadFromJSON($this->definitions_path);
        }
        else
        {
            $this->LoadFromPHP($this->definitions_path);
        }
        
        $this->SendMessage(t("Import completed."));
    }
350058
public static function launch()
    {
        if (static::check()) {
            clean();

            $view = config('maintenance.view');
            $view = str_replace('.', '/', $view).'.php';

            // $view = '../app/views/'.$view;
            $view = '../resources/views/'.$view;
            // d($view);:
            if (!file_exists($view)) {
                throw new \Exception('The view \''.config('maintenance.view').'\' not found');
            }

            include $view;

            out('');
        }
    }
1052865
protected function openHandler($filePath, $mode)
    {
        $fileHandler = @fopen($filePath, $mode);
        if (false === $fileHandler) {
            throw new \RuntimeException("Cannot open the file '$filePath' in '$mode' mode");
        }

        return $fileHandler;
    }
1287158
protected function openFile($filename)
    {
        $this->filename = $filename;

        if (!is_file($this->filename)) {
            throw new \Exception(
                sprintf(
                    'File %s does not exist',
                    $this->filename
                )
            );
        }

        $this->file = fopen($this->filename, 'rb');
        if (false === $this->file) {
            throw new \Exception(
                sprintf(
                    'Could not open file %s for reading',
                    $this->filename
                )
            );
        }
    }
372418
public function create()
    {
        $fs = new Filesystem();

        if (!$this->sourceDir) {
            throw new \Exception('O diretório de código fonte "singular.directory.src" da aplicação não foi definido!');
        }

        $migrationDir = $this->getMigrationDir();

        if (!$fs->exists($migrationDir)) {
            throw new \Exception(sprintf('O diretório de migration não existe!'));
        }

        $timestamp = time();

        $aplicacoes = $this->getAplicacoesToMigration();

        if (count($aplicacoes) > 0) {
            $template = file_get_contents(
                __DIR__.DIRECTORY_SEPARATOR."templates".DIRECTORY_SEPARATOR."app_migration.tpl"
            );

            $template = str_replace('$TIMESTAMP',$timestamp, $template);
            $template = str_replace('$APLICACOES', $this->arrayToString($aplicacoes, $timestamp) , $template);

            $dt = new \DateTime('now', new \DateTimeZone('UTC'));
            $date = $dt->format('YmdHis');

            file_put_contents($migrationDir.DIRECTORY_SEPARATOR.$date.'_insere_registros_aplicacoes_'.$timestamp.'.php', $template);
        }

        $modulos = $this->getModulosToMigration();

        if (count($modulos) > 0) {
            $template = file_get_contents(
                __DIR__.DIRECTORY_SEPARATOR."templates".DIRECTORY_SEPARATOR."mod_migration.tpl"
            );

            $template = str_replace('$TIMESTAMP',$timestamp, $template);
            $template = str_replace('$MODULOS', $this->arrayToString($modulos, $timestamp) , $template);

            sleep(1);

            $dt = new \DateTime('now', new \DateTimeZone('UTC'));
            $date = $dt->format('YmdHis');

            file_put_contents($migrationDir.DIRECTORY_SEPARATOR.$date.'_insere_registros_modulos_'.$timestamp.'.php', $template);
        }

        $this->clearMigrations();

        return count($modulos) + count($aplicacoes);
    }
1283507
public function init()
    {
        //strip the / off the end to check for existence of a file
        //that has the same name as $this->dir
        if (!file_exists(substr($this->dir, 0, -1)) && is_writable(dirname($this->dir))) {
            mkdir($this->dir, 0777);
        } elseif (!is_dir($this->dir)) {
            throw new \Exception("'$this->dir' is not a directory");
        } elseif (!is_writable($this->dir)) {
            throw new \Exception("'$this->dir' is not writable");
        }

        return $this;
    }
237083
function handler()
    {
        if (!isset($this->_handler)){
            $file = $this->getDir().'/'.$this->file;
            switch ($this->ext()){
                case 'gif':
                    $this->_handler = @imagecreatefromgif($file);
                    break;
                case 'png':
                    $this->_handler = @imagecreatefrompng($file);
                    break;
                case 'jpg':
                    $this->_handler = @imagecreatefromjpeg($file);
                    break;
                default:
                    throw new \Exception('Не поддерживаем тип файла-изображения');
            }
        }
        return $this->_handler;
    }
574391
public function execute()
    {
        if (!is_resource($this->handle)) {
            throw new RuntimeException('Curl handle has been closed, just open it before execute...');
        }

        curl_setopt_array($this->handle, array_filter($this->options));
        $return = curl_exec($this->handle);

        if ($return === false) {
            throw ExceptionFactory::build(
                curl_errno($this->handle),
                curl_error($this->handle)
            );
        }

        return $return;
    }
592634
private function openImage($file)
		# Author:     Jarrod Oberto
		# Date:       27-02-08
		# Purpose:
		# Param in:
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{

		if ( ! file_exists($file) && ! $this->checkStringStartsWith('http://', $file) && ! $this->checkStringStartsWith('https://', $file) )
		{
			if ($this->debug)
			{
				throw new Exception('Image not found.');
			}
			else
			{
				throw new Exception();
			}
		};

		// *** Get extension
		$extension = strrchr($file, '.');
		$extension = fix_strtolower($extension);
		switch ($extension)
		{
			case '.jpg':
			case '.jpeg':
				$img = @imagecreatefromjpeg($file);
				break;
			case '.gif':
				$img = @imagecreatefromgif($file);
				break;
			case '.png':
				$img = @imagecreatefrompng($file);
				break;
			case '.bmp':
				$img = @$this->imagecreatefrombmp($file);
				break;
			case '.psd':
				$img = @$this->imagecreatefrompsd($file);
				break;


			// ... etc

			default:
				$img = false;
				break;
		}

		return $img;
	}
688529
public function executeSplit()
    {
        $command = $this->getCommand();
        $process = new Process($command);
        $process->setTimeout(null);
        $process->run();

        if (!$process->isSuccessful()) {
            throw new \Exception($process->getOutput(), 1);
        }

        $this->renameSplitFiles();
    }
867881
protected function open($archiveFileName)
    {
        $this->rar = \RarArchive::open($archiveFileName);
        if ($this->rar === false) {
            throw new Exception('Could not open Rar archive');
        }
    }