示例#1
0
<?php

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use Hoa\Exception;
use Hoa\Dispatcher;
use Hoa\Router;
Exception\Error::enableErrorHandler();
Exception\Idle::enableUncaughtHandler();
$dispatcher = new Dispatcher\ClassMethod(['synchronous.call' => 'Application\\Resource\\(:call:U:)', 'synchronous.able' => '(:%variables._method:U:)', 'asynchronous.call' => '(:%synchronous.call:)', 'asynchronous.able' => '(:%synchronous.able:)']);
$router = new Router\Http();
$router->_get('_resource', '/Static/(?<resource>)')->get('dates', '/api/dates(?:/(?<limit>\\d+))?', 'Dates')->get('discography', '/api/discography', 'Discography')->get('album', '/api/album/(?<albumId>.+)', 'Album')->get('videos', '/api/videos', 'Videos')->get('fallback', '/.*', 'Fallback');
$dispatcher->dispatch($router);
示例#2
0
文件: Xyl.php 项目: Grummfy/Central
 /**
  * Interprete a stream as XYL.
  *
  * @param   \Hoa\Stream\IStream\In     $in              Stream to interprete
  *                                                      as XYL.
  * @param   \Hoa\Stream\IStream\Out    $out             Stream for rendering.
  * @param   \Hoa\Xyl\Interpreter       $interpreter     Interpreter.
  * @param   \Hoa\Router\Http           $router          Router.
  * @param   mixed                      $entityResolver  Entity resolver.
  * @param   array                      $parameters      Parameters.
  * @return  void
  * @throws  \Hoa\Xyl\Exception
  * @throws  \Hoa\Xml\Exception
  * @throws  \Hoa\Xml\Exception\NamespaceMissing
  */
 public function __construct(Stream\IStream\In $in, Stream\IStream\Out $out, Interpreter $interpreter, Router\Http $router = null, $entityResolver = null, array $parameters = [])
 {
     parent::__construct('\\Hoa\\Xyl\\Element\\Basic', $in, true, $entityResolver);
     if (false === $this->namespaceExists(self::NAMESPACE_ID)) {
         throw new Exception('The XYL file %s has no XYL namespace (%s) declared.', 0, [$in->getStreamName(), self::NAMESPACE_ID]);
     }
     if (null === self::$_parameters) {
         self::$_parameters = new Core\Parameter($this, ['theme' => 'classic'], ['theme' => '(:theme:lU:)']);
         $this->getParameters()->setParameters($parameters);
     }
     $this->_i = self::$_ci++;
     $this->_data = new Core\Data();
     $this->_out = $out;
     $this->_interpreter = $interpreter;
     $this->_router = $router;
     $this->_mowgli = $this->getStream()->readDOM()->ownerDocument;
     switch (strtolower($this->getName())) {
         case 'document':
             $this->_type = self::TYPE_DOCUMENT;
             break;
         case 'definition':
             $this->_type = self::TYPE_DEFINITION;
             break;
         case 'overlay':
             $this->_type = self::TYPE_OVERLAY;
             break;
         case 'fragment':
             $this->_type = self::TYPE_FRAGMENT;
             break;
         default:
             throw new Exception('Unknown document <%s>.', 1, $this->getName());
     }
     $this->useNamespace(self::NAMESPACE_ID);
     $protocol = Core::getInstance()->getProtocol();
     $protocol['Library'][] = new _Protocol('Xyl[' . $this->_i . ']', 'Xyl' . DS . 'Interpreter' . DS . $this->_interpreter->getResourcePath());
     if (null !== $router && false === $router->ruleExists('_resource')) {
         $router->_get('_resource', '/(?<theme>)/(?<resource>)');
     }
     return;
 }