Open EizEddin opened 8 years ago
ln -s ./../vendor/maximebf/debugbar/src/DebugBar/Resources ./debugbar
...
<IfModule rewrite_module>
RewriteEngine On
RewriteRule ^debugbar/(.*) /vendor/maximebf/debugbar/src/DebugBar/Resources/$1 [NC,L]
</IfModule>
...
...
location ~* ^/debugbar/(.*)$ {
alias "$root_dir/vendor/maximebf/debugbar/src/DebugBar/Resources/$1";
}
...
But as i think this is not good ideas. What do you think?
Can't you set the baseUrl in the JavascriptRenderer? https://github.com/maximebf/php-debugbar/blob/e634fbd32cd6bc3fa0e8c972b52d4bf49bab3988/src/DebugBar/JavascriptRenderer.php#L86
What is the best practices for making accessible "outside" debugbar assets from vendor directory? This is the first step before setting baseUrl
.
Whatever you like, setup a symlink, copy the assets or serve them on the fly. I usually do the latter, serving them on demand through a frontend controller.
This is what I have done eventually. I have defined the assets' paths in a separate include file, then included that file in the head.
One more idea - maybe you can make a bower package for your web accessible resources? Than everyone can install a package and use them without any server reconfiguration
p.s. Sorry for my english
@EizEddin I think it is a bad idea to serve files straight from vendor/ anyway. IMO all files that reside there should not be directly served by your server software.
I've wasted a lot of time trying to customize the URL and path to the JS and CSS assets required by PHP DebugBar.
I wish I'd found an example like this in the docs:
<pre><?php
ini_set( "display_errors", 1 );
require('vendor/autoload.php');
use DebugBar\StandardDebugBar;
use DebugBar\JavascriptRenderer;
$debugbar = new StandardDebugBar();
/** Set the path to the assets.
* Make sure to do so BEFORE any reference to `getJavascriptRenderer`, else the default values will be used.
* Note that this is required for Heroku, because the `vendor` directory is restricted on Heroku, meanwhile DebugBar uses it as its default path.
* See: https://github.com/maximebf/php-debugbar/issues/269
*/
// Approach #1 · Works fine.
$debugbarRenderer = $debugbar->getJavascriptRenderer( "http://example1.com/", "/path1" );
// Approach #2 · Works only partially, as the path doesn't get set.
// $debugbarRenderer = new JavascriptRenderer( $debugbar, "http://example2.com/", "/path2" );
// Aproach #3 · Works fine
// $debugbarRenderer = $debugbar->getJavascriptRenderer();
// $debugbarRenderer->setOptions( array( 'base_url' => 'http://example3.com/', 'base_path' => 'path3' ) );
// Default approach:
// $debugbarRenderer = $debugbar->getJavascriptRenderer();
print_r( $debugbar->getJavascriptRenderer()->getAssets() );
$debugbar["messages"]->addMessage("hello world!");
?>
<html>
<head>
<?php echo $debugbarRenderer->renderHead() ?>
</head>
<body>
...
<?php echo $debugbarRenderer->render() ?>
</body>
</html>
<pre>
(Note that approch #2 did not work for me, as marked in the code's comments.)
What compounded the issue is that I'm using Heroku where serving files from vendor
is not possible and results in 403 Forbidden
errors.
I'm still looking for a satisfying way to link to the asset files, something better than just duplicating them.
In addition to restricting access to its /app/vendor
folder, Heroku also filters out (i.e.: won't deploy) any vendor
folder regardless of its position in the hierarchy.
(This is easily verifiable: create /app/assets
then create /app/assets/foo.txt
and /app/assets/vendor/bar.txt
. Deploy then browse the directories: foo.txt will be there, not bar.txt)
This means that using PHP DebugBar on Heroku would require to also rename Resources/vendor
. The path to that folder is inside of protected
methods inside of JavascriptRenderer
making them not easily customizable.
I hope this helps a bit.
@fabswt I faced the same problem.
I had to put the whole path, like this:
$debugbarRenderer = new JavascriptRenderer( $debugbar, "http://example.cm/subfolder/vendor/maximebf/debugbar/src/DebugBar/Resources/");
Nothing else was working.
Hi,
If my website URL is http://www.example.com/subdir, be default, the assets path will be http://www.example.com/vendor/maximebf/debugbar....etc. ignoring the {subdir} directory.
How can I modify the assets' path to include the {subdir}, like this: http://www.example.com/subdir/vendor/maximebf/debugbar....etc.
Thanks