具体如何写文件

@param mixed $sType
@param mixed $sMessage
@param mixed $bHead
@param mixed $iFlag
@static
@access public
@return bool
358388
public static function _file($sType, $sMessage, $bHead, $iFlag) {

		if (!self::_init()) {
			return FALSE;
		}

		if (!is_string($sType) && !preg_match('#[0-9a-z\_]{1, 30}#', $sType)) {
			return FALSE;
		}

		$aConfig = Config::get('debug');

		$sFile = self::$_sDebugPath.'/'.$sType;
		if (disk_free_space(self::$_sDebugPath) < $aConfig['disk_free_space']) {
			return FALSE;
		}

		if (file_exists($sFile) && (filesize($sFile) > $aConfig['max_size'] || !is_writable($sFile))) {
			return FALSE;
		}

		if (!is_string($sMessage)) {
			$sMessage = json_encode($sMessage, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
		}

		if ($bHead) {
			$fTimeCost = sprintf('%.06f', microtime(TRUE) - $_SERVER['REQUEST_TIME_FLOAT']);
			$sHead= $_SERVER['REQUEST_URI']."\n"
				.date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME'])."\n"
				.$fTimeCost."\n";
			$sMessage = $sHead.$sMessage."\n";
		}

		$sMessage .= "\n";

		return file_put_contents($sFile, $sMessage, $iFlag);
	}
322364
public function handle(
        $msgType,
        \fpoirotte\Pssht\Wire\Decoder $decoder,
        \fpoirotte\Pssht\Transport $transport,
        array &$context
    ) {
        $message = \fpoirotte\Pssht\Messages\DEBUG::unserialize($decoder);
        if ($message->mustAlwaysDisplay()) {
            echo escape($message->getMessage()) . PHP_EOL;
        }
        return true;
    }
1242780
public static function dump($sType, $sMessage = NULL, $bHead = FALSE) {
		if ($sMessage === NULL) {
			return ;
		}
		self::_file($sType, $sMessage, $bHead, LOCK_EX);
	}
1173014
protected function RemoveFromWishlist($sPkgShopWishlistArticleId = null, $sMessageHandler = null, $bIsInternalCall = false)
    {
        $oGlobal = TGlobal::instance();
        $aRequestData = $oGlobal->GetUserData(self::URL_REQUEST_PARAMETER);
        if (is_null($sPkgShopWishlistArticleId) && array_key_exists(self::URL_ITEM_ID_NAME, $aRequestData)) {
            $sPkgShopWishlistArticleId = $aRequestData[self::URL_ITEM_ID_NAME];
        }

        if (is_null($sMessageHandler) && array_key_exists(self::URL_MESSAGE_CONSUMER_NAME, $aRequestData)) {
            $sMessageHandler = $aRequestData[self::URL_MESSAGE_CONSUMER_NAME];
            if (empty($sMessageHandler)) {
                $sMessageHandler = null;
            }
        }
        if (is_null($sMessageHandler)) {
            $sMessageHandler = self::MSG_CONSUMER_NAME;
        }
        $oMessageManager = TCMSMessageManager::GetInstance();
        $oUser = TdbDataExtranetUser::GetInstance();
        if (!$oUser->IsLoggedIn()) {
            $oMessageManager->AddMessage($sMessageHandler, 'WISHLIST-USER-NOT-LOGGED-IN');
        } else {
            $oWishlistItem = TdbPkgShopWishlistArticle::GetNewInstance();
            /** @var $oWishlistItem TdbPkgShopWishlistArticle */
            $oWishlistItem->Load($sPkgShopWishlistArticleId);
            $oArticle = $oWishlistItem->GetFieldShopArticle();
            if ($oArticle) {
                $aMessageData = array('sArticleLinkStart' => '<a href="'.TGlobal::OutHTML($oArticle->GetDetailLink()).'">', 'sArticleLinkEnd' => '</a>', 'sArticleName' => $oArticle->GetName());
            } else {
                $aMessageData = array();
            }
            $oUser->RemoveArticleFromWishlist($sPkgShopWishlistArticleId);
            $oMessageManager->AddMessage($sMessageHandler, 'WISHLIST-REMOVED-ITEM', $aMessageData);
        }

        $iRedirectNodeId = null;
        if (array_key_exists(self::URL_REDIRECT_NODE_ID_NAME, $aRequestData)) {
            $iRedirectNodeId = $aRequestData[self::URL_REDIRECT_NODE_ID_NAME];
            if (empty($iRedirectNodeId)) {
                $iRedirectNodeId = null;
            }
        }

        if (!$bIsInternalCall) {
            $this->RedirectAfterEvent($iRedirectNodeId);
        }
    }
1204950
public function prependHeadScript($src, $isFile = true)
    {
        $script = $this->createScript($src, $isFile);
        $scripts = $this->headScripts;
        array_unshift($scripts, $script);
        $this->headScripts = $scripts;
    }
103548
function _send_sftp_packet($type, $data)
    {
        $packet = $this->request_id !== false ?
            pack('NCNa*', strlen($data) + 5, $type, $this->request_id, $data) :
            pack('NCa*',  strlen($data) + 1, $type, $data);

        $start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
        $result = $this->_send_channel_packet(self::CHANNEL, $packet);
        $stop = strtok(microtime(), ' ') + strtok('');

        if (defined('NET_SFTP_LOGGING')) {
            $packet_type = '-> ' . $this->packet_types[$type] .
                           ' (' . round($stop - $start, 4) . 's)';
            if (NET_SFTP_LOGGING == self::LOG_REALTIME) {
                echo "<pre>\r\n" . $this->_format_log(array($data), array($packet_type)) . "\r\n</pre>\r\n";
                flush();
                ob_flush();
            } else {
                $this->packet_type_log[] = $packet_type;
                if (NET_SFTP_LOGGING == self::LOG_COMPLEX) {
                    $this->packet_log[] = $data;
                }
            }
        }

        return $result;
    }
533293
public function wasJSCodeInjected($sType)
    {
        $aCodeInjected = $this->_getInjectedCode();
        return isset($aCodeInjected[$sType]) && $aCodeInjected[$sType];
    }
384609
function smtp_send($header, $body) {
//echo $header."<hr />".$body;
      // Include SMTP class code, but not twice
      require_once("class.smtp.php"); // Load code only if asked

      $smtp = new SMTP;

      $smtp->do_debug = $this->SMTPDebug;

      // Try to connect to all SMTP servers
      $hosts = explode(";", $this->Host);
      $index = 0;
      $connection = false;

      // Retry while there is no connection
      while($index < count($hosts) && $connection == false)
      {
         if($smtp->Connect($hosts[$index], $this->Port, $this->Timeout))
            $connection = true;
         //printf("%s host could not connect<br>", $hosts[$index]); //debug only
         $index++;
      }
      if(!$connection)
      {
         $this->error_handler("SMTP Error: could not connect to SMTP host server(s)");
         return false;
      }

      // Must perform HELO before authentication
      $smtp->Hello($this->Helo);

      // If user requests SMTP authentication
      if($this->SMTPAuth)
      {
         if(!$smtp->Authenticate($this->Username, $this->Password))
         {
            $this->error_handler("SMTP Error: Could not authenticate");
            return false;
         }
      }

      if ($this->Sender == "")
         $smtp->Mail(sprintf("<%s>", $this->From));
      else
         $smtp->Mail(sprintf("<%s>", $this->Sender));

      for($i = 0; $i < count($this->to); $i++)
         $smtp->Recipient(sprintf("<%s>", $this->to[$i][0]));
      for($i = 0; $i < count($this->cc); $i++)
         $smtp->Recipient(sprintf("<%s>", $this->cc[$i][0]));
      for($i = 0; $i < count($this->bcc); $i++)
         $smtp->Recipient(sprintf("<%s>", $this->bcc[$i][0]));

      if(!$smtp->Data(sprintf("%s%s", $header, $body)))
      {
         $this->error_handler("SMTP Error: Data not accepted");
         return false;
      }
      $smtp->Quit();

      return true;
   }
250244
function chmod($mode, $filename, $recursive = false)
    {
        if (is_string($mode) && is_int($filename)) {
            $temp = $mode;
            $mode = $filename;
            $filename = $temp;
        }

        $attr = pack('N2', NET_SFTP_ATTR_PERMISSIONS, $mode & 07777);
        if (!$this->_setstat($filename, $attr, $recursive)) {
            return false;
        }
        if ($recursive) {
            return true;
        }

        $filename = $this->_realPath($filename);
        // rather than return what the permissions *should* be, we'll return what they actually are.  this will also
        // tell us if the file actually exists.
        // incidentally, SFTPv4+ adds an additional 32-bit integer field - flags - to the following:
        $packet = pack('Na*', strlen($filename), $filename);
        if (!$this->_send_sftp_packet(NET_SFTP_STAT, $packet)) {
            return false;
        }

        $response = $this->_get_sftp_packet();
        switch ($this->packet_type) {
            case NET_SFTP_ATTRS:
                $attrs = $this->_parseAttributes($response);
                return $attrs['permissions'];
            case NET_SFTP_STATUS:
                $this->_logError($response);
                return false;
        }

        user_error('Expected SSH_FXP_ATTRS or SSH_FXP_STATUS');
        return false;
    }
660493
function setContentType( $type = false, $charset = false,
                             $transferEncoding = false, $disposition = false, $boundary = false )
    {
        if ( $type )
        {
            $this->ContentType['type'] = $type;
        }
        if ( $charset )
            $this->ContentType['charset'] = $charset;
        if ( $transferEncoding )
            $this->ContentType['transfer-encoding'] = $transferEncoding;
        if ( $disposition )
            $this->ContentType['disposition'] = $disposition;
        if ( $boundary )
            $this->ContentType['boundary'] = $boundary;

        // if the body was already defined
        if ( $this->Mail->body instanceof ezcMailText )
        {
            // if the content-type is in the form of e.g. 'text/plain'
            if ( strpos( $this->ContentType['type'] ,'/' ) !== false )
            {
                list( $type, $subType ) = explode( '/', $this->ContentType['type'] );
                $this->Mail->body->subType = $subType;
            }
        }
    }
689983
public static boolean startsWith(byte[] bs, byte[] head) {
        if (bs.length < head.length) {
            return false;
        }
        for (int i = 0; i < head.length; i++) {
            if (head[i] != bs[i]) {
                return false;
            }
        }
        return true;
    }
678374
public static function readFileChunked($sFilename, $iChunkSize = 1048576)
    {
        $iBytesRead = 0;
        $rHandle    = fopen($sFilename, 'rb');
        if ($rHandle === false) {
            return false;
        }

        while (!feof($rHandle)) {
            $sBuffer    = fread($rHandle, $iChunkSize);
            $iBytesRead += strlen($sBuffer);
            echo $sBuffer;
        }

        $bStatus = fclose($rHandle);
        return $bStatus ? $iBytesRead : false;
    }
1220253
public function sendfile($outfd, $cb, $startCb = null, $offset = 0, $length = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!$this->fd) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        if (!FileSystem::$supported) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        static $chunkSize = 1024;
        $ret = true;

        $handler = function (
            $file,
            $sent = -1
        ) use (
            &$ret,
            $outfd,
            $cb,
            &$handler,
            &$offset,
            &$length,
            $pri,
            $chunkSize
        ) {
            if ($outfd instanceof IOStream) {
                if ($outfd->isFreed()) {
                    $cb($file, false);
                    return;
                }
                $ofd = $outfd->getFd();
            } else {
                $ofd = $outfd;
            }
            if (!$ret) {
                $cb($file, false);
                return;
            }
            if ($sent === -1) {
                $sent = 0;
            }
            $offset += $sent;
            $length -= $sent;
            if ($length <= 0) {
                $cb($file, true);
                return;
            }
            if (!$ofd) {
                $cb($file, false);
                return;
            }
            $c = min($chunkSize, $length);
            $ret = eio_sendfile($ofd, $file->fd, $offset, $c, $pri, $handler, $file);
        };
        if ($length !== null) {
            if ($startCb !== null) {
                if (!$startCb($this, $length, $handler)) {
                    $handler($this);
                }
            } else {
                $handler($this);
            }
            return true;
        }
        $this->statRefresh(function ($file, $stat) use ($startCb, $handler, &$length) {
            $length = $stat['size'];
            if ($startCb !== null) {
                if (!$startCb($file, $length, $handler)) {
                    $handler($file);
                }
            } else {
                $handler($file);
            }
        }, $pri);
        return true;
    }
624726
public function sendFrame($data, $type = null, $cb = null)
    {
        if (!$this->handshaked) {
            return false;
        }

        if ($this->finished && $type !== 'CONNCLOSE') {
            return false;
        }

        /*if (in_array($type, ['STRING', 'BINARY']) && ($this->outgoingCompression > 0) && in_array('deflate-frame', $this->extensions)) {
            //$data = gzcompress($data, $this->outgoingCompression);
            //$rsv1 = 1;
        }*/

        $fin = 1;
        $rsv1 = 0;
        $rsv2 = 0;
        $rsv3 = 0;
        $this->write(
            chr(
                bindec(
                    $fin . $rsv1 . $rsv2 . $rsv3
                    . str_pad(
                        decbin(
                            $this->getFrameType($type)
                        ),
                        4,
                        '0',
                        STR_PAD_LEFT
                    )
                )
            )
        );
        $dataLength = mb_orig_strlen($data);
        $isMasked = false;
        $isMaskedInt = $isMasked ? 128 : 0;
        if ($dataLength <= 125) {
            $this->write(chr($dataLength + $isMaskedInt));
        } elseif ($dataLength <= 65535) {
            $this->write(chr(126 + $isMaskedInt) . // 126 + 128
                chr($dataLength >> 8) .
                chr($dataLength & 0xFF));
        } else {
            $this->write(chr(127 + $isMaskedInt) . // 127 + 128
                chr($dataLength >> 56) .
                chr($dataLength >> 48) .
                chr($dataLength >> 40) .
                chr($dataLength >> 32) .
                chr($dataLength >> 24) .
                chr($dataLength >> 16) .
                chr($dataLength >> 8) .
                chr($dataLength & 0xFF));
        }
        if ($isMasked) {
            $mask = chr(mt_rand(0, 0xFF)) .
                chr(mt_rand(0, 0xFF)) .
                chr(mt_rand(0, 0xFF)) .
                chr(mt_rand(0, 0xFF));
            $this->write($mask . $this->mask($data, $mask));
        } else {
            $this->write($data);
        }
        if ($cb !== null) {
            $this->onWriteOnce($cb);
        }
        return true;
    }
1210167
public boolean isBlock() {
		if (permissions != null
				&& (permissions.longValue() & SftpFileAttributes.S_IFBLK) == SftpFileAttributes.S_IFBLK) {
			return true;
		}
		return false;
	}
698054
function _initShell()
    {
        if ($this->in_request_pty_exec === true) {
            return true;
        }

        $this->window_size_server_to_client[self::CHANNEL_SHELL] = $this->window_size;
        $packet_size = 0x4000;

        $packet = pack(
            'CNa*N3',
            NET_SSH2_MSG_CHANNEL_OPEN,
            strlen('session'),
            'session',
            self::CHANNEL_SHELL,
            $this->window_size_server_to_client[self::CHANNEL_SHELL],
            $packet_size
        );

        if (!$this->_send_binary_packet($packet)) {
            return false;
        }

        $this->channel_status[self::CHANNEL_SHELL] = NET_SSH2_MSG_CHANNEL_OPEN;

        $response = $this->_get_channel_packet(self::CHANNEL_SHELL);
        if ($response === false) {
            return false;
        }

        $terminal_modes = pack('C', NET_SSH2_TTY_OP_END);
        $packet = pack(
            'CNNa*CNa*N5a*',
            NET_SSH2_MSG_CHANNEL_REQUEST,
            $this->server_channels[self::CHANNEL_SHELL],
            strlen('pty-req'),
            'pty-req',
            1,
            strlen('vt100'),
            'vt100',
            $this->windowColumns,
            $this->windowRows,
            0,
            0,
            strlen($terminal_modes),
            $terminal_modes
        );

        if (!$this->_send_binary_packet($packet)) {
            return false;
        }

        $response = $this->_get_binary_packet();
        if ($response === false) {
            user_error('Connection closed by server');
            return false;
        }

        if (!strlen($response)) {
            return false;
        }
        list(, $type) = unpack('C', $this->_string_shift($response, 1));

        switch ($type) {
            case NET_SSH2_MSG_CHANNEL_SUCCESS:
            // if a pty can't be opened maybe commands can still be executed
            case NET_SSH2_MSG_CHANNEL_FAILURE:
                break;
            default:
                user_error('Unable to request pseudo-terminal');
                return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
        }

        $packet = pack(
            'CNNa*C',
            NET_SSH2_MSG_CHANNEL_REQUEST,
            $this->server_channels[self::CHANNEL_SHELL],
            strlen('shell'),
            'shell',
            1
        );
        if (!$this->_send_binary_packet($packet)) {
            return false;
        }

        $this->channel_status[self::CHANNEL_SHELL] = NET_SSH2_MSG_CHANNEL_REQUEST;

        $response = $this->_get_channel_packet(self::CHANNEL_SHELL);
        if ($response === false) {
            return false;
        }

        $this->channel_status[self::CHANNEL_SHELL] = NET_SSH2_MSG_CHANNEL_DATA;

        $this->bitmap |= self::MASK_SHELL;

        return true;
    }
261266
public function handle(
        $msgType,
        \fpoirotte\Pssht\Wire\Decoder $decoder,
        \fpoirotte\Pssht\Transport $transport,
        array &$context
    ) {
        if ($this->connection !== null) {
            // Silently ignore subsequent authentication requests
            // after a successful authentication took place.
            return true;
        }

        $encoder    = new \fpoirotte\Pssht\Wire\Encoder();
        $user       = $decoder->decodeString();
        $service    = $decoder->decodeString();
        $method     = $decoder->decodeString();

        $encoder->encodeString($user);
        $encoder->encodeString($service);
        $encoder->encodeString($method);
        $decoder->getBuffer()->unget($encoder->getBuffer()->get(0));

        if (!isset($context['authMethods'])) {
            $context['authMethods']     = $this->methods;
        }

        if (!isset($context['banner'])) {
            $context['banner'] = (string) $transport->getBanner();
            if ($context['banner'] !== '') {
                $response = new \fpoirotte\Pssht\Messages\USERAUTH\BANNER($context['banner']);
                $transport->writeMessage($response);
            }
        }

        if (!isset($context['authMethods'][$method])) {
            return $this->failure($transport, $context);
        }

        $messagesCls = array(
            'none' =>
                '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\None',
            'hostbased' =>
                '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\HostBased',
            'password' =>
                '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\Password',
            'publickey' =>
                '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\PublicKey',
        );
        $methodObj  = $context['authMethods'][$method];
        $message    = $messagesCls[$method]::unserialize($decoder);

        switch ($methodObj->check($message, $transport, $context)) {
            case AuthenticationInterface::CHECK_IGNORE:
                return true;

            case AuthenticationInterface::CHECK_REJECT:
                return $this->failure($transport, $context);

            case AuthenticationInterface::CHECK_OK:
                break;

            default:
                throw new \RuntimeException();
        }

        switch ($methodObj->authenticate($message, $transport, $context)) {
            case AuthenticationInterface::AUTH_REMOVE:
                unset($context['authMethods'][$method]);
                // Do not break.

            case AuthenticationInterface::AUTH_REJECT:
                return $this->failure($transport, $context);

            case AuthenticationInterface::AUTH_ACCEPT:
                break;

            default:
                throw new \RuntimeException();
        }

        unset($context['authMethods'][$method]);
        $response = new \fpoirotte\Pssht\Messages\USERAUTH\SUCCESS();
        $this->connection = new \fpoirotte\Pssht\Connection($transport);
        $transport->writeMessage($response);

        $compressor = $transport->getCompressor();
        if ($compressor instanceof \fpoirotte\Pssht\DelayedCompressionInterface) {
            $compressor->setAuthenticated();
        }
        $uncompressor = $transport->getUncompressor();
        if ($uncompressor instanceof \fpoirotte\Pssht\DelayedCompressionInterface) {
            $uncompressor->setAuthenticated();
        }

        return true;
    }