AppserverIo\Appserver\ServletEngine\RequestHandler::getApplicationContext PHP Method

getApplicationContext() public static method

Returns the actual application instance thatrepresents the application context of this request.
public static getApplicationContext ( ) : AppserverIo\Psr\Application\ApplicationInterface
return AppserverIo\Psr\Application\ApplicationInterface The actual application context
    public static function getApplicationContext()
    {
        return RequestHandler::$applicationContext;
    }

Usage Example

 /**
  * JSON encodes the passed content and returns it.
  *
  * @param mixed $content The content to be JSON encoded
  *
  * @return \AppserverIo\Apps\Api\TransferObject\EncodedViewData The DTO with the encoded content
  */
 public function encode($content)
 {
     // load the application instance
     $application = RequestHandler::getApplicationContext();
     // this is necessary to load the PSR-4 compatible Swagger library
     \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(function ($className) use($application) {
         // load the application directory
         $webappPath = $application->getWebappPath();
         $shortName = str_replace("Swagger\\Annotations\\", DIRECTORY_SEPARATOR, $className);
         // prepare the annotation filename for the Swagger annotations
         $file = sprintf('%s/vendor/zircote/swagger-php/src/Annotations/%s.php', $webappPath, $shortName);
         // query whether the file exists or not
         if (file_exists($file)) {
             require $file;
             return class_exists($className);
         }
         // return FALSE if the class can't be loaded
         return false;
     });
     // serialize the passed content
     return new EncodedViewData($this->getContentType(), SerializerBuilder::create()->build()->serialize($content, 'json'));
 }
All Usage Examples Of AppserverIo\Appserver\ServletEngine\RequestHandler::getApplicationContext