Esempio n. 1
0
 /**
  * Setup the template file to use. 
  * The first component in $ref MUST be the a colon separated pair having MODULE_NAME:TEMPLATE_NAME without file extension.
  * This will translate into APP_PATH/Modules/MODULE_NAME/Views/Templates/TEMPLATE_NAME.php
  *
  * @param string $ref A (MODULE_NAME, TEMPLATE_NAME) pair separated by colon.
  *
  * @return Self
  */
 public function using($ref)
 {
     $parts = [];
     $moduleName = '';
     $templateFilename = $ref . '.php';
     if (preg_match("#^([^\\:\\\\/]+):([^\\:]+)\$#", $ref, $parts)) {
         $moduleName = $parts[1];
         $templateFilename = $parts[2] . '.php';
     }
     $this->fileName = '';
     // Reset to override any previously used template
     $fullPath = APP_PATH . DS . 'Templates' . DS . $this->getTheme()->name . DS . $templateFilename;
     if (!is_readable($fullPath)) {
         $fullPath = APP_PATH . DS . 'Templates' . DS . 'Default' . DS . $templateFilename;
         if (!is_readable($fullPath)) {
             $fullPath = APP_PATH . DS . 'Modules' . DS . $moduleName . DS . 'Themes' . DS . $this->getTheme()->name . DS . 'Templates' . DS . $templateFilename;
             if (!is_readable($fullPath)) {
                 $fullPath = APP_PATH . DS . 'Modules' . DS . $moduleName . DS . 'Themes' . DS . 'Default' . DS . 'Templates' . DS . $templateFilename;
                 if (!is_readable($fullPath)) {
                     // Fallback to installed package modules
                     $packages = \Chubby\PackageLoader::findPackages('Modules');
                     foreach ($packages as $package) {
                         $fullPath = $package['path'] . DS . $moduleName . DS . 'Themes' . DS . 'Default' . DS . 'Templates' . DS . $templateFilename;
                         if (is_readable($fullPath)) {
                             break;
                         }
                     }
                     if (!is_readable($fullPath)) {
                         throw new \Exception("Cannot find a template from the given reference: {$ref}");
                     }
                 }
             }
         }
     }
     $this->fileName = $fullPath;
     return $this;
 }
Esempio n. 2
0
File: App.php Progetto: a3gz/chubby
 /**
  * @inheritdoc
  */
 public function run($appNamespace = self::ROOT_NAMESPACE)
 {
     //
     // Each application must exist inside its own namespace. Chubby uses that namespace to search for modules.
     $this->appNamespace = $appNamespace;
     //
     // Slim can be initiated in one of two ways:
     // 1. Without a container. Slim will create the default container.
     // 2. Receiving a container in the constructor. We can pass Slim some settings and services
     //      by passing a pre-created container. We do this here via a configuration file.
     $container = $this->getContainerConfig();
     $this->slim = new \Slim\App($container);
     $container = $this->slim->getContainer();
     //
     $this->modules = \Chubby\PackageLoader::loadModules($container);
     if (!is_array($this->modules) || !count($this->modules)) {
         throw new \Exception("Chubby Framework requires at least one module.");
     }
     //
     // Initialize the modules following the order given by each module's priority.
     foreach ($this->modules as $priority => $modules) {
         foreach ($modules as $module) {
             $module['object']->setApp($this);
             $module['object']->init();
         }
     }
     //
     $this->slim->run();
     return $this;
 }