Last active
January 28, 2021 19:57
-
-
Save rotexdegba/22ac4c5eb8f927d350002d2fe1c2a3a7 to your computer and use it in GitHub Desktop.
Script for dumping debugbar css & js assets into the public folder of apps powered by https://github.com/rotexsoft/slim3-skeleton-mvc-app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// For use in apps built with https://github.com/rotexsoft/slim3-skeleton-mvc-app | |
// Copy script to the root folder of the project and run from there. | |
// Works with "maximebf/debugbar" version "^1.16 | |
// This script copies the fonts folder from the debugbar composer vendor folder | |
// to the ./public/fonts folder. It also dumps all the css and js assets | |
// needed by debugbar into ./public/css/debugbar-css-assets.css and | |
// ./public/js/debugbar-js-assets.js respectively | |
require dirname(__FILE__, 1) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; | |
use DebugBar\StandardDebugBar; | |
function normalizeFolderPath(string $file_path) { | |
//trim right-most linux style path separator if any | |
$trimed_path = rtrim($file_path, '/'); | |
if( strlen($trimed_path) === strlen($file_path) ) { | |
//there was no right-most linux path separator | |
//try to trim right-most windows style path separator if any | |
$trimed_path = rtrim($trimed_path, '\\'); | |
} | |
return $trimed_path; | |
} | |
function recurseCopyDir(string $src, string $dst, bool $printProgress=false) { | |
$strProgress = "Copying `{$src}` to `{$dst}` ...." . PHP_EOL . PHP_EOL; | |
$dst = \normalizeFolderPath($dst); | |
$src = \normalizeFolderPath($src); | |
$dir = \opendir($src); | |
if( $dir === false) { $strProgress .= "Could not open `{$src}`" . PHP_EOL . PHP_EOL; } | |
if(!\file_exists($dst)) { | |
if(\mkdir($dst)) { | |
$strProgress .= "Successfully created `{$dst}`" . PHP_EOL . PHP_EOL; | |
} else { | |
$strProgress .= "Could not create `{$dst}`" . PHP_EOL . PHP_EOL; | |
} | |
} | |
while(false !== ( $file = \readdir($dir)) ) { | |
if (( $file != '.' ) && ( $file != '..' )) { | |
if ( \is_dir($src . DIRECTORY_SEPARATOR . $file) ) { | |
\recurseCopyDir( | |
$src . DIRECTORY_SEPARATOR . $file, | |
$dst . DIRECTORY_SEPARATOR . $file, | |
$printProgress | |
); | |
} else { | |
if( | |
\copy( | |
$src . DIRECTORY_SEPARATOR . $file, | |
$dst . DIRECTORY_SEPARATOR . $file | |
) === true | |
) { | |
$strProgress .= \sprintf( | |
"Successfully copied `%s` to `%s`", | |
$src . DIRECTORY_SEPARATOR . $file, | |
$dst . DIRECTORY_SEPARATOR . $file | |
) | |
. PHP_EOL . PHP_EOL; | |
} else { | |
$strProgress .= \sprintf( | |
"Could not copy `%s` to `%s`", | |
$src . DIRECTORY_SEPARATOR . $file, | |
$dst . DIRECTORY_SEPARATOR . $file | |
) | |
. PHP_EOL . PHP_EOL; | |
} | |
} | |
} | |
} | |
\closedir($dir); | |
if($printProgress) { echo $strProgress . PHP_EOL . PHP_EOL . PHP_EOL; } | |
} | |
$currentDir = dirname(__FILE__, 1); | |
$debugbar = new StandardDebugBar(); | |
$debugbarRenderer = $debugbar->getJavascriptRenderer(); | |
$fontAwesomeFontsVendorPath = $currentDir | |
. DIRECTORY_SEPARATOR | |
. 'vendor' | |
. DIRECTORY_SEPARATOR | |
. 'maximebf' | |
. DIRECTORY_SEPARATOR | |
. 'debugbar' | |
. DIRECTORY_SEPARATOR | |
. 'src' | |
. DIRECTORY_SEPARATOR | |
. 'DebugBar' | |
. DIRECTORY_SEPARATOR | |
. 'Resources' | |
. DIRECTORY_SEPARATOR | |
. 'vendor' | |
. DIRECTORY_SEPARATOR | |
. 'font-awesome' | |
. DIRECTORY_SEPARATOR | |
. 'fonts' | |
. DIRECTORY_SEPARATOR; | |
$fontAwesomeFontsPublicPath = $currentDir | |
. DIRECTORY_SEPARATOR | |
. 'public' | |
. DIRECTORY_SEPARATOR | |
. 'fonts'; | |
(!\file_exists($fontAwesomeFontsPublicPath)) | |
&& \recurseCopyDir($fontAwesomeFontsVendorPath, $fontAwesomeFontsPublicPath, true); | |
// make sure path is writable | |
$debubugBarJsAssetsPath = $currentDir | |
. DIRECTORY_SEPARATOR | |
. 'public' | |
. DIRECTORY_SEPARATOR | |
. 'js' | |
. DIRECTORY_SEPARATOR | |
. 'debugbar-js-assets.js'; | |
// make sure path is writable | |
$debubugBarCssAssetsPath = $currentDir | |
. DIRECTORY_SEPARATOR | |
. 'public' | |
. DIRECTORY_SEPARATOR | |
. 'css' | |
. DIRECTORY_SEPARATOR | |
. 'debugbar-css-assets.css'; | |
if(!\file_exists($debubugBarCssAssetsPath)) { | |
echo "Dumping CSS assets to `{$debubugBarCssAssetsPath}`" .PHP_EOL . PHP_EOL; | |
$debugbarRenderer->dumpCssAssets($debubugBarCssAssetsPath); | |
} | |
if(!\file_exists($debubugBarJsAssetsPath)) { | |
echo "Dumping JS assets to `{$debubugBarJsAssetsPath}`" .PHP_EOL . PHP_EOL; | |
$debugbarRenderer->dumpJsAssets($debubugBarJsAssetsPath); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment