/**
  * Loads a template resource
  *
  * @param resource string
  * @return mixed PHPSTLTemplate, PHPSTLTemplateProvider::DECLINE, or
  * PHPSTLTemplateProvider::FAIL
  * @see PHPSTL::load
  */
 public function load($resource)
 {
     $pl = strlen(self::$Prefix);
     if (strlen($resource) > $pl) {
         $id = (int) substr($resource, $pl);
         if ($id == 0) {
             return PHPSTLTemplateProvider::FAIL;
         }
         $node = CMSNode::load((int) $id);
         if (!isset($node)) {
             return PHPSTLTemplateProvider::FAIL;
         }
     } else {
         $node = CMSNode::loadResource($resource);
         if (!isset($node)) {
             return PHPSTLTemplateProvider::DECLINE;
         }
     }
     return $this->createTemplate($resource, $node);
 }
示例#2
0
 public function __construct(Site $site, $what, $action, $extra)
 {
     $method = 'do' . ucfirst($what) . ucfirst($action);
     if (!method_exists(__CLASS__, $method)) {
         throw new BadMethodCallException('no such method');
     }
     parent::__construct($site, 'application/json', false);
     $this->response = array();
     if (array_key_exists('id', $_REQUEST)) {
         $id = $_REQUEST['id'];
     }
     try {
         if (isset($id)) {
             switch ($what) {
                 case 'page':
                     $subject = CMSPage::load($id);
                     break;
                 case 'node':
                     $subject = CMSNode::load($id);
                     break;
                 default:
                     throw new RuntimeException('shouldn\'t happen');
                     break;
             }
         }
         $rclass = new ReflectionClass(get_class($this));
         $rmeth = $rclass->getMethod($method);
         if (isset($subject)) {
             $this->{$method}($subject, $extra);
         } else {
             if ($rmeth->getNumberOfRequiredParameters() > 0) {
                 throw new InvalidArgumentException('subject required');
             }
             $this->{$method}();
         }
     } catch (StopException $e) {
         // noop
     }
 }