How it works:
Router w/Static HTML Limitations:
Overview:
The Router integration method:
The route should be placed at the end of other application routes.
Integration:
composer require apharmony/jsharmony-cms-sdk-php
* Be sure to update the "content_path" property to match the CMS files publish folder in your Zend / Laminas project
<?php
namespace App\Handler;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\RedirectResponse;
use Laminas\Diactoros\Response\TextResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use apHarmony\jsHarmonyCms\CmsRouter;
class jsHarmonyCmsHandler implements RequestHandlerInterface
{
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$url = $request->getAttribute('url');
// Initialize the jsHarmony CMS Router
$cmsRouter = new CmsRouter([
"redirect_listing_path" => "jshcms_redirects.json",
"cms_server_urls" => ["https://cms.example.com/"],
"content_path" => $_SERVER['DOCUMENT_ROOT']."/path/to/published_files"
]);
return $cmsRouter->serve($url, [
'onPage' => function($router, $fileName){
return new HtmlResponse($router->getFile($fileName));
},
'on301' => function($router, $url){
return new RedirectResponse($url, 301);
},
'on302' => function($router, $url){
return new RedirectResponse($url, 302);
},
'onPassthru' => function($router, $url){
$passthru = $router->passthru($url);
return new TextResponse($passthru->content, $passthru->http_code, ['Content-Type' => $passthru->content_type]);
},
'on404' => function($route){
return new TextResponse('Page not found.', 404);
},
]);
}
}
$app->get('/{url:.*}', App\Handler\jsHarmonyCmsHandler::class, 'jsharmonycms');
<script type="text/javascript" class="removeOnPublish" src="/.jsHarmonyCms/jsHarmonyCmsEditor.js"></script>
<script type="text/javascript" class="removeOnPublish">
jsHarmonyCmsEditor({"access_keys":["****ACCESS_KEY*****"]});
</script>
* Be sure to keep the "removeOnPublish" class in the Launcher script tags, so that the Launcher will not be included in the published pages