Skip to content

Commit

Permalink
added a header in the generated bundle file. improved regex for php t…
Browse files Browse the repository at this point in the history
…ags removal.
  • Loading branch information
nocive committed Mar 15, 2012
1 parent 67b0af7 commit e9f18d0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/Freesound.php
Expand Up @@ -20,13 +20,15 @@
*************************************************************************************************/

/**
* Autoloader class
* Utilities class
*
* @package Freesound
* @package Freesound
* @subpackage Freesound_Utils
*/
class Freesound_Utils
{
public static $classmap = array(
'Freesound' => 'Freesound',
'Freesound_Base' => 'Base/Base',
'Freesound_Config' => 'Config/Config',
'Freesound_API_Base' => 'API/Base',
Expand All @@ -50,13 +52,20 @@ public static function BundleBuild( $file )
$classpaths = array_unique( array_values( self::$classmap ) );

$content = "<?php\n\n";
$content .= "/**\n";
$content .= " * This file was automatically generated by PHP.\n";
$content .= " * Do NOT edit this file!\n";
$content .= " *\n";
$content .= " * Generated at: " . date( 'r' ) . "\n";
$content .= " */\n";
$content .= "define( 'FREESOUND_BUNDLE', true );\n\n";
foreach( $classpaths as $path ) {
$f = __DIR__ . DIRECTORY_SEPARATOR . $path . self::CLASS_EXTENSION;
if (false === ($c = @file_get_contents( $f ))) {
throw new Exception( "Could not open file '$f'" );
}
// remove php tags
$c = preg_replace ( '#<\?(?:php)?\s*(.*?)\s*\?>#s', '\\1', $c );
$c = preg_replace( array( '#<\?(?:php)?\s*#s', '#\?\>(?=([\s\n]+)?$(?!\n))#s' ), null, $c );
$content .= "$c\n\n";
}
$content .= "?>";
Expand All @@ -80,8 +89,9 @@ public static function AutoloadRegister()
}
}

// register autoload
Freesound_Utils::AutoloadRegister();
if (! defined( 'FREESOUND_BUNDLE' )) {
Freesound_Utils::AutoloadRegister();
}


/**
Expand Down

0 comments on commit e9f18d0

Please sign in to comment.