/** * Execute a command against the service and get the response * @param string The command to execute (leave off any CRLF!!!) * @param int The code to check for in the response, if any. -1 indicates that no response is wanted. * @return Swift_Events_ResponseEvent The server's response (could be multiple lines) * @throws Swift_ConnectionException If a code was expected but does not match the one returned */ function &command($command, $code = null) { $null = null; $log =& Swift_LogContainer::getLog(); if (Swift_Errors::halted()) { return $null; } if ($command !== "") { Swift_ClassLoader::load("Swift_Events_CommandEvent"); $command_event =& new Swift_Events_CommandEvent($command, $code); $command = null; //For memory reasons $this->notifyListeners($command_event, "BeforeCommandListener"); if ($log->hasLevel(SWIFT_LOG_NETWORK) && $code != -1) { $log->add($command_event->getString(), SWIFT_LOG_COMMAND); } $end = $code != -1 ? "\r\n" : null; $this->connection->write($command_event->getString(), $end); $this->notifyListeners($command_event, "CommandListener"); } if ($code == -1) { return $null; } Swift_ClassLoader::load("Swift_Events_ResponseEvent"); $response_event =& new Swift_Events_ResponseEvent($this->connection->read()); $this->notifyListeners($response_event, "ResponseListener"); if ($log->hasLevel(SWIFT_LOG_NETWORK)) { $log->add($response_event->getString(), SWIFT_LOG_RESPONSE); } if ($command !== "" && $command_event->getCode() !== null) { $this->assertCorrectResponse($response_event, $command_event->getCode()); } return $response_event; }
/** * Execute needed logic prior to compilation */ function preBuild() { if (Swift_Errors::halted()) { return; } $data =& $this->getData(); if (!($enc = $this->getEncoding())) { $this->setEncoding("8bit"); } if ($this->getCharset() === null && !$this->numChildren()) { if (is_string($data) && $this->_encoder->isUTF8($data)) { $this->setCharset("utf-8"); } elseif (is_string($data) && $this->_encoder->is7BitAscii($data)) { $this->setCharset("us-ascii"); if (!$enc) { $this->setEncoding("7bit"); } } else { $this->setCharset("iso-8859-1"); } } elseif ($this->numChildren()) { if (!$data) { $this->setData($this->getMimeWarning()); $this->setLineWrap(76); } if ($this->getCharset() !== null) { $this->setCharset(null); } if ($this->isFlowed()) { $this->setFlowed(false); } $this->setEncoding("7bit"); } }