public static function getApplicationContext() { return RequestHandler::$applicationContext; }
/** * 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')); }