Beispiel #1
0
 public function outputModel($oModel)
 {
     $flags = 0;
     //JSON_FORCE_OBJECT;
     if (phpversion() > '5.3.3') {
         $flags |= JSON_NUMERIC_CHECK;
     }
     if (phpversion() > '5.4.0') {
         $flags |= JSON_UNESCAPED_UNICODE;
         if (\vsc\isDebug()) {
             $flags |= JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES;
         }
     }
     if (ModelA::isValid($oModel)) {
         /* @var ModelA $oModel */
         $sOutput = json_encode($oModel->toArray(), $flags);
     } else {
         $sOutput = json_encode($oModel, $flags);
     }
     if (!json_last_error()) {
         return $sOutput;
     } else {
         throw new ExceptionView(json_last_error_msg());
     }
 }
Beispiel #2
0
 public function __construct()
 {
     if (!extension_loaded('dom')) {
         throw new ExceptionUnimplemented('The DOM extension is not loaded');
     }
     parent::__construct();
 }
Beispiel #3
0
 public function __get($sIncName = null)
 {
     try {
         $oProperty = new \ReflectionProperty($this, $sIncName);
         if ($oProperty->isPublic()) {
             return $oProperty->getValue($this);
         }
     } catch (\ReflectionException $e) {
         //
     }
     return parent::__get($sIncName);
 }
Beispiel #4
0
/* @var $this \vsc\presentation\views\JsonView  */
$aArray = $model->toArray();
$mEnd = end($aArray);
$sEndKey = key($aArray);
foreach ($aArray as $sName => $mValue) {
    if (is_scalar($mValue)) {
        StringUtils::_echo("\t", $GLOBALS['depth']);
        if (!is_int($sName)) {
            echo '"' . $sName . '": ';
        }
        echo '"' . StringUtils::stripEntities(str_replace('"', '\\"', $mValue)) . '"' . ($sName != $sEndKey ? ',' : '') . "\n";
        continue;
    } elseif (is_array($mValue)) {
        $mValue = new ArrayModel($mValue);
    }
    if (ModelA::isValid($mValue)) {
        $this->setModel($mValue);
        StringUtils::_echo("\t", $GLOBALS['depth']);
        echo '"' . $sName . '": ';
        echo '{' . "\n";
        $GLOBALS['depth']++;
        echo $this->fetch(__FILE__);
        StringUtils::_echo("\t", $GLOBALS['depth'] - 1);
        echo '}' . ($sName != $sEndKey && $mEnd != $mValue ? ',' : '') . "\n";
        $GLOBALS['depth']--;
        continue;
    }
    StringUtils::_echo("\t", $GLOBALS['depth']);
    echo '"' . $sName . '" : ';
    echo '"' . var_export($mValue, true) . '"' . ($sName != $sEndKey ? ',' : '') . "\n";
}
 /**
  * @param bool $bAll
  * @return array
  */
 public function getPropertyNames($bAll = false)
 {
     return parent::getPropertyNames($bAll);
 }
Beispiel #6
0
 /**
  * recursively transform all properties into arrays
  */
 public function toArray()
 {
     return parent::toArray();
 }
Beispiel #7
0
 /**
  * @param bool $bIncludeNonPublic
  * @return array
  */
 public function getProperties($bIncludeNonPublic = false)
 {
     return parent::getProperties($bIncludeNonPublic);
 }
Beispiel #8
0
 public function __construct(\Exception $e)
 {
     $this->setException($e);
     parent::__construct();
 }
Beispiel #9
0
 /**
  * @throws ExceptionView
  * @returns ModelA
  */
 public function getModel()
 {
     if (ModelA::isValid($this->oModel)) {
         return $this->oModel;
     } else {
         return new Base();
     }
 }
Beispiel #10
0
 /**
  * recursively transform all properties into arrays
  */
 public function toArray()
 {
     $aRet = array();
     $aProperties = $this->getProperties();
     foreach ($aProperties as $sName => $oProperty) {
         if (ModelA::isValid($oProperty)) {
             /* @var ModelA $oProperty */
             $aRet[$sName] = $oProperty->toArray();
         } elseif (is_array($oProperty) || is_scalar($oProperty)) {
             $aRet[$sName] = $oProperty;
         } elseif (is_null($oProperty)) {
             $aRet[$sName] = $oProperty;
         } else {
             $aRet[$sName] = var_export($oProperty, true);
         }
     }
     return $aRet;
 }
Beispiel #11
0
 public function getCurrent()
 {
     return parent::getCurrent();
 }
Beispiel #12
0
 /**
  * @param HttpRequestA $oRequest
  * @param ProcessorA $oProcessor
  * @throws ExceptionPath
  * @throws ExceptionResponse
  * @throws ExceptionView
  * @returns HttpResponseA
  */
 public function getResponse(HttpRequestA $oRequest, $oProcessor = null)
 {
     $oResponse = vsc::getEnv()->getHttpResponse();
     $oModel = null;
     /* @var ControllerMap $oMyMap */
     $oMyMap = $this->getMap();
     if (ProcessorA::isValid($oProcessor)) {
         try {
             $oProcessor->init();
             $oModel = $oProcessor->handleRequest($oRequest);
         } catch (ExceptionResponseRedirect $e) {
             $oResponse->setStatus($e->getRedirectCode());
             $oResponse->setLocation($e->getLocation());
             return $oResponse;
         } catch (\Exception $e) {
             // we had error in the controller
             // @todo make more error processors
             return $this->getErrorResponse($e, $oRequest);
         }
     }
     if ($oResponse->getStatus() == 0) {
         $oResponse->setStatus(HttpResponseType::OK);
     }
     // we didn't set any special view
     // this means that the developer needs to provide his own views
     $oView = $this->getView();
     $oMap = null;
     if (ProcessorA::isValid($oProcessor)) {
         /* @var ProcessorMap $oMap */
         $oMap = $oProcessor->getMap();
         if (MappingA::isValid($oMap)) {
             if (MappingA::isValid($oMyMap)) {
                 $oMap->merge($oMyMap);
             }
             $oProcessorResponse = $oMap->getResponse();
             if (HttpResponseA::isValid($oProcessorResponse)) {
                 $oResponse = $oProcessorResponse;
             }
         }
         // setting the processor map
         $oView->setMap($oMap);
     }
     try {
         if ((ProcessorMap::isValid($oMap) || ClassMap::isValid($oMap)) && !$oMap->isStatic() && !$oMyMap->isStatic() && (ControllerMap::isValid($oMyMap) || ClassMap::isValid($oMyMap))) {
             $oView->setMainTemplate($oMyMap->getMainTemplatePath() . $oView->getViewFolder() . DIRECTORY_SEPARATOR . $oMyMap->getMainTemplate());
         }
     } catch (ExceptionPath $e) {
         // fallback to html5
         // @todo verify main template path and main template exist
         $oView->setMainTemplate($oMyMap->getMainTemplatePath() . DIRECTORY_SEPARATOR . 'html5' . DIRECTORY_SEPARATOR . $oMyMap->getMainTemplate());
     }
     if (!ModelA::isValid($oModel)) {
         $oModel = new EmptyModel();
         if (!ProcessorMap::isValid($oMap) || $oMap->getTitle() == '') {
             $oModel->setPageTitle('Warning');
         }
         $oModel->setPageContent('Warning: the processor didn\'t return a valid model. This is probably an error');
     }
     $oView->setModel($oModel);
     $oResponse->setView($oView);
     if (MappingA::isValid($oMap)) {
         $aHeaders = $oMap->getHeaders();
         if (count($aHeaders) > 0) {
             foreach ($aHeaders as $sName => $sHeader) {
                 $oResponse->addHeader($sName, $sHeader);
             }
         }
         $iProcessorSetStatus = $oMap->getResponseStatus();
         if (HttpResponseType::isValidStatus($iProcessorSetStatus)) {
             $oResponse->setStatus($iProcessorSetStatus);
         }
     }
     return $oResponse;
 }