Loading a lithium library only in certain environments -


i have added li3_docs (https://github.com/unionofrad/li3_docs) application don't want library load in production environment. best way prevent docs being available in production environment? thought of adding line config/bootstrap/libraries.php:

if(!environment::is('production')) {    libraries::add('li3_docs'); } 

this doesn't work because environment class hasn't been loaded yet , feel isn't wise load before libraries loader. best way this?

the hacky way add environment::set(new \lithium\net\http\request()) before adding libraries.

another way:

  1. add configuration value when adding library

    libraries::add('li3_docs', array('devonly' => true)); 
  2. update default dispatcher::run filter in app\bootstrap\action.php this

    dispatcher::applyfilter('run', function($self, $params, $chain) {   environment::set($params['request']);    foreach (array_reverse(libraries::get()) $name => $config) {     $devonly = isset($config['devonly']) && $config['devonly'];     $devonly = $devonly && environment::is('development');     if ($name === 'lithium' || $devonly) {       continue;     }     $file = "{$config['path']}/config/routes.php";     file_exists($file) ? include $file : null;   }   return $chain->next($self, $params, $chain); }); 

Comments