Beispiel #1
0
 /**
  * Render the component.
  *
  * @param   string  $option  The component option.
  * @param   array   $params  The component parameters
  * @return  object
  */
 public function render($option, $params = array())
 {
     // Load template language files.
     $lang = $this->app['language'];
     if ($this->app->has('template')) {
         $template = $this->app['template']->template;
         $lang->load('tpl_' . $template, JPATH_BASE, null, false, true);
         $lang->load('tpl_' . $template, JPATH_THEMES . DS . $template, null, false, true);
     }
     if (empty($option)) {
         // Throw 404 if no component
         $this->app->abort(404, $lang->translate('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'));
     }
     $option = $this->canonical($option);
     // Record the scope
     $scope = $this->app->has('scope') ? $this->app->get('scope') : null;
     // Set scope to component name
     $this->app->set('scope', $option);
     // Build the component path.
     $file = substr($option, 4);
     $client = isset($this->app['client']->alias) ? $this->app['client']->alias : $this->app['client']->name;
     // Get component path
     if (is_dir(PATH_APP . DS . 'components' . DS . $option . DS . $client)) {
         // Set path and constants for combined components
         define('JPATH_COMPONENT', PATH_APP . DS . 'components' . DS . $option . DS . $client);
         define('JPATH_COMPONENT_SITE', PATH_APP . DS . 'components' . DS . $option . DS . 'site');
         define('JPATH_COMPONENT_ADMINISTRATOR', PATH_APP . DS . 'components' . DS . $option . DS . 'admin');
     } else {
         // Set path and constants for combined components
         define('JPATH_COMPONENT', PATH_CORE . DS . 'components' . DS . $option . DS . $client);
         define('JPATH_COMPONENT_SITE', PATH_CORE . DS . 'components' . DS . $option . DS . 'site');
         define('JPATH_COMPONENT_ADMINISTRATOR', PATH_CORE . DS . 'components' . DS . $option . DS . 'admin');
     }
     $path = JPATH_COMPONENT . DS . $file . '.php';
     // If component is disabled throw error
     if (!$this->isEnabled($option) || !file_exists($path)) {
         $this->app->abort(404, $lang->translate('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'));
     }
     // Load common and local language files.
     $lang->load($option, JPATH_COMPONENT, null, false, true) || $lang->load($option, JPATH_BASE, null, false, true);
     // Handle template preview outlining.
     $contents = null;
     // Execute the component.
     $contents = $this->execute($path);
     // Revert the scope
     $this->app->forget('scope');
     $this->app->set('scope', $scope);
     return $contents;
 }
 private function resolve()
 {
     $args = $this->args;
     // Location ($args[#]) containing the callable method
     $call_loc = 1;
     $http_in_args = true;
     // http method defined? !!
     if (isset($args[0]) && is_string($args[0]) && in_array(strtolower($args[0]), $this->request_methods)) {
         $http_method = $args[0];
     } else {
         $http_method = $this->request->getMethod();
         $http_in_args = false;
         $call_loc = 0;
     }
     // fetch call identifier
     $call_method = @$args[$call_loc] ?: $this->default_method;
     if (!$call_method) {
         $this->app->abort(404, sprintf('No callable method in "%s" (context: [%s]). Consider providing "%s::$default_method" with a callable method in your resolver.', get_class($this->resolver), strtoupper($http_method), get_class($this)));
     }
     // construct method
     $call = strtolower($http_method) . $this->ah->createNamespace(ucfirst($call_method));
     if (method_exists($this->resolver, $call)) {
         // delete HTTP method from argument list
         if ($http_in_args) {
             unset($args[0]);
         }
         // delete call from argument list? !!
         if (!$this->keep_method && isset($args[$call_loc])) {
             unset($args[$call_loc]);
         }
         // prepend application container to argument list
         array_unshift($args, $this->app);
         return call_user_func_array(array($this->resolver, $call), $args);
     } else {
         $this->app->abort(404, sprintf('Could not complete request. Method "%s::%s(...)" does not exist.', get_class($this->resolver), $call));
     }
     return $result;
 }
Beispiel #3
0
 /**
  * Handles the output from downstream requests.
  * @param  object  $req \PHPDaemon\Request\Generic.
  * @param  string  $s   The output.
  * @return boolean      Success
  */
 public function requestOut($req, $s)
 {
     if ($this->write($s) === false) {
         $req->abort();
         return false;
     }
     return true;
 }
Beispiel #4
0
 /**
  * Render the component.
  *
  * @param   string  $option  The component option.
  * @param   array   $params  The component parameters
  * @return  object
  */
 public function render($option, $params = array())
 {
     // Load template language files.
     $lang = $this->app['language'];
     if ($this->app->has('template')) {
         $template = $this->app['template']->template;
         $lang->load('tpl_' . $template, JPATH_BASE, null, false, true);
         $lang->load('tpl_' . $template, JPATH_THEMES . DS . $template, null, false, true);
     }
     if (empty($option)) {
         // Throw 404 if no component
         $this->app->abort(404, $lang->translate('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'));
     }
     $option = $this->canonical($option);
     // Record the scope
     $scope = $this->app->has('scope') ? $this->app->get('scope') : null;
     // Set scope to component name
     $this->app->set('scope', $option);
     // Build the component path.
     $file = substr($option, 4);
     $client = isset($this->app['client']->alias) ? $this->app['client']->alias : $this->app['client']->name;
     // Get component path
     if (is_dir(PATH_APP . DS . 'components' . DS . $option . DS . $client)) {
         // Set path and constants for combined components
         define('JPATH_COMPONENT', PATH_APP . DS . 'components' . DS . $option . DS . $client);
         define('JPATH_COMPONENT_SITE', PATH_APP . DS . 'components' . DS . $option . DS . 'site');
         define('JPATH_COMPONENT_ADMINISTRATOR', PATH_APP . DS . 'components' . DS . $option . DS . 'admin');
     } else {
         // Set path and constants for combined components
         define('JPATH_COMPONENT', PATH_CORE . DS . 'components' . DS . $option . DS . $client);
         define('JPATH_COMPONENT_SITE', PATH_CORE . DS . 'components' . DS . $option . DS . 'site');
         define('JPATH_COMPONENT_ADMINISTRATOR', PATH_CORE . DS . 'components' . DS . $option . DS . 'admin');
     }
     $path = JPATH_COMPONENT . DS . $file . '.php';
     $namespace = '\\Components\\' . ucfirst(substr($option, 4)) . '\\' . ucfirst($client) . '\\Bootstrap';
     $found = false;
     // Make sure the component is enabled
     if ($this->isEnabled($option)) {
         // Check to see if the class is autoload-able
         if (class_exists($namespace)) {
             $found = true;
             $path = $namespace;
             // Infer the appropriate language path and load from there
             $file = with(new \ReflectionClass($namespace))->getFileName();
             $bits = explode(DS, $file);
             $local = implode(DS, array_slice($bits, 0, -1));
             // Load local language files
             $lang->load($option, $local, null, false, true);
         } else {
             if (file_exists($path)) {
                 $found = true;
                 // Load local language files
                 $lang->load($option, JPATH_COMPONENT, null, false, true);
             }
         }
     }
     // Make sure we found something
     if (!$found) {
         $this->app->abort(404, $lang->translate('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND_OR_ENABLED'));
     }
     // Load base language file
     $lang->load($option, JPATH_BASE, null, false, true);
     // Handle template preview outlining.
     $contents = null;
     // Execute the component.
     $contents = $this->execute($path);
     // Revert the scope
     $this->app->forget('scope');
     $this->app->set('scope', $scope);
     return $contents;
 }