Beispiel #1
0
 /**
  * Implement's module logic for given hook
  *
  * @param \TechDivision\Connection\ConnectionRequestInterface     $request        A request object
  * @param \TechDivision\Connection\ConnectionResponseInterface    $response       A response object
  * @param \TechDivision\Server\Interfaces\RequestContextInterface $requestContext A requests context instance
  * @param int                                                     $hook           The current hook to process logic for
  *
  * @return bool
  * @throws \TechDivision\Server\Exceptions\ModuleException
  */
 public function process(ConnectionRequestInterface $request, ConnectionResponseInterface $response, RequestContextInterface $requestContext, $hook)
 {
     /** @var $request \TechDivision\Http\HttpRequestInterface */
     /** @var $request \TechDivision\Http\HttpRequestInterface */
     // if false hook is comming do nothing
     if (ModuleHooks::REQUEST_POST !== $hook) {
         return;
     }
     // check if core module should still handle this request
     // maybe later on this can be overwritten by another core module for some reasons
     if ($requestContext->getServerVar(ServerVars::SERVER_HANDLER) !== self::MODULE_NAME) {
         // stop processing
         return;
     }
     $this->populateRequestContext($requestContext);
     // check if core module should still handle this request
     if ($requestContext->getServerVar(ServerVars::SERVER_HANDLER) !== self::MODULE_NAME) {
         // stop processing
         return;
     }
 }
Beispiel #2
0
 /**
  * Implement's module logic for given hook
  *
  * @param \TechDivision\Connection\ConnectionRequestInterface     $request        A request object
  * @param \TechDivision\Connection\ConnectionResponseInterface    $response       A response object
  * @param \TechDivision\Server\Interfaces\RequestContextInterface $requestContext A requests context instance
  * @param int                                                     $hook           The current hook to process logic for
  *
  * @return bool
  * @throws \TechDivision\Server\Exceptions\ModuleException
  */
 public function process(ConnectionRequestInterface $request, ConnectionResponseInterface $response, RequestContextInterface $requestContext, $hook)
 {
     /** @var $request \TechDivision\Http\HttpRequestInterface */
     /** @var $request \TechDivision\Http\HttpRequestInterface */
     // if false hook is comming do nothing
     if (ModuleHooks::REQUEST_POST !== $hook) {
         return false;
     }
     // check if correct file handler was set for this module to process
     if ($requestContext->getServerVar(ServerVars::SERVER_HANDLER) !== self::MODULE_NAME) {
         // stop processing
         return false;
     }
     // just if method is POST
     if ($request->getMethod() === HttpProtocol::METHOD_POST) {
         // prepare vars
         $documentRoot = $requestContext->getServerVar(ServerVars::DOCUMENT_ROOT);
         $scriptName = $requestContext->getServerVar(ServerVars::SCRIPT_NAME);
         $logDir = dirname($scriptName);
         $filename = basename($scriptName);
         $baseDir = $documentRoot . $logDir;
         $filepath = $baseDir . DIRECTORY_SEPARATOR . $filename;
         // check if base dir exists
         if (!is_dir($baseDir)) {
             // create it recursively
             mkdir($baseDir, 0775, true);
         }
         // open file handle to log file
         $fileHandle = fopen($filepath, 'a+');
         // write to file
         fwrite($fileHandle, $request->getBodyContent());
         // set response state to be dispatched after this without calling other modules process
         $response->setState(HttpResponseStates::DISPATCH);
     }
 }