1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-06-21 18:25:18 +02:00

moved web files from web/ to src/DebugBar/Resources

This commit is contained in:
maximebf
2013-06-19 11:34:47 +09:00
parent 96c49f0784
commit 571b865fcd
36 changed files with 87 additions and 8 deletions

View File

@ -5,4 +5,4 @@ include '../tests/bootstrap.php';
use DebugBar\StandardDebugBar;
$debugbar = new StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer()->setBaseUrl('../web');
$debugbarRenderer = $debugbar->getJavascriptRenderer()->setBaseUrl('../src/DebugBar/Resources');

15
demo/dump_assets.php Normal file
View File

@ -0,0 +1,15 @@
<?php
include 'bootstrap.php';
if (!isset($_GET['type'])) {
$_GET['type'] = 'js';
}
if ($_GET['type'] == 'css') {
header('content-type', 'text/css');
$debugbarRenderer->dumpCssAssets();
} else if ($_GET['type'] == 'js') {
header('content-type', 'text/javascript');
$debugbarRenderer->dumpJsAssets();
}

View File

@ -52,13 +52,17 @@ class JavascriptRenderer
* @param string $baseUrl
* @param string $basePath
*/
public function __construct(DebugBar $debugBar, $baseUrl = '/debugbar', $basePath = null)
public function __construct(DebugBar $debugBar, $baseUrl = null, $basePath = null)
{
$this->debugBar = $debugBar;
if ($baseUrl === null) {
$baseUrl = '/vendor/maximebf/debugbar/src/DebugBar/Resources';
}
$this->baseUrl = $baseUrl;
if ($basePath === null) {
$basePath = __DIR__ . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('..', '..', '..', 'web'));
$basePath = __DIR__ . DIRECTORY_SEPARATOR . 'Resources';
}
$this->basePath = $basePath;
@ -224,9 +228,10 @@ class JavascriptRenderer
/**
* Returns the list of asset files
*
* @param string $type Only return css or js files
* @return array
*/
protected function getAssetFiles()
protected function getAssetFiles($type = null)
{
$cssFiles = $this->cssFiles;
$jsFiles = $this->jsFiles;
@ -236,22 +241,42 @@ class JavascriptRenderer
$jsFiles = array_merge($this->jsVendors, $jsFiles);
}
return array($cssFiles, $jsFiles);
return $this->filterAssetArray(array($cssFiles, $jsFiles), $type);
}
/**
* Filters a tuple of (css, js) assets according to $type
*
* @param array $array
* @param string $type 'css', 'js' or null for both
* @return array
*/
protected function filterAssetArray($array, $type = null)
{
$type = strtolower($type);
if ($type === 'css') {
return $array[0];
}
if ($type === 'js') {
return $array[1];
}
return $array;
}
/**
* Returns a tuple where the both items are Assetic AssetCollection,
* the first one being css files and the second js files
*
* @param string $type Only return css or js collection
* @return array or \Assetic\Asset\AssetCollection
*/
public function getAsseticCollection()
public function getAsseticCollection($type = null)
{
list($cssFiles, $jsFiles) = $this->getAssetFiles();
return array(
return $this->filterAssetArray(array(
$this->createAsseticCollection($cssFiles),
$this->createAsseticCollection($jsFiles)
);
), $type);
}
/**
@ -271,6 +296,45 @@ class JavascriptRenderer
return new \Assetic\Asset\AssetCollection($assets);
}
/**
* Write all CSS assets to standard output or in a file
*
* @param string $targetFilename
*/
public function dumpCssAssets($targetFilename = null)
{
$this->dumpAssets($this->getAssetFiles('css'), $targetFilename);
}
/**
* Write all JS assets to standard output or in a file
*
* @param string $targetFilename
*/
public function dumpJsAssets($targetFilename = null)
{
$this->dumpAssets($this->getAssetFiles('js'), $targetFilename);
}
/**
* Write assets to standard output or in a file
*
* @param array $files
* @param string $targetFilename
*/
protected function dumpAssets($files, $targetFilename = null)
{
$content = '';
foreach ($files as $file) {
$content .= file_get_contents($this->makeUriRelativeTo($file, $this->basePath)) . "\n";
}
if ($targetFilename !== null) {
file_put_contents($targetFilename, $content);
} else {
echo $content;
}
}
/**
* Renders the html to include needed assets
*

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 193 KiB

After

Width:  |  Height:  |  Size: 193 KiB