Пример #1
0
 public static function resolve(Site $site, $url)
 {
     $matches = array();
     if ($url == 'test') {
         $cms = $site->modules->get('CMS');
         $oldPath = CurrentPath::set($cms->getDir());
         $prefix = $cms->getPrefix();
         try {
             $page = new HTMLPage($site, null, "{$prefix}/cmstest.html", array('cms' => $cms));
         } catch (Exception $e) {
             CurrentPath::set($oldPath);
             throw $e;
         }
         CurrentPath::set($oldPath);
         return $page;
     } elseif (!preg_match('~^(page|node)/(\\w+)(?:/(.+))?$~', $url, $matches)) {
         return null;
     }
     try {
         $what = $matches[1];
         $action = $matches[2];
         if (count($matches) > 3) {
             $extra = $matches[3];
         } else {
             $extra = null;
         }
         return new self($site, $what, $action, $extra);
     } catch (BadMethodCallException $e) {
         return null;
     }
 }
Пример #2
0
 public function draw()
 {
     $oldPath = CurrentPath::set(dirname(__FILE__));
     $template = new Template('view/view.xml');
     print $template->render(array('payment' => $this));
     CurrentPath::set($oldPath);
 }
Пример #3
0
 /**
  * Restores the application path after template is rendered.
  */
 protected function renderCleanup()
 {
     parent::renderCleanup();
     if (isset($this->currentPath)) {
         CurrentPath::set($this->oldAppPath);
     }
 }
Пример #4
0
 /**
  * Sets the current->path. A relative or absolute path
  * may be used.
  *
  * @static
  * @access public
  * @param string $path the value current->path should be set to
  * @return string the old value of current->path
  */
 public static function set($path)
 {
     if (isset($path)) {
         if (is_string($path) || $path instanceof StupidPath) {
             $path = new self($path);
         } elseif (!$path instanceof CurrentPath) {
             throw new InvalidArgumentException('Invalid path');
         }
     }
     $oldPath = self::$current;
     self::$current = $path;
     return $oldPath;
 }
Пример #5
0
 /**
  * Implements the perform
  *
  * @param ActionDescription $action
  * @param int $stage
  * @return boolean, null on permission denied
  */
 public function perform(ActionDescription &$action, $stage)
 {
     $oldPath = CurrentPath::set($this->getPath());
     $handler = is_string($action->handler) ? array($this, $action->handler) : $action->handler;
     $returnValue = call_user_func($handler, $stage);
     CurrentPath::set($oldPath);
     return $returnValue;
 }
Пример #6
0
 /**
  * Handling process:
  *   dispatch: onParseUrl      }-> caught Exception
  *   dispatch: onAccessCheck     |-> dispatch: onException
  *   dispatch: onRequestStart    |
  *   dispatch: onSendResponse  }---> caught SiteRedirectException
  *   dispatch: onResponseSent    | |-> redirect
  *   cleanup <-------------------/-/
  *
  * At any point in the process, a thrown exception will cause 'onException'
  * to be dispatched, if that generates no output, then the exception is
  * simply printed in a minimal html document. After the onException, normal cleanup is done
  *
  * @return void
  * @see parseUrl
  */
 public final function handle()
 {
     $args = array_slice(func_get_args(), 1);
     try {
         ob_start();
         CurrentPath::set(Loader::$Base);
         $this->parseUrl(Params::server('REQUEST_URI'));
         $this->log->info(sprintf('==> Framework v%s: New Request from %s - %s <==', Loader::$FrameworkVersion, Params::server('REMOTE_ADDR'), $this->requestUrl));
         $this->dispatchCallback('onAccessCheck', $this);
         $this->dispatchCallback('onRequestStart', $this);
         $this->dispatchCallback('onSendResponse', $this);
         $this->dispatchCallback('onResponseSent', $this);
         ob_end_flush();
     } catch (SiteRedirectException $r) {
         ob_end_clean();
         header("Location: {$r->url}");
     }
     $this->cleanup();
 }
 protected function createTemplate($resource, $data, $identifier = null)
 {
     return parent::createTemplate($resource, $data, 'file://' . CurrentPath::get() . '/' . $resource);
 }
 /**
  * Adds assets to the page
  *
  * Expects child elements like:
  *   <script href="some.js" />
  *   <stylesheet href="some.css" />
  *   <link href="some/resource" rel="something" type="some/mime" />
  *   <alternate href="some.rss" type="application/rss+xml" title="RSS Feed" />
  *
  * If any href is a simple string (i.e. no ${...} expression), and it is
  * relative, it will be passed to CurrentPath->url->down to form an
  * absolute url.
  *
  * Full gory attribute details:
  *   script: a HTMLPageScript asset
  *     href string required
  *     type string optional default 'text/javascript'
  *
  *   stylesheet: a HTMLPageStylesheet asset
  *     href      string  required
  *     alternate boolean optional default false
  *     title     string  optional default null
  *     media     string  optional default null
  *
  *   alternate: a HTMLPageAlternateLink asset
  *     href  string required
  *     type  string required
  *     title string optional default null
  *
  *   link: a HTMLPageLinkedResource asset
  *     href  string required
  *     rel   string required
  *     type  string required
  *     title string optional default null
  *
  * @param DOMElement element the tag such as <ui:pageBuffer />
  * @return void
  */
 public function handleElementAddAssets(DOMElement $element)
 {
     if ($element->hasAttribute('base')) {
         $base = 'new StupidPath(' . $this->getAttr($element, 'base') . ')';
     } else {
         $base = 'CurrentPath::get()->url';
     }
     $this->compiler->write("<?php if (! \$page instanceof HTMLPage) {\n" . "  throw new RuntimeException('Can only add html assets to an html page');\n" . '} ?>');
     $assets = array();
     $baseVar = '$__base' . uniqid();
     foreach ($element->childNodes as $n) {
         if ($n->nodeType == XML_ELEMENT_NODE) {
             $href = $this->requiredAttr($n, 'href');
             $path = CurrentPath::get();
             $href = "(string) {$baseVar}->rel2abs({$href})";
             switch ($n->tagName) {
                 case 'script':
                     $asset = array('HTMLPageScript', $href);
                     $type = $this->getAttr($n, 'type');
                     if (isset($type)) {
                         array_push($asset, $type);
                     }
                     break;
                 case 'stylesheet':
                     $alt = $this->getBooleanAttr($n, 'alternate');
                     $title = $this->getAttr($n, 'title');
                     $media = $this->getAttr($n, 'media');
                     $asset = array('HTMLPageStylesheet', $href);
                     array_push($asset, $alt ? 'true' : 'false');
                     if (isset($title)) {
                         array_push($asset, $title);
                     } elseif (isset($media)) {
                         array_push($asset, 'null');
                     }
                     if (isset($media)) {
                         array_push($asset, $media);
                     }
                     break;
                 case 'link':
                     $rel = $this->requiredAttr($n, 'rel');
                     $type = $this->requiredAttr($n, 'type');
                     $title = $this->getAttr($n, 'title');
                     $asset = array('HTMLPageLinkedResource', $href, $type, $rel);
                     if (isset($title)) {
                         array_push($asset, $title);
                     }
                     break;
                 case 'alternate':
                     $type = $this->requiredAttr($n, 'type');
                     $title = $this->getAttr($n, 'title');
                     $asset = array('HTMLPageAlternateLink', $href, $type);
                     if (isset($title)) {
                         array_push($asset, $title);
                     }
                     break;
                 default:
                     throw new RuntimeException('Unknown asset element ' . $n->tagName);
             }
             array_push($assets, sprintf('new %s(%s)', array_shift($asset), implode(', ', $asset)));
         }
     }
     if (count($assets)) {
         $buffer = '';
         foreach ($assets as $asset) {
             $buffer .= "\$page->addAsset({$asset});\n";
         }
         $this->compiler->write("<?php\n" . "{$baseVar} = {$base};\n" . $buffer . "?>");
     }
 }
Пример #9
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $oldPath = CurrentPath::set($this->getPath());
     $this->onInitialize();
     CurrentPath::set($oldPath);
 }