{@inheritDoc}
@throws \RuntimeException
552021
protected function init()
    {
        // php --rf msg_send
        if (!function_exists('msg_receive')) {
            throw new \RuntimeException(
                'To enable System V semaphore,shared-memory,messages support compile PHP with the option --enable-sysvsem --enable-sysvshm --enable-sysvmsg.',
                -500
            );
        }

        parent::init();

        $this->driver = Queue::DRIVER_SYSV;

        if ($this->id <= 0) {
            $this->id = ftok(__FILE__, $this->project);
        }

        // 初始化队列列表. 使用时再初始化需要的队列
        $this->queues = new \SplFixedArray(count($this->getPriorities()));
    }
382870
public function serialize()
    {
        if ($this->getIsModified() || $this->getIsNew()) {
            throw new RuntimeException($this->translate(
                'Cannot serialize modified or new object.'
            ));
        }

        if ($this->collection && $this->type) {
            $this->fullyLoad(true);
        }
        $data = [
            $this->initialValues,
            $this->getCollectionName(),
            $this->getTypeName()
        ];

        return serialize($data);
    }
318922
public function load($file)
    {
        if (!is_file($file)) {
            if (!$file = $this->findFile($file)) {
                throw new \RuntimeException(sprintf('Language file: %s not found.', $file));
            }
        }

        return include $file;
    }
1160653
public function send()
    {
        if (!$this->client) {
            throw new RuntimeException('A client must be set on the request');
        }

        if (null === $this->configuration->url) {
            $this->configuration->url = $this->getUrl()->toString();
        }
        $this->prepare();

        return $this->client->send($this);
    }
1299078
public function write($message)
    {
        if ($this->output instanceof OutputInterface) {
            $this->output->write($message);
        } elseif (@fwrite($this->output, $message) === false) {
            throw new \RuntimeException('Unable to write output.');
        }
    }
931568
public function execute()
	{
		$this->connect();

		if (!is_object($this->connection))
		{
			$this->log(
				Log\LogLevel::ERROR,
				'Database query failed (error #{code}): {message}',
				array('code' => $this->errorNum, 'message' => $this->errorMsg)
			);
			throw new \RuntimeException($this->errorMsg, $this->errorNum);
		}

		// Take a local copy so that we don't modify the original query and cause issues later
		$sql = $this->replacePrefix((string) $this->sql);

		if ($this->limit > 0 || $this->offset > 0)
		{
			// @TODO
			$sql .= ' LIMIT ' . $this->offset . ', ' . $this->limit;
		}

		// Increment the query counter.
		$this->count++;

		// If debugging is enabled then let's log the query.
		if ($this->debug)
		{
			// Add the query to the object queue.
			$this->log(
				Log\LogLevel::DEBUG,
				'{sql}',
				array('sql' => $sql, 'category' => 'databasequery', 'trace' => debug_backtrace())
			);
		}

		// Reset the error values.
		$this->errorNum = 0;
		$this->errorMsg = '';

		// Execute the query.
		$this->executed = false;

		if ($this->prepared instanceof \PDOStatement)
		{
			// Bind the variables:
			if ($this->sql instanceof PreparableInterface)
			{
				$bounded =& $this->sql->getBounded();

				foreach ($bounded as $key => $obj)
				{
					$this->prepared->bindParam($key, $obj->value, $obj->dataType, $obj->length, $obj->driverOptions);
				}
			}

			$this->executed = $this->prepared->execute();
		}

		// If an error occurred handle it.
		if (!$this->executed)
		{
			// Get the error number and message before we execute any more queries.
			$errorNum = (int) $this->connection->errorCode();
			$errorMsg = (string) 'SQL: ' . implode(", ", $this->connection->errorInfo());

			// Check if the server was disconnected.
			if (!$this->connected())
			{
				try
				{
					// Attempt to reconnect.
					$this->connection = null;
					$this->connect();
				}
				catch (\RuntimeException $e)
				// If connect fails, ignore that exception and throw the normal exception.
				{
					// Get the error number and message.
					$this->errorNum = (int) $this->connection->errorCode();
					$this->errorMsg = (string) 'SQL: ' . implode(", ", $this->connection->errorInfo());

					// Throw the normal query exception.
					$this->log(
						Log\LogLevel::ERROR,
						'Database query failed (error #{code}): {message}',
						array('code' => $this->errorNum, 'message' => $this->errorMsg)
					);
					throw new \RuntimeException($this->errorMsg, $this->errorNum);
				}

				// Since we were able to reconnect, run the query again.
				return $this->execute();
			}
			else
			// The server was not disconnected.
			{
				// Get the error number and message from before we tried to reconnect.
				$this->errorNum = $errorNum;
				$this->errorMsg = $errorMsg;

				// Throw the normal query exception.
				$this->log(
					Log\LogLevel::ERROR,
					'Database query failed (error #{code}): {message}',
					array('code' => $this->errorNum, 'message' => $this->errorMsg)
				);
				throw new \RuntimeException($this->errorMsg, $this->errorNum);
			}
		}

		return $this->prepared;
	}
487520
private function connect()
    {
        $dsn = "{$this->credentials->getDriver()}:host={$this->credentials->getHost()}";

        try {
            $pdo = new \PDO($dsn, $this->credentials->getUsername(), $this->credentials->getPassword());
        } catch (\PDOException $e) {
            throw new \RuntimeException('Failed to connect to database.', 0, $e);
        }

        $this->pdo = $pdo;

        if (null !== $this->credentials->getCharset()) {
            $this->setCharset($this->credentials->getCharset());
        }

        if (null !== $this->credentials->getDatabase()) {
            $this->selectDatabase($this->credentials->getDatabase());
        }
    }
151429
protected function handleError($response) {
    $errorMsg = $response->getValue('errorMsg');
    self::$logger->error("Error in remote call to ".$this->serverUrl.": ".$errorMsg."\n".$response->toString(), __FILE__);
    throw new \RuntimeException("Error in remote call to ".$this->serverUrl.": ".$errorMsg);
  }
543638
public function setTemplate($template)
    {
        $this->templatePath = $this->getTemplatesDirectory() . '/' . ltrim($template, '/');
        if (!file_exists($this->templatePath)) {
            throw new \RuntimeException('View cannot render template `' . $this->templatePath . '`. Template does not exist.');
        }
    }
1132085
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->requireConfig();

        $utils = new Utils();
        $output->writeln('Starting <fg=blue>Magallanes</>');
        $output->writeln('');

        try {
            $this->runtime->setEnvironment($input->getArgument('environment'));

            if (!$this->runtime->getEnvOption('releases', false)) {
                throw new RuntimeException('Releases are not enabled', 70);
            }

            $output->writeln(sprintf('    Environment: <fg=green>%s</>', $this->runtime->getEnvironment()));
            $this->log(sprintf('Environment: %s', $this->runtime->getEnvironment()));

            if ($this->runtime->getConfigOption('log_file', false)) {
                $output->writeln(sprintf('    Logfile: <fg=green>%s</>', $this->runtime->getConfigOption('log_file')));
            }

            $output->writeln('');

            $hosts = $this->runtime->getEnvOption('hosts');
            if (!is_array($hosts) && !$hosts instanceof \Countable) {
                $hosts = [];
            }
            if (count($hosts) == 0) {
                $output->writeln('No hosts defined');
                $output->writeln('');
            } else {
                $hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');

                foreach ($hosts as $host) {
                    $this->runtime->setWorkingHost($host);

                    // Get List of Releases
                    $cmdListReleases = sprintf('ls -1 %s/releases', $hostPath);

                    /** @var Process $process */
                    $process = $this->runtime->runRemoteCommand($cmdListReleases, false);
                    if (!$process->isSuccessful()) {
                        throw new RuntimeException(sprintf('Unable to retrieve releases from host "%s"', $host), 80);
                    }

                    $releases = [];
                    if (trim($process->getOutput()) != '') {
                        $releases = explode(PHP_EOL, trim($process->getOutput()));
                        rsort($releases);
                    }

                    if (count($releases) == 0) {
                        $output->writeln(sprintf('    No releases available on host <fg=black;options=bold>%s</>:', $host));
                    } else {
                        // Get Current Release
                        $cmdCurrentRelease = sprintf('readlink -f %s/current', $hostPath);

                        /** @var Process $process */
                        $process = $this->runtime->runRemoteCommand($cmdCurrentRelease, false);
                        if (!$process->isSuccessful()) {
                            throw new RuntimeException(sprintf('Unable to retrieve current release from host "%s"', $host), 85);
                        }

                        $currentReleaseId = explode('/', trim($process->getOutput()));
                        $currentReleaseId = $currentReleaseId[count($currentReleaseId) - 1];

                        $output->writeln(sprintf('    Releases on host <fg=black;options=bold>%s</>:', $host));

                        foreach ($releases as $releaseId) {
                            $releaseDate = $utils->getReleaseDate($releaseId);

                            $output->write(sprintf('        Release ID: <fg=magenta>%s</> - Date: <fg=black;options=bold>%s</> [%s]',
                                $releaseId,
                                $releaseDate->format('Y-m-d H:i:s'),
                                $utils->getTimeDiff($releaseDate)
                            ));

                            if ($releaseId == $currentReleaseId) {
                                $output->writeln(' <fg=red;options=bold>[current]</>');
                            } else {
                                $output->writeln('');
                            }
                        }
                    }

                    $this->runtime->setWorkingHost(null);
                    $output->writeln('');
                }
            }
        } catch (RuntimeException $exception) {
            $output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
            $this->statusCode = $exception->getCode();
        }

        $output->writeln('Finished <fg=blue>Magallanes</>');

        return $this->statusCode;
    }
1374252
public function remove($key)
    {
        $this->load();

        if ($this->exists($key)) {
            unset($this->config[$key]);
            return true;
        } else {
            throw new RuntimeException(sprintf('Attempted to read non-existing key "%s"', $key));
        }
    }
718494
public function indexAction()
    {
        $request = $this->getRequest();
        $type    = $request->getParam( 'type' );

        if ( ! $request instanceof ConsoleRequest )
        {
            throw new \RuntimeException( sprintf(
                '%s can only be used from a console.',
                __METHOD__
            ) );
        }

        $phpSelf = realpath( static::PHP_SELF );

        if ( empty( $phpSelf ) || ! is_file( $phpSelf ) )
        {
            throw new \RuntimeException( sprintf(
                '%s: php not found at "%s" (in "%s").',
                __METHOD__,
                static::PHP_SELF,
                getcwd()
            ) );
        }

        $result = 'Running ' . $type . ' cron(s) ...' . PHP_EOL . PHP_EOL;

        foreach ( $this->mimicSiteInfos() as $siteInfo )
        {
            $domain  = $siteInfo->getDomain();
            $process = new Process( array(
                'command'   => 'php',
                'arguments' => array(
                    $phpSelf,
                    'cron',
                    $domain,
                    $type,
                ),
                'environmentVariables'  => array(
                    'GRIDGUYZ_HOST'     => $domain,
                    'HTTP_HOST'         => $domain,
                ),
            ) );

            $result .= 'Calling process ...' . PHP_EOL .
                       $process->getRunCommand() . PHP_EOL;

            $output = tempnam( './data/', $domain );
            $descr  = array( Process::TYPE_FILE, $output, Process::MODE_APPEND );
            file_put_contents( $output, '' );

            $process->open( array(
                Process::STREAM_STDOUT => $descr,
                Process::STREAM_STDERR => $descr,
            ) );

            $return     = $process->close();
            $messages   = rtrim( file_get_contents( $output ), PHP_EOL );
            unlink( $output );

            if ( $messages )
            {
                $result .= static::PADDING . preg_replace(
                    '/[' . PHP_EOL . ']+/',
                    '$0' . static::PADDING,
                    $messages
                ) . PHP_EOL;
            }

            $result .= sprintf(
                'Process returned with #%d: %s' . PHP_EOL . PHP_EOL,
                $return,
                $return ? 'error!' : 'success.'
            );
        }

        $result .= 'Done.' . PHP_EOL;
        return $result;
    }
363173
protected function executeCommand($command) {
        $class = $this->config['commands'][$command]['class'];

        if (!class_exists($class) ||
            !is_subclass_of($class, __NAMESPACE__ . '\\Command\\Executes')
        ) {
            throw new RuntimeException(sprintf(
                'Command "%s" not found',
                $command
            ), ExitApp::BAD_USER_INTERACTION);
        }

        $this->config['command'] = $command;

        /** @var Executes $command */
        $command = new $class($this->config, $this->log);

        foreach ($this->config['args'] as $help) {
            if (in_array($help, ['-h', '--help'])) {
                $command->printUsage();
                return;
            }
        }

        $command->setup()->execute()->tearDown();
    }
1076133
public function compile(Compiler $compiler)
    {
        $compiler->addDebugInfo($this);

        $compiler
            ->write('throw new \RuntimeException(')
            ->subcompile($this->getNode('message'))
            ->write(', ')
            ->write($this->getAttribute('code') ?: 500)
            ->write(");\n");
    }
879712
public function getConfig($key)
    {
        if (null === $this->configs) {
            $this->loadConfigs();
        }

        if (false == array_key_exists($key, $this->configs)) {
            $availableKeys = implode(', ', array_keys($this->configs));
            throw new \RuntimeException(sprintf('Config "%s" could not be found. Found: %s', $key, $availableKeys));
        }

        $config = $this->configs[$key];

        return $config;
    }
468408
public function load() : Persistable
    {
        if (!is_readable($this->path)) {
            throw new RuntimeException("File $this->path does not"
                . ' exist or is a folder, check path and permissions.');
        }
            
        $data = file_get_contents($this->path) ?: '';

        $persistable = $this->serializer->unserialize($data);

        if (!$persistable instanceof Persistable) {
            throw new RuntimeException('Model could not be reconstituted.');
        }

        return $persistable;
    }
90453
public function add($name)
    {
        $this->repository->setCurrentUser($this->repository->getUserService()->loadUser($this->adminID));
        $contentTypeService = $this->repository->getContentTypeService();

        $contentTypeGroupStruct = $contentTypeService->newContentTypeGroupCreateStruct($name);

        try {
            $contentTypeGroup = $contentTypeService->createContentTypeGroup($contentTypeGroupStruct);
            return $contentTypeGroup;
        } catch (UnauthorizedException $e) {
            throw new \RuntimeException($e->getMessage());
        } catch (InvalidArgumentException $e) {
            throw new \RuntimeException($e->getMessage());
        }
    }