Example #1
0
 /**
  * Initializes the Spire framework.
  *
  * @return void
  */
 public static function initialize()
 {
     // Start the system.
     Spire::start();
     // Load routes.
     static::routes();
     // Find the current route.
     $route = Repository::retrieve(Request::method(), Uri::segmentString());
     // If no route was found, show a 404.
     if (empty($route)) {
         die('404');
     }
     // Instantiate the module.
     static::$module = $module = new Module($route);
     // Run the module.
     $response = $module->run();
     // Run the response.
     if (is_object($response) && method_exists($response, 'respond')) {
         $response->respond();
     }
     // Do we have a layout to process?
     $layout = $module->instance()->layout;
     // Process layout.
     if ($layout !== '') {
         echo Layout::get($layout);
     }
     // Close Spire.
     Spire::close();
 }
Example #2
0
 /**
  * Gets a component.
  *
  * @param  string  $name  The component name.
  * @param  array   $data  The component data.
  * @return string
  */
 public static function get(string $name, array $data = []) : string
 {
     // Merge the data.
     $data = array_merge_recursive(Layout::data(), $data);
     // Get the component path.
     $path = path('components') . $name . '.component.php';
     // Return the loaded component.
     return static::load($path, $data);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function respond()
 {
     // Get the module action instance.
     $instance = Router::module()->instance();
     // If we have no layout, then directly output the view.
     if (is_object($instance) && isset($instance->layout) && $instance->layout === '') {
         echo $this->render();
     } else {
         Layout::view($this);
     }
 }