예제 #1
0
 /**
  * Run app
  *
  * @throws \Exception|Exception
  */
 public function run()
 {
     try {
         \Magelight\Event\Manager::getInstance()->dispatchEvent('app_start', []);
         $request = \Magelight\Http\Request::getInstance();
         $resource = $request->getGet('resource');
         $staticDir = realpath($this->getAppDir() . DS . \Magelight\Config::getInstance()->getConfigString('global/view/published_static_dir', 'pub/static'));
         foreach (array_reverse($this->getModuleDirectories()) as $modulesPath) {
             $resource = str_replace('\\/', DS, $resource);
             $filename = $modulesPath . DS . $resource;
             $targetFilename = $staticDir . DS . $resource;
             if (file_exists($filename)) {
                 if (!is_dir(dirname($targetFilename))) {
                     mkdir(dirname($targetFilename), 0777, true);
                 }
                 if (\Magelight\Config::getInstance()->getConfigBool('global/app/developer_mode', false)) {
                     $pathinfo = pathinfo($filename, PATHINFO_EXTENSION);
                     if (isset($this->mimeTypes[$pathinfo])) {
                         $mimeType = $this->mimeTypes[$pathinfo];
                         header('Content-type: ' . $mimeType);
                     }
                     echo file_get_contents($filename);
                     break;
                 }
                 copy($filename, $targetFilename);
                 header('Location: ' . \Magelight\Helpers\UrlHelper::getInstance()->getUrl($resource));
                 break;
             }
         }
     } catch (\Exception $e) {
         \Magelight\Log::getInstance()->add($e->getMessage());
         if ($this->developerMode) {
             throw $e;
         }
     }
 }
예제 #2
0
 public function testUrl()
 {
     $match = 'test';
     $params = ['xxx' => '1', 'yyy' => '2'];
     $type = \Magelight\Helpers\UrlHelper::TYPE_HTTP;
     $addOnlyMaskParams = false;
     $urlHelperMock = $this->getMock(\Magelight\Helpers\UrlHelper::class, [], [], '', false);
     \Magelight\Helpers\UrlHelper::forgeMock($urlHelperMock);
     $urlHelperMock->expects($this->once())->method('getUrl')->with($match, $params, $type, $addOnlyMaskParams)->will($this->returnValue('http://localhost/test?xxx=1&yyy=2'));
     $block = \Magelight\Block::forge();
     $this->assertEquals('http://localhost/test?xxx=1&yyy=2', $block->url($match, $params, $type, $addOnlyMaskParams));
 }
예제 #3
0
 /**
  * Minify document static entry
  *
  * @param string $type
  * @param array $staticEntries
  * @return array
  * @throws \Magelight\Exception
  */
 protected function minifyDocumentStatic($type = 'css', $staticEntries = [])
 {
     $minifier = $this->getMinifierByType($type);
     $content = '';
     $path = $this->getEntriesStaticPath($staticEntries, $type);
     $dir = dirname($path);
     if (!is_writable($dir)) {
         trigger_error(__("Static cache directory %s is not writable or does not exist!", [$dir]));
         return $staticEntries;
     }
     if ($isAlreadyMinified = $this->cache()->get($this->buildCacheKey($path), false)) {
         $ok = true;
         if (\Magelight\Config::getInstance()->getConfigBool('global/minifier/check_readability')) {
             $ok = is_readable($path);
         }
         if ($ok) {
             return ['path' => $path, 'content' => '', 'url' => \Magelight\Helpers\UrlHelper::getInstance()->getUrl($path), 'inline' => false];
         }
     }
     foreach ($staticEntries as $entry) {
         if ($entry['inline']) {
             $content .= $minifier->minify($entry['content']);
         } else {
             $buffer = file_get_contents(\Magelight\App::getInstance()->getRealPathInModules($entry['path']));
             if ($buffer === false) {
                 trigger_error(__("File %s for minifier cannot be read", [$entry['path']]), E_USER_WARNING);
             }
             if (\Magelight\Config::getInstance()->getConfigBool('global/minifier/compress_' . $type)) {
                 $buffer = $minifier->minify($buffer);
             }
             switch ($type) {
                 case 'css':
                     $content .= $this->fixCssUrls($buffer, $entry['path']);
                     break;
                 case 'js':
                     $content .= $buffer;
                     break;
                 default:
                     break;
             }
             unset($buffer);
         }
     }
     if (file_put_contents($path, $content)) {
         $this->cache()->set($this->buildCacheKey($path), 1, \Magelight\Config::getInstance()->getConfigInt('global/minifier/cache_ttl_' . $type));
         return ['path' => $path, 'content' => '', 'url' => \Magelight\Helpers\UrlHelper::getInstance()->getUrl($path), 'inline' => false];
     } else {
         return $staticEntries;
     }
 }
예제 #4
0
 public function testRedirectInternal()
 {
     $url = 'http://url/match?param=value';
     $urlHelperMock = $this->getMock(\Magelight\Helpers\UrlHelper::class, [], [], '', false);
     $urlHelperMock->expects($this->once())->method('getUrl')->with('match', ['param' => 'value'], 'http')->will($this->returnValue('http://url/match?param=value'));
     \Magelight\Helpers\UrlHelper::forgeMock($urlHelperMock);
     $this->serverMock->expects($this->once())->method('sendHeader')->with("Location: " . $url);
     $this->appMock->expects($this->once())->method('shutdown');
     $this->controller->redirectInternal('match', ['param' => 'value']);
 }
예제 #5
0
 /**
  * Fetch url by match mask
  *
  * @param string $match - url match mask
  * @param array $params - params to be passed to URL
  * @param string $type - URL type (http|https)
  * @return string
  */
 public function url($match, $params = [], $type = null)
 {
     return \Magelight\Helpers\UrlHelper::getInstance()->getUrl($match, $params, $type);
 }
예제 #6
0
파일: Block.php 프로젝트: rganin/magelight
 /**
  * Fetch url by match mask
  *
  * @param string $match - url match mask
  * @param array $params - params to be passed to URL
  * @param string $type - URL type (http|https)
  * @param bool $addOnlyMaskParams - add to url only params that are present in URL match mask
  * @return string
  */
 public function url($match, $params = [], $type = null, $addOnlyMaskParams = false)
 {
     return \Magelight\Helpers\UrlHelper::getInstance()->getUrl($match, $params, $type, $addOnlyMaskParams);
 }
예제 #7
0
파일: User.php 프로젝트: rganin/magelight
 /**
  * Get user photo URI
  *
  * @param string $photoBaseUrl
  * @return mixed|string
  * @throws \Magelight\Exception
  */
 public function getPhotoUrl($photoBaseUrl = 'var/uploads')
 {
     if ($this->isUserPhotoExternal()) {
         return $this->photo;
     } else {
         return UrlHelper::getInstance()->getUrl($photoBaseUrl . '/' . $this->photo);
     }
 }