getDocRoot() public method

public getDocRoot ( ) : string
return string
Exemplo n.º 1
0
 /**
  * @param mixed $spec
  *
  * @return Minify_SourceInterface
  *
  * @throws Minify_Source_FactoryException
  */
 public function makeSource($spec)
 {
     if (is_string($spec)) {
         $spec = array('filepath' => $spec);
     } elseif ($spec instanceof Minify_SourceInterface) {
         return $spec;
     }
     $source = null;
     if (empty($spec['filepath'])) {
         // not much we can check
         return new Minify_Source($spec);
     }
     if ($this->options['resolveDocRoot'] && 0 === strpos($spec['filepath'], '//')) {
         $spec['filepath'] = $this->env->getDocRoot() . substr($spec['filepath'], 1);
     }
     if (!empty($this->options['fileChecker'])) {
         $spec['filepath'] = call_user_func($this->options['fileChecker'], $spec['filepath']);
     }
     if ($this->options['checkAllowDirs']) {
         $allowDirs = (array) $this->options['allowDirs'];
         $inAllowedDir = false;
         $filePath = $this->env->normalizePath($spec['filepath']);
         foreach ($allowDirs as $allowDir) {
             if (strpos($filePath, $this->env->normalizePath($allowDir)) === 0) {
                 $inAllowedDir = true;
             }
         }
         if (!$inAllowedDir) {
             $allowDirsStr = implode(';', $allowDirs);
             throw new Minify_Source_FactoryException("File '{$spec['filepath']}' is outside \$allowDirs " . "({$allowDirsStr}). If the path is resolved via an alias/symlink, look into the " . "\$min_symlinks option.");
         }
     }
     $basename = basename($spec['filepath']);
     if ($this->options['noMinPattern'] && preg_match($this->options['noMinPattern'], $basename)) {
         if (preg_match('~\\.(css|less)$~i', $basename)) {
             $spec['minifyOptions']['compress'] = false;
             // we still want URI rewriting to work for CSS
         } else {
             $spec['minifier'] = 'Minify::nullMinifier';
         }
     }
     $hoursBehind = $this->options['uploaderHoursBehind'];
     if ($hoursBehind != 0) {
         $spec['uploaderHoursBehind'] = $hoursBehind;
     }
     foreach ($this->handlers as $basenamePattern => $handler) {
         if (preg_match($basenamePattern, $basename)) {
             $source = call_user_func($handler, $spec);
             break;
         }
     }
     if (!$source) {
         throw new Minify_Source_FactoryException("Handler not found for file: {$basename}");
     }
     return $source;
 }
Exemplo n.º 2
0
    return new Minify($cache);
}, 'controller' => function (Minify_Env $env, Minify_Source_Factory $sourceFactory) {
    return new Minify_Controller_MinApp($env, $sourceFactory);
});
if (!isset($min_factories)) {
    $min_factories = array();
}
$min_factories = array_merge($defaultFactories, $min_factories);
// use an environment object to encapsulate all input
$server = $_SERVER;
if ($min_documentRoot) {
    $server['DOCUMENT_ROOT'] = $min_documentRoot;
}
$env = new Minify_Env(array('server' => $server));
// TODO probably should do this elsewhere...
$min_serveOptions['minifierOptions']['text/css']['docRoot'] = $env->getDocRoot();
$min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;
// auto-add targets to allowDirs
foreach ($min_symlinks as $uri => $target) {
    $min_serveOptions['minApp']['allowDirs'][] = $target;
}
if ($min_allowDebugFlag) {
    // TODO get rid of static stuff
    $min_serveOptions['debug'] = Minify_DebugDetector::shouldDebugRequest($env);
}
if (!empty($min_concatOnly)) {
    $min_serveOptions['concatOnly'] = true;
}
if ($min_errorLogger) {
    if (true === $min_errorLogger) {
        $min_errorLogger = FirePHP::getInstance(true);
Exemplo n.º 3
0
 public function indexAction()
 {
     include APP_PATH . '/library/Thirdpart/Minify/bootstrap.php';
     // set config path defaults
     $min_configPaths = array('base' => CONF_PATH . '/minify-config.php', 'test' => CONF_PATH . '/minify-config-test.php');
     // check for custom config paths
     if (!empty($min_customConfigPaths) && is_array($min_customConfigPaths)) {
         $min_configPaths = array_merge($min_configPaths, $min_customConfigPaths);
     }
     // load config
     require $min_configPaths['base'];
     if (isset($_GET['test'])) {
         include $min_configPaths['test'];
     }
     // setup factories
     $defaultFactories = array('minify' => function (Minify_CacheInterface $cache) {
         return new Minify($cache);
     }, 'controller' => function (Minify_Env $env, Minify_Source_Factory $sourceFactory) {
         return new Minify_Controller_MinApp($env, $sourceFactory);
     });
     if (!isset($min_factories)) {
         $min_factories = array();
     }
     $min_factories = array_merge($defaultFactories, $min_factories);
     // use an environment object to encapsulate all input
     $server = $_SERVER;
     if ($min_documentRoot) {
         $server['DOCUMENT_ROOT'] = $min_documentRoot;
     }
     $env = new Minify_Env(array('server' => $server));
     // TODO probably should do this elsewhere...
     $min_serveOptions['minifierOptions']['text/css']['docRoot'] = $env->getDocRoot();
     $min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;
     // auto-add targets to allowDirs
     foreach ($min_symlinks as $uri => $target) {
         $min_serveOptions['minApp']['allowDirs'][] = $target;
     }
     if ($min_allowDebugFlag) {
         // TODO get rid of static stuff
         $min_serveOptions['debug'] = Minify_DebugDetector::shouldDebugRequest($env);
     }
     if (!empty($min_concatOnly)) {
         $min_serveOptions['concatOnly'] = true;
     }
     if ($min_errorLogger) {
         if (true === $min_errorLogger) {
             $min_errorLogger = FirePHP::getInstance(true);
         }
         // TODO get rid of global state
         Minify_Logger::setLogger($min_errorLogger);
     }
     // check for URI versioning
     if (null !== $env->get('v') || preg_match('/&\\d/', $env->server('QUERY_STRING'))) {
         $min_serveOptions['maxAge'] = 31536000;
     }
     // need groups config?
     if (null !== $env->get('g')) {
         // we need groups config
         $min_serveOptions['minApp']['groups'] = \Model\Minify::loadGroupConfig();
     }
     // cache defaults
     if (!isset($min_cachePath)) {
         $min_cachePath = '';
     }
     if (!isset($min_cacheFileLocking)) {
         $min_cacheFileLocking = true;
     }
     if (is_string($min_cachePath)) {
         $cache = new Minify_Cache_File($min_cachePath, $min_cacheFileLocking);
     } else {
         // assume it meets interface.
         $cache = $min_cachePath;
     }
     /* @var Minify_CacheInterface $cache */
     $minify = call_user_func($min_factories['minify'], $cache);
     /* @var Minify $minify */
     if (!$env->get('f') && $env->get('g') === null) {
         // no spec given
         $msg = '<p>No "f" or "g" parameters were detected.</p>';
         $url = 'https://github.com/mrclay/minify/blob/master/docs/CommonProblems.wiki.md#long-url-parameters-are-ignored';
         $defaults = $minify->getDefaultOptions();
         $minify->errorExit($defaults['badRequestHeader'], $url, $msg);
     }
     $sourceFactoryOptions = array();
     // translate legacy setting to option for source factory
     if (isset($min_serveOptions['minApp']['noMinPattern'])) {
         $sourceFactoryOptions['noMinPattern'] = $min_serveOptions['minApp']['noMinPattern'];
     }
     $sourceFactory = new Minify_Source_Factory($env, $sourceFactoryOptions, $cache);
     $controller = call_user_func($min_factories['controller'], $env, $sourceFactory);
     /* @var Minify_ControllerInterface $controller */
     $minify->serve($controller, $min_serveOptions);
     return false;
 }