Skip to content

Commit f100f27

Browse files
committedNov 23, 2014
Merge pull request php-debugbar#182 from alprs/feature/disable-vendor-asset
Allow disabling of specific vendor assets
2 parents f0c0e7e + 196a112 commit f100f27

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed
 

‎src/DebugBar/JavascriptRenderer.php

+21-4
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ class JavascriptRenderer
3737
protected $basePath;
3838

3939
protected $cssVendors = array(
40-
'vendor/font-awesome/css/font-awesome.min.css',
41-
'vendor/highlightjs/styles/github.css'
40+
'fontawesome' => 'vendor/font-awesome/css/font-awesome.min.css',
41+
'highlightjs' => 'vendor/highlightjs/styles/github.css'
4242
);
4343

4444
protected $jsVendors = array(
45-
'vendor/jquery/dist/jquery.min.js',
46-
'vendor/highlightjs/highlight.pack.js'
45+
'jquery' => 'vendor/jquery/dist/jquery.min.js',
46+
'highlightjs' => 'vendor/highlightjs/highlight.pack.js'
4747
);
4848

4949
protected $includeVendors = true;
@@ -247,6 +247,23 @@ public function areVendorsIncluded()
247247
return $this->includeVendors !== false;
248248
}
249249

250+
/**
251+
* Disable a specific vendor's assets.
252+
*
253+
* @param string $name "jquery", "fontawesome", "highlightjs"
254+
*
255+
* @return void
256+
*/
257+
public function disableVendor($name)
258+
{
259+
if (array_key_exists($name, $this->cssVendors)) {
260+
unset($this->cssVendors[$name]);
261+
}
262+
if (array_key_exists($name, $this->jsVendors)) {
263+
unset($this->jsVendors[$name]);
264+
}
265+
}
266+
250267
/**
251268
* Sets the javascript class name
252269
*

‎tests/DebugBar/Tests/JavascriptRendererTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,11 @@ public function testJQueryNoConflictAutoDisabling()
126126
$this->r->setIncludeVendors(array('css', 'js'));
127127
$this->assertTrue($this->r->isJqueryNoConflictEnabled());
128128
}
129+
130+
public function testCanDisableSpecificVendors()
131+
{
132+
$this->assertContains('jquery.min.js', $this->r->renderHead());
133+
$this->r->disableVendor('jquery');
134+
$this->assertNotContains('jquery.min.js', $this->r->renderHead());
135+
}
129136
}

0 commit comments

Comments
 (0)
Please sign in to comment.