Exemple #1
0
 private function log_with_helper($prefix, $message, $loglevel)
 {
     // Temporary non-Midgard logger until midgard_error is backported to Ragnaroek
     static $logger = null;
     if (!$logger) {
         try {
             $logger = new midgardmvc_core_helpers_log();
         } catch (Exception $e) {
             // Unable to instantiate logger
             return;
         }
     }
     static $log_levels = array('debug' => 4, 'info' => 3, 'message' => 2, 'warn' => 1);
     if ($log_levels[$loglevel] > $log_levels[$this->configuration->get('log_level')]) {
         // Skip logging, too low level
         return;
     }
     $logger->log("{$prefix}: {$message}");
 }
 private function _process()
 {
     $this->context->create();
     date_default_timezone_set($this->configuration->get('default_timezone'));
     $this->dispatcher->get_midgard_connection()->set_loglevel($this->configuration->get('log_level'));
     // Let dispatcher populate request with the page and other information used
     $request = $this->dispatcher->get_request();
     $request->populate_context();
     if (isset($this->context->page->guid)) {
         // Load per-folder configuration
         $this->configuration->load_instance($this->context->component, $this->context->page);
     }
     $this->log('Midgard MVC', "Serving " . $request->get_method() . " {$this->context->uri} at " . gmdate('r'), 'info');
     // Let injectors do their work
     $this->componentloader = new midgardmvc_core_component_loader();
     $this->componentloader->inject_process();
     // Load the cache service and check for content cache
     self::$instance->context->cache_enabled = false;
     /*
     if (self::$instance->context->cache_enabled)
     {
         $request->generate_identifier();
         $this->cache->register_object($this->context->page);
         $this->cache->content->check($this->context->cache_request_identifier);
     }
     */
     // Show the world this is Midgard
     $this->head->add_meta(array('name' => 'generator', 'content' => "Midgard/" . mgd_version() . " MidgardMVC/{$this->componentloader->manifests['midgardmvc_core']['version']} PHP/" . phpversion()));
     if ($this->configuration->enable_attachment_cache) {
         $classname = $this->configuration->attachment_handler;
         $handler = new $classname();
         $handler->connect_to_signals();
     }
     // Then initialize the component, so it also goes to template stack
     $this->dispatcher->initialize($request);
     try {
         $this->dispatcher->dispatch();
     } catch (midgardmvc_exception_unauthorized $exception) {
         // Pass the exception to authentication handler
         $this->authentication->handle_exception($exception);
     }
     $this->dispatcher->header('Content-Type: ' . $this->context->mimetype);
 }
 public function get_routes(array $args)
 {
     $this->midgardmvc->authorization->require_user();
     $this->prepare_component($args['component'], $this->data);
     $configuration = new midgardmvc_core_services_configuration_yaml($this->data['component']);
     $this->data['routes'] = $configuration->get('routes');
     if (!$this->data['routes']) {
         throw new midgardmvc_exception_notfound("Component {$this->data['component']} has no routes");
     }
     foreach ($this->data['routes'] as $route_id => $route_def) {
         // Some normalization
         $this->data['routes'][$route_id]['id'] = $route_id;
         if (!isset($route_def['template_entry_point'])) {
             $this->data['routes'][$route_id]['template_entry_point'] = 'ROOT';
         }
         if (!isset($route_def['content_entry_point'])) {
             $this->data['routes'][$route_id]['content_entry_point'] = 'content';
         }
         $this->data['routes'][$route_id]['controller_action'] = "{$route_def['controller']}:{$route_def['action']}";
         $this->data['routes'][$route_id]['controller_url'] = $this->midgardmvc->dispatcher->generate_url('midcom_documentation_class', array('class' => $route_def['controller']));
         $this->data['routes'][$route_id]['controller_url'] .= "#action_{$route_def['action']}";
     }
 }