Esempio n. 1
0
 public function testSetGetMap()
 {
     $s = new ControllerMap(GenericFrontController::class, '\\A.*\\Z');
     $this->state->setMap($s);
     $m = $this->state->getMap();
     $this->assertInstanceOf(MappingA::class, $m);
     $this->assertInstanceOf(ControllerMap::class, $m);
     $this->assertEquals($s, $m);
 }
Esempio n. 2
0
 public function testIsValid()
 {
     $TestVar = new Base();
     $this->assertTrue(Base::isValid($TestVar));
     $this->assertTrue(Object::isValid($TestVar));
     $TestVar = new RESTProcessorA_underTest_isValid();
     $this->assertTrue(RESTProcessorA_underTest_isValid::isValid($TestVar));
     $this->assertTrue(RESTProcessorA::isValid($TestVar));
     $this->assertTrue(ProcessorA::isValid($TestVar));
     $this->assertTrue(Object::isValid($TestVar));
     $TestVar = new ProcessorA_underTest_isValid();
     $this->assertTrue(ProcessorA_underTest_isValid::isValid($TestVar));
     $this->assertTrue(ProcessorA::isValid($TestVar));
     $this->assertTrue(Object::isValid($TestVar));
     $TestVar = new RESTController();
     $this->assertTrue(RESTController::isValid($TestVar));
     $this->assertTrue(FrontControllerA::isValid($TestVar));
     $this->assertTrue(Object::isValid($TestVar));
     $TestVar = new FrontControllerA_underTest_isValid();
     $this->assertTrue(FrontControllerA_underTest_isValid::isValid($TestVar));
     $this->assertTrue(FrontControllerA::isValid($TestVar));
     $this->assertTrue(Object::isValid($TestVar));
     $TestVar = new ModelA_underTest_isValid();
     $this->assertTrue(ModelA_underTest_isValid::isValid($TestVar));
     $this->assertTrue(ModelA::isValid($TestVar));
 }
Esempio n. 3
0
 /**
  * @param HttpRequestA $oRequest
  * @param ProcessorA $oProcessor
  * @returns HttpResponseA
  */
 public function getResponse(HttpRequestA $oRequest, $oProcessor = null)
 {
     $oResponse = parent::getResponse($oRequest, $oProcessor);
     if (!($oResponse->isRedirect() || $oResponse->isError())) {
         $iExpireTime = 600;
         // ten minute
         $oNow = new \DateTime('now', new \DateTimeZone('GMT'));
         $oResponse->setDate($oNow->format('r'));
         try {
             $oModel = $this->getView()->getModel();
         } catch (ExceptionView $v) {
             $oModel = null;
         }
         if (CacheableModelA::isValid($oModel)) {
             try {
                 /** @var CacheableModelA $oModel */
                 $sLastModified = $oModel->getLastModified();
                 $oLastModified = new \DateTime($sLastModified, new \DateTimeZone('GMT'));
                 $oResponse->setLastModified($oLastModified->format('r'));
                 $oMax = $oLastModified->getTimestamp() > $oNow->getTimestamp() ? $oLastModified : $oNow;
                 $sModifiedSince = $oRequest->getIfModifiedSince();
                 if (!empty($sModifiedSince)) {
                     $oModifiedSince = new \DateTime($sModifiedSince, new \DateTimeZone('GMT'));
                     if ($oLastModified->getTimestamp() <= $oModifiedSince->getTimestamp()) {
                         $oResponse->setStatus(HttpResponseType::NOT_MODIFIED);
                     }
                 }
             } catch (\Exception $e) {
                 $oMax = $oNow;
             }
             $oResponse->setExpires($oMax->add(new \DateInterval('P2W'))->format('r'));
             // adding 2 weeks
         } else {
             try {
                 $oResponse->setETag(substr(sha1($oResponse->getOutput()), 0, 8));
                 $oResponse->setCacheControl('public, max-age=' . $iExpireTime);
             } catch (ExceptionView $v) {
                 //
             }
             if ($oRequest->getIfNoneMatch() == '"' . $oResponse->getETag() . '"') {
                 $oResponse->setStatus(HttpResponseType::NOT_MODIFIED);
             }
         }
     }
     return $oResponse;
 }
Esempio n. 4
0
 /**
  * @throws \vsc\application\sitemaps\ExceptionSitemap
  * @throws \vsc\presentation\responses\ExceptionResponseError
  * @returns FrontControllerA
  */
 public function getFrontController()
 {
     if (!FrontControllerA::isValid($this->oController)) {
         $oControllerMapping = $this->getCurrentControllerMap();
         if (ControllerMap::isValid($oControllerMapping)) {
             $sPath = $oControllerMapping->getPath();
             if ($this->getSiteMap()->isValidObjectPath($sPath)) {
                 include $sPath;
                 $sControllerName = SiteMapA::getClassName($sPath);
             }
         }
         if (ClassMap::isValid($oControllerMapping)) {
             $sControllerName = $oControllerMapping->getPath();
         }
         if (empty($sControllerName)) {
             throw new ExceptionResponseError('Could not find the correct front controller', HttpResponseType::NOT_FOUND);
         }
         /* @var $this->oController FrontControllerA */
         $this->oController = new $sControllerName();
         if (FrontControllerA::isValid($this->oController)) {
             // adding the map to the controller, allows it to add resources (styles,scripts) from inside it
             $this->oController->setMap($oControllerMapping);
         }
     }
     //		d ($oControllerMapping);
     return $this->oController;
 }