/**
  * Create and Endpoint and setup auto virtualhost
  */
 public static function make($endPointClass = null, $virtualhost = null)
 {
     $baseEndPointClassName = '\\BOTK\\Core\\EndPoint';
     if (!$endPointClass) {
         $endPointClass = $baseEndPointClassName;
     }
     if ($endPointClass != $baseEndPointClassName && !is_subclass_of($endPointClass, $baseEndPointClassName)) {
         throw new HttpErrorException(HttpProblem::factory(500, 'Unable to create endpoint', "{$endPointClass} is not and EndPoint class"));
     }
     return new $endPointClass($virtualhost);
 }
示例#2
0
 /**
  * Redefine run taking into account mountend end points
  */
 public function run(Request $request = null)
 {
     $endPointName = $this->getEndPointName();
     $applicationPath = $this->getEndPointPath();
     $routerClass = $endPointName && isset($this->endPointCatalog[$endPointName]) ? $this->endPointCatalog[$endPointName] : '';
     $virtualhost = empty($endPointName) ? $applicationPath : $applicationPath . '/' . $endPointName;
     if (!$routerClass) {
         $result = parent::run($request);
         //fall back to local application routing
     } else {
         // now we test that $routerclass is a valid end_point
         $myClass = get_class();
         if ($routerClass == $myClass || is_subclass_of($routerClass, $myClass)) {
             // Create new end-point
             $endpoint = new $routerClass($virtualhost);
             $result = $endpoint->run();
         } else {
             throw new HttpErrorException(HttpProblem::factory(500, 'Invalid endpoint', $routerClass . ' end point class is not a subClass of ' . $myClass));
         }
     }
     //now prepare an error report for humans when something went wrong
     //Warning this trigger is called only in php >5.4. Otherwhise just empty content is printed
     //(but original status is preserved)
     if (empty($result) && ($errorCode = Http::getHttpResponseCode()) >= 400) {
         $result = ErrorManager::getInstance()->serializeHttpProblem(new HttpProblem($errorCode));
     }
     return $result;
 }