getDocRoot() public static method

Return document root
public static getDocRoot ( ) : string
return string
Beispiel #1
0
 /**
  * @param array $options
  * @return Data
  * @throws Exception
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 protected function _prepareOptions(array $options)
 {
     // Default data for current system
     $this->_default['root_url'] = Url::root();
     $this->_default['root_path'] = Sys::getDocRoot();
     $options = array_merge($this->_default, $options);
     // Check cache directory
     $cachePath = FS::clean($options['cache_path']);
     if (!$cachePath) {
         throw new Exception('Option "cache_path" is empty!');
     }
     if (!FS::isDir($cachePath)) {
         mkdir($cachePath, 0755, true);
     }
     $options['cache_path'] = FS::real($cachePath);
     $options['root_url'] = rtrim($options['root_url'], '/');
     $options['root_path'] = FS::real($options['root_path']);
     $options['driver'] = ucfirst(strtolower(trim($options['driver'])));
     // Check mixin paths
     $lessFile = (array) $options['autoload'];
     foreach ($lessFile as $key => $mixin) {
         $lessFile[$key] = FS::real($mixin);
     }
     $options['autoload'] = array_filter($lessFile);
     // Check imported paths
     $importPaths = [];
     foreach ((array) $options['import_paths'] as $path => $uri) {
         if ($cleanPath = FS::real($path)) {
             $importPaths[$cleanPath] = $uri;
         }
     }
     $importPaths[$options['root_path']] = $options['root_url'];
     // Forced add root path in the end of list!
     $options['import_paths'] = array_filter($importPaths);
     return new Data($options);
 }
Beispiel #2
0
 /**
  * Path constructor.
  * @param string $root
  */
 public function __construct($root = null)
 {
     $root = $root ?: Sys::getDocRoot();
     $this->setRoot($root);
 }
Beispiel #3
0
 public function testPredefinedRoot()
 {
     $_SERVER['HTTP_HOST'] = 'test.dev';
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER['REQUEST_URI'] = '/page';
     // defult
     $sysRoot = Sys::getDocRoot();
     $path = new Path();
     $this->_is($sysRoot, $path->getRoot());
     // custom
     $path = new Path(PROJECT_ROOT);
     $this->_is(PROJECT_ROOT, $path->getRoot());
     $this->_is(PROJECT_ROOT, $path->get('root:'));
     $this->_is(PROJECT_SRC, $path->get('root:src'));
     isSame('src', $path->rel('root:src'));
     isSame('/src', $path->url('root:src', false));
     isSame('http://test.dev/src', $path->url('root:src', true));
 }
Beispiel #4
0
 public function testGetDocumentRoot()
 {
     $_SERVER['DOCUMENT_ROOT'] = null;
     isSame(realpath('.'), Sys::getDocRoot());
     $_SERVER['DOCUMENT_ROOT'] = __DIR__;
     isSame(__DIR__, Sys::getDocRoot());
     $_SERVER['DOCUMENT_ROOT'] = '../../';
     isSame(realpath('../../'), Sys::getDocRoot());
     $_SERVER['DOCUMENT_ROOT'] = __DIR__ . '\\..\\';
     isSame(PROJECT_ROOT, Sys::getDocRoot());
 }