root() публичный статический Метод

Return current root URL
public static root ( boolean $addAuth = false ) : null | string
$addAuth boolean
Результат null | string
Пример #1
0
 /**
  * Create img tag.
  *
  * @param string $src
  * @param string|array $class
  * @param string $id
  * @param array $attrs
  * @return string
  */
 public function render($src, $class = '', $id = '', array $attrs = array())
 {
     $attrs['class'] = false;
     $attrs = array_merge(array('fullUrl' => true), $attrs);
     $attrs['id'] = $id;
     $attrs = $this->_normalizeClassAttr($attrs, $this->_jbSrt('image'));
     if ($class !== '') {
         $attrs = $this->_normalizeClassAttr($attrs, $class);
     }
     $attrs['class'] = Str::clean($attrs['class']);
     $isFull = $attrs['fullUrl'];
     unset($attrs['fullUrl']);
     $src = FS::clean($src, '/');
     $attrs['src'] = $isFull ? Url::root() . '/' . $src : $src;
     return '<img ' . $this->buildAttrs($attrs) . ' />';
 }
Пример #2
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);
 }
Пример #3
0
 public function testFullUrl()
 {
     $path = Path::getInstance(__METHOD__);
     $fs = new Filesystem();
     $_SERVER['HTTP_HOST'] = 'test.dev';
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER['REQUEST_URI'] = '/custom';
     $paths = array($this->_root . DS . 'my-folder', $this->_root . DS . 'my-folder2' . DS . 'dir', $this->_root);
     foreach ($paths as $key => $p) {
         $fs->mkdir($p);
         $fs->dumpFile($p . DS . 'file' . $key . '.txt', '');
     }
     $fs->dumpFile($this->_root . DS . 'my-folder2' . DS . 'my-file.txt', '');
     list($path1, $path2) = $paths;
     $path->setRoot($this->_root);
     $path->set('default', $paths);
     $current = Url::root() . '/';
     $file1 = $current . 'my-folder2/dir/file1.txt';
     $file2 = $current . 'my-folder/file0.txt';
     $file3 = $current . 'my-folder2/my-file.txt';
     $this->_is($file1, $path->url('default:file1.txt'));
     $this->_is($file3, $path->url('default:my-folder2/my-file.txt'));
     $this->_is($file3, $path->url('default:my-folder2\\\\my-file.txt'));
     $this->_is($file3, $path->url('default:\\my-folder2\\my-file.txt'));
     $this->_is($file1, $path->url($path2 . DS . 'file1.txt'));
     $this->_is($file2, $path->url($path1 . DS . 'file0.txt'));
     $this->_is($file2, $path->url($path1 . '/file0.txt'));
     $this->_is($file3, $path->url($this->_root . '\\my-folder2\\my-file.txt'));
     $this->_is($file3, $path->url($this->_root . '/my-folder2////my-file.txt'));
     $this->_is($file3, $path->url($this->_root . DS . 'my-folder2' . DS . 'my-file.txt'));
     $this->_is($file2 . '?data=test&value=hello', $path->url($path1 . DS . 'file0.txt?data=test&value=hello'));
     isNull($path->url('default:file.txt'));
     isNull($path->url('alias:file.txt'));
     isNull($path->url($this->_root . DS . 'my-folder2' . DS . 'file.txt'));
     isNull($path->url($this->_root . 'my/' . DS . 'file.txt'));
     $fs->remove(array($path1, $path2, $this->_root . DS . 'my-folder2', $this->_root . DS . 'file2.txt'));
 }
Пример #4
0
 public function testRootBugWithPost3()
 {
     $_SERVER['HTTP_HOST'] = '127.0.0.1';
     $_SERVER['SERVER_PORT'] = 80;
     isSame('http://127.0.0.1', Url::root());
 }
Пример #5
0
 /**
  * Get url to a file.
  *
  * @param string    $source (example: "default:file.txt" or "C:\server\test.dev\file.txt")
  * @param bool|true $full
  * @return null|string
  */
 public function url($source, $full = true)
 {
     $details = explode('?', $source);
     $path = $details[0];
     $path = $this->_cleanPath($path);
     $path = $this->_getUrlPath($path, true);
     if (!empty($path)) {
         if (isset($details[1])) {
             $path .= '?' . $details[1];
         }
         $path = '/' . $path;
         return $full ? Url::root() . $path : $path;
     }
     return null;
 }
Пример #6
0
 /**
  * Get full URL to image (if not CLI mode)
  *
  * @return string
  * @throws Exception
  */
 public function getUrl()
 {
     return Url::root() . '/' . $this->getPath();
 }