/** * 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; }
* limitations under the License. * */ require '../../vendor/autoload.php'; use BOTK\Core\EndPointFactory, BOTK\Core\ErrorManager; // Control errors use Geocodit\View\GoogleAnalyticsEnabledRenderer; // for CSS use BOTK\Context\Context; // get config vars and other inputs use BOTK\Context\ContextNameSpace as CX; // search configs files in in config and /etc/geocodit directories if (!isset($_ENV['BOTK_CONFIGDIR'])) { if (file_exists(__DIR__ . '/../../config/geocodit.ini')) { $_ENV['BOTK_CONFIGDIR'] = realpath(__DIR__ . '/../../config'); } elseif (is_dir('/etc/geocodit')) { $_ENV['BOTK_CONFIGDIR'] = '/etc/geocodit'; } } // Enable Universal Analytics code $UA = Context::factory()->ns('geocodit')->getValue('UA', CX::NULL_AS_DEFAULT); GoogleAnalyticsEnabledRenderer::$UniversalAnalyticsId = $UA; // Enable the catching of PHP errors $errorManager = ErrorManager::getInstance()->registerErrorHandler(); try { $endpoint = EndPointFactory::make('Geocodit\\ApiEndpoint'); $result = $endpoint->run(); } catch (Exception $e) { $result = ErrorManager::getInstance()->render($e); } echo $result;
/** * @expectedException \ErrorException */ public function testErrorExceptions() { $errorManager = ErrorManager::getInstance()->registerErrorHandler(); $x = $y + 1; // trigger notice }
/** * This example shows how to use content management policies for a RDF source. * It reads sample.ttl turtle file and renders it in all RDF serialization + html. */ require '../vendor/autoload.php'; use BOTK\Core\EndPoint, BOTK\Core\Controller, BOTK\Core\EndPointFactory, BOTK\Core\ErrorManager; use BOTK\RDF\Representations\RDF; use EasyRdf_Graph as Graph; class Router extends EndPoint { protected function setRoutes() { $this->get('/', 'sampleManager')->accept(RDF::renderers()); } } class sampleManager extends Controller { public function get() { $graph = new Graph(); $graph->parseFile('sample.ttl'); return $graph; } } $errorManager = ErrorManager::getInstance()->registerErrorHandler(); try { echo EndPointFactory::make('Router')->run(); } catch (Exception $e) { echo $errorManager->render($e); }
{ return "{$this->greeting} {$this->to}"; } } /* This class implements MVC View */ class GreetingRepresentation extends Standard { } /* This class implements MVC Controller for Resource*/ class HelloworldController extends Controller { public function get($to = 'World') { return $this->stateTransfer($hello = new Greeting($to), WebLink::factory($hello->by)->rel('next')); } } /* This class implements MVC Controller for End-Point*/ class Helloworld extends EndPoint { protected function setRoutes() { $this->get('/*', new HelloworldController())->accept(GreetingRepresentation::renderers())->through($this->representationCachingProcessor(Caching::SHORT)); } } //uncomment above to use your css: //Standard::$htmlMetadata = 'http://www.w3.org/StyleSheets/Core/parser.css?family=6&doc=XML'; try { echo EndPointFactory::make('Helloworld')->run(); } catch (Exception $e) { echo ErrorManager::getInstance()->render($e); }