예제 #1
0
 /**
  * write logs
  *
  * @param  string $type
  * @param  string $message
  * @throws RuntimeException if failed to create log-dir
  * @throws RuntimeException if log-file exists & is dir or link
  */
 protected static function log($type, $message)
 {
     $now = new DateTime();
     # create dir
     $logFile = new File(self::LOG_DIR . $now->format('Y-M'));
     if (!$logFile->isDir()) {
         $logFile->makeDir();
     }
     # check file
     $logFile->attach($now->format('d') . '.log');
     if (!$logFile->isFile() && $logFile->exists()) {
         throw new RuntimeException('log-file is not a file `' . $logFile . '`');
     }
     # write log
     $time = $now->format('H:i:s');
     $logFile->putContents('[' . $type . ' @ ' . $time . '] ' . $message . PHP_EOL);
 }
예제 #2
0
 /**
  * @see    AbstractModeHandler::handle
  * @throws RuntimeException
  * @return SiteModeHandler this
  */
 public function handle()
 {
     $className = ucfirst($this->request->getPage()) . 'Page';
     $nameSpace = 'area\\' . $this->request->getArea() . '\\logic\\site\\' . $className;
     $styleSheet = new File('private/src/area/' . $this->request->getArea() . '/app/view/site/' . $this->request->getPage() . '.xsl');
     if (!class_exists($nameSpace)) {
         $reason404 = 'class `' . $nameSpace . '`';
     } elseif (!$styleSheet->isFile()) {
         $reason404 = 'stylesheet `' . $styleSheet . '`';
     }
     if (isset($reason404)) {
         Logger::debug('HTTP-404 because: ' . $reason404 . ' not found');
         return $this->error(404);
     }
     $formStatus = $this->getFormStatus();
     if ($formStatus === null) {
         $requestData = $_POST;
     } else {
         $requestData = array();
     }
     $page = new $nameSpace($this->config, $requestData);
     if (!$page instanceof AbstractSitePage) {
         throw new RuntimeException('class `' . $nameSpace . '` isn\'t instance of `' . AbstractSitePage::class . '`');
     }
     if ($page->access() !== true) {
         return $this->error(403);
     }
     if ($formStatus !== null) {
         if ($formStatus === AbstractSitePage::STATUS_RESTORED) {
             foreach ($this->getStoredFormData() as $name => $value) {
                 $page->setFormData($name, $value);
             }
         }
         $page->setUp();
     } else {
         if ($page->checkExpectation() === true && $page->check() === true) {
             $formStatus = AbstractSitePage::STATUS_ACCEPTED;
             $this->closeStoredForm($requestData['formId']);
         } else {
             $formStatus = AbstractSitePage::STATUS_REJECTED;
             $this->saveForm($requestData);
         }
     }
     $page->formData->setAttribute('status', $formStatus);
     $page->response->getRootNode()->addChild($this->getTextNode());
     echo (new XSLProcessor())->setStyleSheetFile($styleSheet)->setDocumentDoc($page->response->toDomDoc())->transform();
     # output: XML-Tree into temporary File
     if (isset($this->settings['tempXMLFile']) && $this->settings['tempXMLFile'] === true) {
         $xmlFile = new File(self::PATH_TEMP_XML);
         $xmlFile->putContents($page->response->getSource(true), false);
     }
     return $this;
 }