Пример #1
0
 /**
  * Bootstrap the Primer singleton
  *
  * For backwards compatibility the first param is either a string to the BASE_PATH
  * or it can be an assoc array
  *
  * array(
  *     'basePath' => '',
  *     'patternPath' => '',     // Defaults to PRIMER::$BASE_PATH . '/pattern'
  *     'cachePath' => '',       // Defaults to PRIMER::$BASE_PATH . '/cache'
  *     'templateEngine' => ''   // Defaults to 'Rareloop\Primer\TemplateEngine\Handlebars\Template'
  * )
  *
  * @param  String|Array $options
  * @return Rareloop\Primer\Primer
  */
 public static function start($options)
 {
     ErrorHandler::register();
     ExceptionHandler::register();
     // Default params
     $defaultTemplateClass = 'Rareloop\\Primer\\TemplateEngine\\Handlebars\\Template';
     // Work out what we were passed as an argument
     if (is_string($options)) {
         // Backwards compatibility
         Primer::$BASE_PATH = realpath($options);
         Primer::$PATTERN_PATH = Primer::$BASE_PATH . '/patterns';
         Primer::$PATTERN_PATH = Primer::$BASE_PATH . '/views';
         Primer::$CACHE_PATH = Primer::$BASE_PATH . '/cache';
         Primer::$TEMPLATE_CLASS = $defaultTemplateClass;
         Primer::$WRAP_TEMPLATES = true;
     } else {
         // New more expressive function params
         if (!isset($options['basePath'])) {
             throw new Exception('No `basePath` param passed to Primer::start()');
         }
         Primer::$BASE_PATH = realpath($options['basePath']);
         Primer::$PATTERN_PATH = isset($options['patternPath']) ? realpath($options['patternPath']) : Primer::$BASE_PATH . '/patterns';
         Primer::$VIEW_PATH = isset($options['viewPath']) ? realpath($options['viewPath']) : Primer::$BASE_PATH . '/views';
         Primer::$CACHE_PATH = isset($options['cachePath']) ? realpath($options['cachePath']) : Primer::$BASE_PATH . '/cache';
         Primer::$TEMPLATE_CLASS = isset($options['templateClass']) ? $options['templateClass'] : $defaultTemplateClass;
         Primer::$WRAP_TEMPLATES = isset($options['wrapTemplate']) ? $options['wrapTemplate'] : true;
     }
     // Attempt to load all `init.php` files. We shouldn't really have to do this here but currently
     // include functions don't actually load patterns so its hard to track when things are loaded
     // TODO: Move everything through Pattern constructors
     $finder = new Finder();
     $initFiles = $finder->in(Primer::$PATTERN_PATH)->files()->name('init.php');
     foreach ($initFiles as $file) {
         include_once $file;
     }
     return Primer::instance();
 }