Open url/stream
@return void
@throws \RuntimeException
350776
public function init()
    {
        $stream = @fopen($this->config['url'], 'a');
        if (!$stream) {
            throw new \RuntimeException(sprintf("Couldn't open resource '%s'", $this->config['url']));
        }

        $this->stream = $stream;

        if (!empty($this->config['lock']) && $this->config['lock'] === true && stream_supports_lock($this->stream)) {
            $this->useLocks = true;
        }
    }
637549
public function tell()
    {
        $this->valideAttach();
        if (($stream = ftell($this->stream)) === false) {
            throw new \RuntimeException('An error has occurred.');
        }

        return $stream;
    }
731882
private function connect()
    {
        if ($this->ssl && !function_exists('ftp_ssl_connect')) {
            throw new \RuntimeException('This Server Has No SSL-FTP Available.');
        }

        // open ftp connection
        if (!$this->ssl) {
            $this->connection = ftp_connect($this->host, $this->port, $this->timeout);
        } else {
            $this->connection = ftp_ssl_connect($this->host, $this->port, $this->timeout);
        }

        if (!$this->connection) {
            throw new \RuntimeException(sprintf('Could not connect to \'%s\' (port: %s).', $this->host, $this->port));
        }

        if (defined('FTP_USEPASVADDRESS')) {
            ftp_set_option($this->connection, FTP_USEPASVADDRESS, false);
        }

        $username = $this->username ?: 'anonymous';
        $password = $this->password ?: '';

        // login ftp user
        if (!@ftp_login($this->connection, $username, $password)) {
            $this->close();
            throw new \RuntimeException(sprintf('Could not login as %s.', $username));
        }

        // switch to passive mode if needed
        if ($this->passive && !ftp_pasv($this->connection, true)) {
            $this->close();
            throw new \RuntimeException('Could not turn passive mode on.');
        }

        // enable utf8 mode if configured
        if($this->utf8 == true) {
            ftp_raw($this->connection, "OPTS UTF8 ON");
        }

        // ensure the adapter's directory exists
        if ('/' !== $this->directory) {
            try {
                $this->ensureDirectoryExists($this->directory, $this->create);
            } catch (\RuntimeException $e) {
                $this->close();
                throw $e;
            }

            // change the current directory for the adapter's directory
            if (!ftp_chdir($this->connection, $this->directory)) {
                $this->close();
                throw new \RuntimeException(sprintf('Could not change current directory for the \'%s\' directory.', $this->directory));
            }
        }
    }
363039
private function createFileHandler()
    {
        $path = sprintf($this->config["destination"], time(), date($this->config["datetimeFormat"]));

        $this->destinationHandler = @fopen($path, $this->config["writeMode"]);
        if (!$this->config["blocking"]) {
            stream_set_blocking($this->destinationHandler, (int)$this->config["blocking"]);
        }

        if (!$this->destinationHandler) {
            throw new RuntimeException("Failed to open file $path created from " . $this->config["destination"] . " expression (mode: " . $this->config["writeMode"] . ")");
        }
    }
121680
public function getContents()
    {
        if (!$this->stream) {
            throw new RuntimeException("No stream attached");
        }

        if (!$this->isReadable() || ($contents = stream_get_contents($this->stream)) === false) {
            throw new RuntimeException('Could not get contents of stream');
        }

        return $contents;
    }
267852
private function load()
    {
        if (! isset($this->runtime_file_content)) {
            $this->runtime_file_content = json_decode(@file_get_contents($this->getFilePath()), true);
        }

        return $this->runtime_file_content;
    }
799455
protected function read()
	{
		if( !file_exists( $this->fileName ) )
			throw new RuntimeException( 'File "'.$this->fileName.'" is not existing.' );
		$this->data		= parse_ini_file( $this->fileName, true );
	}
1173893
private function open()
  {
    // Used for trapping `fopen()` errors.
    $this->trappedErrorNumber = null;
    $this->trappedErrorString = null;

    $old = set_error_handler(array($this, 'trapError'));

    $needsChmod = !file_exists($this->file);
    $fh = fopen($this->file, 'a');

    restore_error_handler();

    // Handles trapped `fopen()` errors.
    if ($this->trappedErrorNumber) {
      throw new Exception(
          sprintf(
              "Logger Error: '%s'",
              $this->trappedErrorString
          ),
          $this->trappedErrorNumber
      );
    }

    if ($needsChmod) {
      @chmod($this->file, $this->mode & ~umask());
    }

    return $this->file = $fh;
  }
641554
public function start() {

		if(!$this->started) {

			// only non-CLI environments are supposed to provide sessions

			if(PHP_SAPI !== 'cli') {
				
				// avoid starting an already started session

				if (
					(PHP_VERSION_ID >= 50400 && session_status() === PHP_SESSION_ACTIVE) ||
					(PHP_VERSION_ID < 50400 && session_id())
				) {
					throw new \RuntimeException('Failed to start the session: Session already started.');
				}

				// allow session only when no headers have been sent

				if (headers_sent($file, $line)) {
					throw new \RuntimeException(sprintf("Cannot start session. Headers have already been sent by file '%s' at line %d.", $file, $line));
				}

				if(!session_start()) {
					throw new \RuntimeException('Session start failed.');
				}
			}

			$this->loadSession();

		}
	}
743986
public function connect()
    {
        $streamContext = stream_context_create(array(
            $this->getTransport() => $this->getContextOptions()
        ));

        $streamResource = stream_socket_client(
            $this->getAddress(),
            $errorCode,
            $errorMessage,
            $this->getSocketTimeout(),
            $this->getConnectionFlags(),
            $streamContext
        );

        if (!$streamResource) {
            throw new \RuntimeException(sprintf(
                'Unable to connect on socket. Error [%d]: %s',
                $errorCode,
                $errorMessage
            ));
        }

        stream_set_blocking($streamResource, $this->isBlockingMode());

        $this->setStreamResource($streamResource);

        return $this;
    }
266094
public function run()
    {
        // Firstly make sure, default is set
        if (!isset($this->config['components']['router']['default'])) {
            throw new RuntimeException('You should provide default controller for router');
        }

        $sl = $this->bootstrap();

        // Grab required services to run the application
        $request = $sl->get('request');
        $dispatcher = $sl->get('dispatcher');
        $response = $sl->get('response');

        // Do we need to perform SSL redirect?
        if (isset($this->config['components']['router']['ssl']) && $this->config['components']['router']['ssl'] == true) {
            $request->sslRedirect();
        }

        // We will start from route matching firstly
        $router = new Router();

        // Returns RouteMatch on success, false on failure
        $route = $router->match($request->getURI(), $dispatcher->getURIMap());
        $notFound = false;

        // $route is false on failure, otherwise RouteMatch is returned when found
        if ($route !== false) {
            $content = null;

            try {
                $content = $dispatcher->render($route->getMatchedURITemplate(), $route->getVariables());
            } catch(\DomainException $e){
                $notFound = true;
            }

            if ($content === false) {
                // Returning false from an action, will trigger 404
                $notFound = true;
            }

        } else {
            $notFound = true;
        }

        // Handle now found now
        if ($notFound === true) {
            $default = $this->config['components']['router']['default'];

            if (is_string($default)) {
                $notation = new RouteNotation();
                $args = $notation->toArgs($default);

                // Extract controller and action from $args
                $controller = $args[0];
                $action = $args[1];
                
                // Finally call it
                $content = $dispatcher->call($controller, $action);

            } else if (is_callable($default)) {
                $content = call_user_func($default, $sl);
            } else {
                throw new LogicException(sprintf(
                    'Default route must be either callable or a string that represents default controller, not %s', gettype($default)
                ));
            }

            $response->setStatusCode(404);
        }

        $response->send($content);
    }
1215716
public final function getContents(): string
   {
       if (!$this->isReadable()) {
           throw new RuntimeException(
               "Can't getContents: stream is not readable");
       }
       $this->meta["eof"] = true;
       return (string) stream_get_contents($this->stream);
   }
1211173
public function run() {
		if ($this->url === null) {
			throw new \Exception("No URL configured for redirection.");
		}
		if (strpos($this->url, '/') === 0 || strpos($this->url, 'http://') === 0 || strpos($this->url, 'https://') === 0) {
			$url = ValueUtils::val($this->url);
		} else {
			$url = ROOT_URL.ValueUtils::val($this->url);
		}
		header("Location: ".$url);
	}
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;
    }
644108
protected function openSink()
    {
        if (!$this->uri) {
            throw new \LogicException(
                'Missing stream uri, the stream can not be opened.'
            );
        }
        $this->error = null;
        set_error_handler(array($this, 'errorTrap'));

        if (substr($this->uri, 0, 4) === 'udp:') {
            $parsed = parse_url($this->uri);
            if (!isset($parsed['host'])) {
                throw new \UnexpectedValueException(sprintf(
                    'Udp transport "%s" must specify a host', $this->uri
                ));
            }
            if (!isset($parsed['port'])) {
                throw new \UnexpectedValueException(sprintf(
                    'Udp transport "%s" must specify a port', $this->uri
                ));
            }

            $this->prefix = '';
            if (isset($parsed['path'])) {
                $this->prefix = ltrim($parsed['path'], '/');
            }

            $this->writer = new UdpWriter($parsed['host'], $parsed['port']);
        } else {
            $this->writer = new StreamWriter($this->uri);
        }
        restore_error_handler();

        if ($this->error !== null) {
            $this->writer = null;
            throw new \UnexpectedValueException(sprintf(
                'The stream or file "%s" could not be opened: %s',
                $this->uri, $this->error
            ));
        }
    }
1151986
public function open()
    {
        $this->severityLabels = [
            LOG_EMERG   => 'EMERGENCY',
            LOG_ALERT   => 'ALERT    ',
            LOG_CRIT    => 'CRITICAL ',
            LOG_ERR     => 'ERROR    ',
            LOG_WARNING => 'WARNING  ',
            LOG_NOTICE  => 'NOTICE   ',
            LOG_INFO    => 'INFO     ',
            LOG_DEBUG   => 'DEBUG    ',
        ];

        $this->streamHandle = fopen('php://' . $this->streamName, 'w');
        if (!is_resource($this->streamHandle)) {
            throw new CouldNotOpenResourceException('Could not open stream "' . $this->streamName . '" for write access.', 1310986609);
        }
    }
167054
public function open()
    {
        if (!$this->isRemoteFile($this->path) && !is_readable($this->path)) {
            throw new BoxClientException('Failed to create BoxFile instance. Unable to read resource: ' . $this->path . '.');
        }

        $this->stream = \GuzzleHttp\Psr7\stream_for(fopen($this->path, 'r'));

        if (!$this->stream) {
            throw new BoxClientException('Failed to create BoxFile instance. Unable to open resource: ' . $this->path . '.');
        }
    }