/**
  * Builds asset file path based off url
  *
  * @param string $url
  * @return string Absolute path for asset file
  */
 protected function _getAssetFile($url)
 {
     $parts = explode('/', $url);
     if ($parts[0] === 'theme') {
         $themeName = $parts[1];
         unset($parts[0], $parts[1]);
         $fileFragment = implode(DS, $parts);
         $path = App::themePath($themeName) . 'webroot' . DS;
         return $path . $fileFragment;
     }
     $plugin = Inflector::camelize($parts[0]);
     if ($plugin && Plugin::loaded($plugin)) {
         unset($parts[0]);
         $fileFragment = implode(DS, $parts);
         $pluginWebroot = Plugin::path($plugin) . 'webroot' . DS;
         return $pluginWebroot . $fileFragment;
     }
 }
 /**
  * Tests that $response->checkNotModified() is called and bypasses
  * file dispatching
  *
  * @return void
  */
 public function testNotModified()
 {
     $filter = new AssetDispatcher();
     $time = filemtime(App::themePath('TestTheme') . 'webroot/img/cake.power.gif');
     $time = new \DateTime('@' . $time);
     $response = $this->getMock('Cake\\Network\\Response', array('send', 'checkNotModified'));
     $request = new Request('theme/test_theme/img/cake.power.gif');
     $response->expects($this->once())->method('checkNotModified')->with($request)->will($this->returnValue(true));
     $event = new Event('DispatcherTest', $this, compact('request', 'response'));
     ob_start();
     $this->assertSame($response, $filter->beforeDispatch($event));
     ob_end_clean();
     $this->assertEquals(200, $response->statusCode());
     $this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());
     $response = $this->getMock('Cake\\Network\\Response', array('_sendHeader', 'checkNotModified'));
     $request = new Request('theme/test_theme/img/cake.power.gif');
     $response->expects($this->once())->method('checkNotModified')->with($request)->will($this->returnValue(true));
     $response->expects($this->never())->method('send');
     $event = new Event('DispatcherTest', $this, compact('request', 'response'));
     $this->assertSame($response, $filter->beforeDispatch($event));
     $this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());
 }
Esempio n. 3
0
 /**
  * Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in
  * Configure. If Asset.timestamp is true and debug is true, or Asset.timestamp === 'force'
  * a timestamp will be added.
  *
  * @param string $path The file path to timestamp, the path must be inside WWW_ROOT
  * @return string Path with a timestamp added, or not.
  */
 public function assetTimestamp($path)
 {
     $stamp = Configure::read('Asset.timestamp');
     $timestampEnabled = $stamp === 'force' || $stamp === true && Configure::read('debug');
     if ($timestampEnabled && strpos($path, '?') === false) {
         $filepath = preg_replace('/^' . preg_quote($this->request->webroot, '/') . '/', '', urldecode($path));
         $webrootPath = WWW_ROOT . str_replace('/', DS, $filepath);
         if (file_exists($webrootPath)) {
             //@codingStandardsIgnoreStart
             return $path . '?' . @filemtime($webrootPath);
             //@codingStandardsIgnoreEnd
         }
         $segments = explode('/', ltrim($filepath, '/'));
         if ($segments[0] === 'theme') {
             $theme = $segments[1];
             unset($segments[0], $segments[1]);
             $themePath = App::themePath($theme) . 'webroot' . DS . implode(DS, $segments);
             //@codingStandardsIgnoreStart
             return $path . '?' . @filemtime($themePath);
             //@codingStandardsIgnoreEnd
         } else {
             $plugin = Inflector::camelize($segments[0]);
             if (Plugin::loaded($plugin)) {
                 unset($segments[0]);
                 $pluginPath = Plugin::path($plugin) . 'webroot' . DS . implode(DS, $segments);
                 //@codingStandardsIgnoreStart
                 return $path . '?' . @filemtime($pluginPath);
                 //@codingStandardsIgnoreEnd
             }
         }
     }
     return $path;
 }
Esempio n. 4
0
 /**
  * test that themePath can find paths for themes.
  *
  * @return void
  */
 public function testThemePath()
 {
     $path = App::themePath('test_theme');
     $expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Themed' . DS . 'TestTheme' . DS;
     $this->assertPathEquals($expected, $path);
     $path = App::themePath('TestTheme');
     $expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Themed' . DS . 'TestTheme' . DS;
     $this->assertPathEquals($expected, $path);
 }